Commit | Line | Data |
---|---|---|
e539f186 JR |
1 | <?php |
2 | namespace wcf\system\category; | |
9e1fe407 JR |
3 | use wcf\data\category\CategoryEditor; |
4 | use wcf\data\user\trophy\UserTrophyAction; | |
5 | use wcf\data\user\trophy\UserTrophyList; | |
e539f186 JR |
6 | use wcf\system\WCF; |
7 | ||
8 | /** | |
9 | * Trophy category type. | |
10 | * | |
11 | * @author Joshua Ruesweg | |
c839bd49 | 12 | * @copyright 2001-2018 WoltLab GmbH |
e539f186 JR |
13 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> |
14 | * @package WoltLabSuite\Core\System\Category | |
15 | * @since 3.1 | |
16 | */ | |
17 | class TrophyCategoryType extends AbstractCategoryType { | |
18 | /** | |
19 | * @inheritDoc | |
20 | */ | |
21 | protected $langVarPrefix = 'wcf.trophy.category'; | |
22 | ||
23 | /** | |
24 | * @inheritDoc | |
25 | */ | |
26 | protected $maximumNestingLevel = 0; | |
27 | ||
aed0411e JR |
28 | /** |
29 | * @inheritDoc | |
30 | */ | |
31 | protected $forceDescription = false; | |
32 | ||
e539f186 JR |
33 | /** @noinspection PhpMissingParentCallCommonInspection */ |
34 | /** | |
35 | * @inheritDoc | |
36 | */ | |
37 | public function canAddCategory() { | |
38 | return $this->canEditCategory(); | |
39 | } | |
40 | ||
41 | /** @noinspection PhpMissingParentCallCommonInspection */ | |
42 | /** | |
43 | * @inheritDoc | |
44 | */ | |
45 | public function canDeleteCategory() { | |
46 | return $this->canEditCategory(); | |
47 | } | |
48 | ||
49 | /** @noinspection PhpMissingParentCallCommonInspection */ | |
50 | /** | |
51 | * @inheritDoc | |
52 | */ | |
53 | public function canEditCategory() { | |
54 | return WCF::getSession()->getPermission('admin.trophy.canManageTrophy'); | |
55 | } | |
9e1fe407 JR |
56 | |
57 | /** | |
58 | * @inheritDoc | |
59 | */ | |
60 | public function beforeDeletion(CategoryEditor $categoryEditor) { | |
61 | // update user trophyPoints | |
62 | $userTrophyList = new UserTrophyList(); | |
63 | if (!empty($userTrophyList->sqlJoins)) $userTrophyList->sqlJoins .= ' '; | |
64 | $userTrophyList->sqlJoins .= 'LEFT JOIN wcf'.WCF_N.'_trophy trophy ON user_trophy.trophyID = trophy.trophyID'; | |
65 | $userTrophyList->sqlJoins .= ' LEFT JOIN wcf'.WCF_N.'_category category ON trophy.categoryID = category.categoryID'; | |
66 | ||
67 | $userTrophyList->getConditionBuilder()->add('trophy.isDisabled = ?', [0]); | |
68 | $userTrophyList->getConditionBuilder()->add('category.isDisabled = ?', [0]); | |
69 | $userTrophyList->getConditionBuilder()->add('category.categoryID = ?', [$categoryEditor->categoryID]); | |
70 | $userTrophyList->readObjects(); | |
71 | ||
72 | $userTrophyAction = new UserTrophyAction($userTrophyList->getObjects(), 'delete'); | |
73 | $userTrophyAction->executeAction(); | |
74 | } | |
e539f186 | 75 | } |