Makes Category a ProcessibleDatabaseObject
authorMatthias Schmidt <gravatronics@live.com>
Fri, 4 Jan 2013 10:46:28 +0000 (11:46 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Fri, 4 Jan 2013 10:46:28 +0000 (11:46 +0100)
wcfsetup/install/files/lib/data/category/Category.class.php
wcfsetup/install/files/lib/data/category/CategoryAction.class.php

index f0ab4b88a03bf3e51c671b3798b0006497a266d2..85be108260dc283f3a32ddc2abf6b16330ad8cdb 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 namespace wcf\data\category;
-use wcf\data\DatabaseObject;
+use wcf\data\ProcessibleDatabaseObject;
 use wcf\system\category\CategoryHandler;
 use wcf\system\request\IRouteController;
 use wcf\system\WCF;
@@ -15,13 +15,7 @@ use wcf\system\WCF;
  * @subpackage data.category
  * @category   Community Framework
  */
-class Category extends DatabaseObject implements IRouteController {
-       /**
-        * category type of this category
-        * @var wcf\system\category\ICategoryType
-        */
-       protected $categoryType = null;
-       
+class Category extends ProcessibleDatabaseObject implements IRouteController {
        /**
         * list of all parent category generations of this category
         * @var array<wcf\data\category\Category>
@@ -44,10 +38,20 @@ class Category extends DatabaseObject implements IRouteController {
         */
        protected static $databaseTableName = 'category';
        
+       /**
+        * @see wcf\data\ProcessibleDatabaseObject::$processorInterface
+        */
+       protected static $processorInterface = 'wcf\system\category\ICategoryType';
+       
        /**
         * @see wcf\data\IStorableObject::__get()
         */
        public function __get($name) {
+               // forward 'className' property requests to object type
+               if ($name == 'className') {
+                       return $this->getObjectType()->className;
+               }
+               
                $value = parent::__get($name);
                
                // check additional data
@@ -61,32 +65,19 @@ class Category extends DatabaseObject implements IRouteController {
        }
        
        /**
-        * Returns the category type of this category.
-        * 
-        * @return      wcf\system\category\ICategoryType
-        */
-       public function getCategoryType() {
-               if ($this->categoryType === null) {
-                       $this->categoryType = CategoryHandler::getInstance()->getObjectType($this->objectTypeID)->getProcessor();
-               }
-               
-               return $this->categoryType;
-       }
-       
-       /**
-        * Returns the name of the category type of this category.
-        *
-        * @return      string
+        * @see wcf\system\request\IRouteController::getID()
         */
-       public function getCategoryTypeName() {
-               return CategoryHandler::getInstance()->getObjectType($this->objectTypeID)->objectType;
+       public function getID() {
+               return $this->categoryID;
        }
        
        /**
-        * @see wcf\system\request\IRouteController::getID()
+        * Returns the category object type of the category.
+        * 
+        * @return      wcf\data\category\Category
         */
-       public function getID() {
-               return $this->categoryID;
+       public function getObjectType() {
+               return CategoryHandler::getInstance()->getObjectType($this->objectTypeID);
        }
        
        /**
index 59c90553553c44ce3944123380c5ae743d19473d..04265450b6755ac0e2246ac0e376c2ca0ce96894 100644 (file)
@@ -36,7 +36,7 @@ class CategoryAction extends AbstractDatabaseObjectAction implements ICollapsibl
                
                // call category types
                foreach ($this->objects as $categoryEditor) {
-                       $categoryEditor->getCategoryType()->afterDeletion($categoryEditor);
+                       $categoryEditor->getProcessor()->afterDeletion($categoryEditor);
                }
                
                return $returnValue;
@@ -57,7 +57,7 @@ class CategoryAction extends AbstractDatabaseObjectAction implements ICollapsibl
         * @see wcf\data\ICollapsibleContainerAction::toggleContainer()
         */
        public function toggleContainer() {
-               $collapsibleObjectTypeName = $this->objects[0]->getCategoryType()->getObjectTypeName('com.woltlab.wcf.collapsibleContent');
+               $collapsibleObjectTypeName = $this->objects[0]->getProcessor()->getObjectTypeName('com.woltlab.wcf.collapsibleContent');
                if ($collapsibleObjectTypeName === null) {
                        throw new SystemException("Categories of this type don't support collapsing");
                }
@@ -100,11 +100,6 @@ class CategoryAction extends AbstractDatabaseObjectAction implements ICollapsibl
         * @see wcf\data\AbstractDatabaseObjectAction::validateDelete()
         */
        public function validateCreate() {
-               // validate permissions
-               if (!empty($this->permissionsCreate)) {
-                       WCF::getSession()->checkPermissions($this->permissionsCreate);
-               }
-               
                if (!isset($this->parameters['data']['objectTypeID'])) {
                        throw new UserInputException('objectTypeID');
                }
@@ -122,16 +117,6 @@ class CategoryAction extends AbstractDatabaseObjectAction implements ICollapsibl
         * @see wcf\data\AbstractDatabaseObjectAction::validateDelete()
         */
        public function validateDelete() {
-               // validate permissions
-               if (!empty($this->permissionsDelete)) {
-                       try {
-                               WCF::getSession()->checkPermissions($this->permissionsDelete);
-                       }
-                       catch (PermissionDeniedException $e) {
-                               throw new PermissionDeniedException();
-                       }
-               }
-               
                // read objects
                if (empty($this->objects)) {
                        $this->readObjects();
@@ -142,7 +127,7 @@ class CategoryAction extends AbstractDatabaseObjectAction implements ICollapsibl
                }
                
                foreach ($this->objects as $categoryEditor) {
-                       if (!$categoryEditor->getCategoryType()->canDeleteCategory()) {
+                       if (!$categoryEditor->getProcessor()->canDeleteCategory()) {
                                throw new PermissionDeniedException();
                        }
                }
@@ -166,11 +151,6 @@ class CategoryAction extends AbstractDatabaseObjectAction implements ICollapsibl
         * @see wcf\data\AbstractDatabaseObjectAction::validateUpdate()
         */
        public function validateUpdate() {
-               // validate permissions
-               if (!empty($this->permissionsUpdate)) {
-                       WCF::getSession()->checkPermissions($this->permissionsUpdate);
-               }
-               
                // read objects
                if (empty($this->objects)) {
                        $this->readObjects();
@@ -181,7 +161,7 @@ class CategoryAction extends AbstractDatabaseObjectAction implements ICollapsibl
                }
                
                foreach ($this->objects as $categoryEditor) {
-                       if (!$categoryEditor->getCategoryType()->canEditCategory()) {
+                       if (!$categoryEditor->getProcessor()->canEditCategory()) {
                                throw new PermissionDeniedException();
                        }
                }
@@ -191,16 +171,6 @@ class CategoryAction extends AbstractDatabaseObjectAction implements ICollapsibl
         * @see wcf\data\ISortableAction::validateUpdatePosition()
         */
        public function validateUpdatePosition() {
-               // validate permissions
-               if (!empty($this->permissionsUpdate)) {
-                       try {
-                               WCF::getSession()->checkPermissions($this->permissionsUpdate);
-                       }
-                       catch (PermissionDeniedException $e) {
-                               throw new PermissionDeniedException();
-                       }
-               }
-               
                // validate 'structure' parameter
                if (!isset($this->parameters['data']['structure']) || !is_array($this->parameters['data']['structure'])) {
                        throw new UserInputException('structure');
@@ -215,12 +185,12 @@ class CategoryAction extends AbstractDatabaseObjectAction implements ICollapsibl
                                        throw new UserInputException('structure');
                                }
                                
-                               $this->objects[$category->categoryID] = new $this->className($category);
-                               
                                // validate permissions
-                               if (!$category->getCategoryType()->canEditCategory()) {
+                               if (!$category->getProcessor()->canEditCategory()) {
                                        throw new PermissionDeniedException();
                                }
+                               
+                               $this->objects[$category->categoryID] = new $this->className($category);
                        }
                        
                        foreach ($categoryIDs as $categoryID) {
@@ -230,12 +200,12 @@ class CategoryAction extends AbstractDatabaseObjectAction implements ICollapsibl
                                        throw new UserInputException('structure');
                                }
                                
-                               $this->objects[$category->categoryID] = new $this->className($category);
-                               
                                // validate permissions
-                               if (!$category->getCategoryType()->canEditCategory()) {
+                               if (!$category->getProcessor()->canEditCategory()) {
                                        throw new PermissionDeniedException();
                                }
+                               
+                               $this->objects[$category->categoryID] = new $this->className($category);
                        }
                }
        }