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