From 39d9992491ac5051e569090c5fc4da00b61a33c6 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Fri, 4 Jan 2013 11:46:28 +0100 Subject: [PATCH] Makes Category a ProcessibleDatabaseObject --- .../lib/data/category/Category.class.php | 49 ++++++++---------- .../data/category/CategoryAction.class.php | 50 ++++--------------- 2 files changed, 30 insertions(+), 69 deletions(-) diff --git a/wcfsetup/install/files/lib/data/category/Category.class.php b/wcfsetup/install/files/lib/data/category/Category.class.php index f0ab4b88a0..85be108260 100644 --- a/wcfsetup/install/files/lib/data/category/Category.class.php +++ b/wcfsetup/install/files/lib/data/category/Category.class.php @@ -1,6 +1,6 @@ @@ -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); } /** diff --git a/wcfsetup/install/files/lib/data/category/CategoryAction.class.php b/wcfsetup/install/files/lib/data/category/CategoryAction.class.php index 59c9055355..04265450b6 100644 --- a/wcfsetup/install/files/lib/data/category/CategoryAction.class.php +++ b/wcfsetup/install/files/lib/data/category/CategoryAction.class.php @@ -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); } } } -- 2.20.1