From: Alexander Ebert Date: Fri, 21 Oct 2011 16:55:08 +0000 (+0200) Subject: Added generic object type providers X-Git-Tag: 2.0.0_Beta_1~1669 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=f7a221f007db5196f6c62defafcc8e9f228a4b8a;p=GitHub%2FWoltLab%2FWCF.git Added generic object type providers --- 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); +}