Added generic object type providers
authorAlexander Ebert <ebert@woltlab.com>
Fri, 21 Oct 2011 16:55:08 +0000 (18:55 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 21 Oct 2011 16:55:08 +0000 (18:55 +0200)
wcfsetup/install/files/lib/data/object/type/AbstractObjectTypeProvider.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/data/object/type/IObjectTypeProvider.class.php [new file with mode: 0644]

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 (file)
index 0000000..83938a8
--- /dev/null
@@ -0,0 +1,48 @@
+<?php
+namespace wcf\data\object\type;
+
+/**
+ * Basic implementation for object type providers.
+ *
+ * @author     Alexander Ebert
+ * @copyright  2001-2011 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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 (file)
index 0000000..3162de9
--- /dev/null
@@ -0,0 +1,30 @@
+<?php
+namespace wcf\data\object\type;
+
+/**
+ * Any object type provider should implement this interface.
+ *
+ * @author     Alexander Ebert
+ * @copyright  2001-2011 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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<integer>          $objectIDs
+        * @return      array<wcf\data\DatabaseObject>
+        */
+       public function getObjectsByIDs(array $objectIDs);
+}