f04539ccc436d7b7f142300af46a54d0b1cb850d
[GitHub/WoltLab/WCF.git] /
1 <?php
2 declare(strict_types=1);
3 namespace wcf\system\condition\user\trophy;
4 use wcf\data\trophy\category\TrophyCategoryCache;
5 use wcf\data\user\trophy\UserTrophyList;
6 use wcf\data\DatabaseObjectList;
7 use wcf\system\condition\AbstractMultiSelectCondition;
8 use wcf\system\condition\IObjectListCondition;
9
10 /**
11 * Condition implementation for the excluded trophies.
12 *
13 * @author Joshua Ruesweg
14 * @copyright 2001-2018 WoltLab GmbH
15 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
16 * @package WoltLabSuite\Core\System\Condition\User\Trophy
17 * @since 3.1
18 */
19 class UserTrophyExcludedTrophyCategoriesCondition extends AbstractMultiSelectCondition implements IObjectListCondition {
20 /**
21 * @inheritDoc
22 */
23 protected $description = 'wcf.global.multiSelect';
24
25 /**
26 * @inheritDoc
27 */
28 protected $fieldName = 'userTrophyExcludedTrophyCategories';
29
30 /**
31 * @inheritDoc
32 */
33 protected $label = 'wcf.user.trophy.condition.excludedTrophyCategories';
34
35 /**
36 * @inheritDoc
37 */
38 public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) {
39 if (!($objectList instanceof UserTrophyList)) {
40 throw new \InvalidArgumentException("Object list is no instance of '".UserTrophyList::class."', instance of '".get_class($objectList)."' given.");
41 }
42
43 $objectList->getConditionBuilder()->add('user_trophy.category NOT IN (?)', [$conditionData[$this->fieldName]]);
44 }
45
46 /**
47 * @inheritDoc
48 */
49 public function getOptions() {
50 $categories = TrophyCategoryCache::getInstance()->getCategories();
51
52 $options = [];
53 foreach ($categories as $category) {
54 $options[$category->categoryID] = $category->getTitle();
55 }
56
57 asort($options);
58
59 return $options;
60 }
61 }