From 5ba4ffc56264064ccaec825cc5cebb93a14f8c1e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Joshua=20R=C3=BCsweg?= Date: Wed, 28 Jun 2017 15:46:28 +0200 Subject: [PATCH] Add trophy category object See #2315 --- com.woltlab.wcf/objectType.xml | 8 ++ .../trophy/category/TrophyCategory.class.php | 63 +++++++++++++ .../category/TrophyCategoryCache.class.php | 93 +++++++++++++++++++ 3 files changed, 164 insertions(+) create mode 100644 wcfsetup/install/files/lib/data/trophy/category/TrophyCategory.class.php create mode 100644 wcfsetup/install/files/lib/data/trophy/category/TrophyCategoryCache.class.php diff --git a/com.woltlab.wcf/objectType.xml b/com.woltlab.wcf/objectType.xml index f2eb5de0bc..c6ecef933c 100644 --- a/com.woltlab.wcf/objectType.xml +++ b/com.woltlab.wcf/objectType.xml @@ -1293,6 +1293,14 @@ + + + com.woltlab.wcf.trophy.category + com.woltlab.wcf.category + wcf\system\category\TrophyCategoryType + + + com.woltlab.wcf.page.controller diff --git a/wcfsetup/install/files/lib/data/trophy/category/TrophyCategory.class.php b/wcfsetup/install/files/lib/data/trophy/category/TrophyCategory.class.php new file mode 100644 index 0000000000..a47df07cbd --- /dev/null +++ b/wcfsetup/install/files/lib/data/trophy/category/TrophyCategory.class.php @@ -0,0 +1,63 @@ + + * @package WoltLabSuite\Core\Data\Trophy\Category + * @since 3.1 + * + * @method TrophyCategory[] getChildCategories() + * @method TrophyCategory[] getAllChildCategories() + * @method TrophyCategory getParentCategory() + * @method TrophyCategory[] getParentCategories() + * @method static TrophyCategory|null getCategory($categoryID) + */ +class TrophyCategory extends AbstractDecoratedCategory implements ITitledLinkObject { + /** + * object type name of the trophy categories + * @var string + */ + const OBJECT_TYPE_NAME = 'com.woltlab.wcf.trophy.category'; + + /** + * @inheritDoc + */ + public function isAccessible(User $user = null) { + if ($this->getObjectType()->objectType != self::OBJECT_TYPE_NAME) return false; + + if ($this->getDecoratedObject()->isDisabled) { + return false; + } + + return true; + } + + /** + * @inheritDoc + */ + public function getLink() { + return LinkHandler::getInstance()->getLink('TrophyList', [ + 'forceFrontend' => true, + 'object' => $this->getDecoratedObject() + ]); + } + + /** @noinspection PhpMissingParentCallCommonInspection */ + /** + * @inheritDoc + */ + public function getTitle() { + return WCF::getLanguage()->get($this->title); + } +} diff --git a/wcfsetup/install/files/lib/data/trophy/category/TrophyCategoryCache.class.php b/wcfsetup/install/files/lib/data/trophy/category/TrophyCategoryCache.class.php new file mode 100644 index 0000000000..a1f320c660 --- /dev/null +++ b/wcfsetup/install/files/lib/data/trophy/category/TrophyCategoryCache.class.php @@ -0,0 +1,93 @@ + + * @package WoltLabSuite\Core\Data\Trophy\Category + * @since 3.1 + */ +class TrophyCategoryCache extends SingletonFactory { + /** + * All categories for trophies. + * @var TrophyCategory[] + */ + protected $categories = []; + + /** + * All enabled categories for trophies. + * @var TrophyCategory[] + */ + protected $enabledCategories = []; + + /** + * @inheritDoc + */ + public function init() { + $categoryData = CategoryCacheBuilder::getInstance()->getData(); + if (isset($categoryData['objectTypeCategoryIDs'][TrophyCategory::OBJECT_TYPE_NAME])) { + $categoryIDs = $categoryData['objectTypeCategoryIDs'][TrophyCategory::OBJECT_TYPE_NAME]; + + foreach ($categoryIDs as $categoryID) { + $this->categories[$categoryID] = new TrophyCategory($categoryData['categories'][$categoryID]); + + if (!$categoryData['categories'][$categoryID]->isDisabled) { + $this->enabledCategories[$categoryID] = $this->categories[$categoryID]; + } + } + } + } + + /** + * Returns the trophy category with the given id. + * + * @param integer $categoryID + * @return TrophyCategory|null + */ + public function getCategoryByID($categoryID) { + if (isset($this->categories[$categoryID])) { + return $this->categories[$categoryID]; + } + + return null; + } + + /** + * Returns the categories with the given id. + * + * @param integer[] $categoryID + * @return TrophyCategory[] + */ + public function getCategoriesByID(array $categoryID) { + $returnValues = []; + + foreach ($categoryID as $categoryID) { + $returnValues[] = $this->getCategoryByID($categoryID); + } + + return $returnValues; + } + + /** + * Return all categories. + * + * @return TrophyCategory[] + */ + public function getCategories() { + return $this->categories; + } + + /** + * Return all enabled categories. + * + * @return TrophyCategory[] + */ + public function getEnabledCategories() { + return $this->enabledCategories; + } +} -- 2.20.1