2 namespace wcf\system\category
;
3 use wcf\data\category\CategoryEditor
;
4 use wcf\system\database\util\PreparedStatementConditionBuilder
;
5 use wcf\system\SingletonFactory
;
9 * Abstract implementation of a category type.
11 * @author Matthias Schmidt
12 * @copyright 2001-2018 WoltLab GmbH
13 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
14 * @package WoltLabSuite\Core\System\Category
16 abstract class AbstractCategoryType
extends SingletonFactory
implements ICategoryType
{
18 * indicates if categories of this type may have no empty description
21 protected $forceDescription = true;
24 * indicates if categories of this type have descriptions
27 protected $hasDescription = true;
30 * language category which contains the language variables of i18n values
33 protected $i18nLangVarCategory = 'wcf.category';
36 * prefix used for language variables in templates
39 protected $langVarPrefix = '';
42 * permission prefix for the add/delete/edit permissions
45 protected $permissionPrefix = '';
48 * maximum category nesting label
51 protected $maximumNestingLevel = -1;
54 * name of the object types associated with categories of this type (the
55 * key is the definition name and value the object type name)
58 protected $objectTypes = [];
63 public function afterDeletion(CategoryEditor
$categoryEditor) {
64 $categoryIDs = array_keys(CategoryHandler
::getInstance()->getChildCategories($categoryEditor->categoryID
));
66 if (!empty($categoryIDs)) {
67 // move child categories to parent category
68 $conditionBuilder = new PreparedStatementConditionBuilder();
69 $conditionBuilder->add("categoryID IN (?)", [$categoryIDs]);
70 $sql = "UPDATE wcf".WCF_N
."_category
71 SET parentCategoryID = ?
73 $statement = WCF
::getDB()->prepareStatement($sql);
74 $statement->execute(array_merge([$categoryEditor->parentCategoryID
], $conditionBuilder->getParameters()));
81 public function beforeDeletion(CategoryEditor
$categoryEditor) {
88 public function canAddCategory() {
89 return WCF
::getSession()->getPermission($this->permissionPrefix
.'.canAddCategory');
95 public function canDeleteCategory() {
96 return WCF
::getSession()->getPermission($this->permissionPrefix
.'.canDeleteCategory');
102 public function canEditCategory() {
103 return WCF
::getSession()->getPermission($this->permissionPrefix
.'.canEditCategory');
109 public function changedParentCategories(array $categoryData) {
116 public function forceDescription() {
117 return $this->hasDescription() && $this->forceDescription
;
123 public function getApplication() {
124 $classParts = explode('\\', get_called_class());
125 return $classParts[0];
131 public function getObjectTypeName($definitionName) {
132 if (isset($this->objectTypes
[$definitionName])) {
133 return $this->objectTypes
[$definitionName];
142 public function getDescriptionLangVarCategory() {
143 return $this->i18nLangVarCategory
;
149 public function getI18nLangVarPrefix() {
150 return $this->i18nLangVarCategory
.'.category';
156 public function getLanguageVariable($name, $optional = false) {
157 if ($this->langVarPrefix
) {
158 $value = WCF
::getLanguage()->getDynamicVariable($this->langVarPrefix
.'.'.$name, [], true);
164 return WCF
::getLanguage()->getDynamicVariable('wcf.category.'.$name, [], $optional);
170 public function getMaximumNestingLevel() {
171 return $this->maximumNestingLevel
;
177 public function getTitleLangVarCategory() {
178 return $this->i18nLangVarCategory
;
184 public function hasDescription() {
185 return $this->hasDescription
;
192 public function supportsHtmlDescription() {