2 declare(strict_types
=1);
3 namespace wcf\system\category
;
4 use wcf\data\category\CategoryEditor
;
5 use wcf\system\database\util\PreparedStatementConditionBuilder
;
6 use wcf\system\SingletonFactory
;
10 * Abstract implementation of a category type.
12 * @author Matthias Schmidt
13 * @copyright 2001-2018 WoltLab GmbH
14 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
15 * @package WoltLabSuite\Core\System\Category
17 abstract class AbstractCategoryType
extends SingletonFactory
implements ICategoryType
{
19 * indicates if categories of this type may have no empty description
22 protected $forceDescription = true;
25 * indicates if categories of this type have descriptions
28 protected $hasDescription = true;
31 * language category which contains the language variables of i18n values
34 protected $i18nLangVarCategory = 'wcf.category';
37 * prefix used for language variables in templates
40 protected $langVarPrefix = '';
43 * permission prefix for the add/delete/edit permissions
46 protected $permissionPrefix = '';
49 * maximum category nesting label
52 protected $maximumNestingLevel = -1;
55 * name of the object types associated with categories of this type (the
56 * key is the definition name and value the object type name)
59 protected $objectTypes = [];
64 public function afterDeletion(CategoryEditor
$categoryEditor) {
65 $categoryIDs = array_keys(CategoryHandler
::getInstance()->getChildCategories($categoryEditor->categoryID
));
67 if (!empty($categoryIDs)) {
68 // move child categories to parent category
69 $conditionBuilder = new PreparedStatementConditionBuilder();
70 $conditionBuilder->add("categoryID IN (?)", [$categoryIDs]);
71 $sql = "UPDATE wcf".WCF_N
."_category
72 SET parentCategoryID = ?
74 $statement = WCF
::getDB()->prepareStatement($sql);
75 $statement->execute(array_merge([$categoryEditor->parentCategoryID
], $conditionBuilder->getParameters()));
82 public function beforeDeletion(CategoryEditor
$categoryEditor) {
89 public function canAddCategory() {
90 return WCF
::getSession()->getPermission($this->permissionPrefix
.'.canAddCategory');
96 public function canDeleteCategory() {
97 return WCF
::getSession()->getPermission($this->permissionPrefix
.'.canDeleteCategory');
103 public function canEditCategory() {
104 return WCF
::getSession()->getPermission($this->permissionPrefix
.'.canEditCategory');
110 public function changedParentCategories(array $categoryData) {
117 public function forceDescription() {
118 return $this->hasDescription() && $this->forceDescription
;
124 public function getApplication() {
125 $classParts = explode('\\', get_called_class());
126 return $classParts[0];
132 public function getObjectTypeName($definitionName) {
133 if (isset($this->objectTypes
[$definitionName])) {
134 return $this->objectTypes
[$definitionName];
143 public function getDescriptionLangVarCategory() {
144 return $this->i18nLangVarCategory
;
150 public function getI18nLangVarPrefix() {
151 return $this->i18nLangVarCategory
.'.category';
157 public function getLanguageVariable($name, $optional = false) {
158 if ($this->langVarPrefix
) {
159 $value = WCF
::getLanguage()->getDynamicVariable($this->langVarPrefix
.'.'.$name, [], true);
165 return WCF
::getLanguage()->getDynamicVariable('wcf.category.'.$name, [], $optional);
171 public function getMaximumNestingLevel() {
172 return $this->maximumNestingLevel
;
178 public function getTitleLangVarCategory() {
179 return $this->i18nLangVarCategory
;
185 public function hasDescription() {
186 return $this->hasDescription
;