From f7a221f007db5196f6c62defafcc8e9f228a4b8a Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Fri, 21 Oct 2011 18:55:08 +0200 Subject: [PATCH] Added generic object type providers --- .../type/AbstractObjectTypeProvider.class.php | 48 +++++++++++++++++++ .../object/type/IObjectTypeProvider.class.php | 30 ++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 wcfsetup/install/files/lib/data/object/type/AbstractObjectTypeProvider.class.php create mode 100644 wcfsetup/install/files/lib/data/object/type/IObjectTypeProvider.class.php diff --git a/wcfsetup/install/files/lib/data/object/type/AbstractObjectTypeProvider.class.php b/wcfsetup/install/files/lib/data/object/type/AbstractObjectTypeProvider.class.php new file mode 100644 index 0000000000..83938a8d22 --- /dev/null +++ b/wcfsetup/install/files/lib/data/object/type/AbstractObjectTypeProvider.class.php @@ -0,0 +1,48 @@ + + * @package com.woltlab.wcf + * @subpackage data.object.type + * @category Community Framework + */ +abstract class AbstractObjectTypeProvider implements IObjectTypeProvider { + /** + * DatabaseObject class name + * @var string + */ + public $className = ''; + + /** + * DatabaseObjectList class name + * @var string + */ + public $listClassName = ''; + + /** + * @see wcf\data\object\type\IObjectTypeProvider::getObjectByID() + */ + public function getObjectByID($objectID) { + return new $this->className($objectID); + } + + /** + * @see wcf\data\object\type\IObjectTypeProvider::getObjectsByIDs() + */ + public function getObjectsByIDs(array $objectIDs) { + $tableAlias = call_user_func($this->className, 'getDatabaseTableAlias'); + $tableIndex = call_user_func($this->className, 'getDatabaseTableIndexName'); + + $objectList = new $this->listClassName(); + $objectList->getConditionBuilder()->add($tableAlias.".".$tableIndex." IN (?)", array($objectIDs)); + $objectList->sqlLimit = 0; + $objectList->readObjects(); + + return $objectList->getObjects(); + } +} diff --git a/wcfsetup/install/files/lib/data/object/type/IObjectTypeProvider.class.php b/wcfsetup/install/files/lib/data/object/type/IObjectTypeProvider.class.php new file mode 100644 index 0000000000..3162de9c43 --- /dev/null +++ b/wcfsetup/install/files/lib/data/object/type/IObjectTypeProvider.class.php @@ -0,0 +1,30 @@ + + * @package com.woltlab.wcf + * @subpackage data.object.type + * @category Community Framework + */ +interface IObjectTypeProvider { + /** + * Gets an object by its ID. + * + * @param integer $objectID + * @return wcf\data\DatabaseObject + */ + public function getObjectByID($objectID); + + /** + * Gets like objects by their IDs. + * + * @param array $objectIDs + * @return array + */ + public function getObjectsByIDs(array $objectIDs); +} -- 2.20.1