00ee75af8e47958c95e28175c78354d8741186b8
[GitHub/WoltLab/WCF.git] /
1 <?php
2 namespace wcf\system\moderation\queue\report;
3 use wcf\data\moderation\queue\ModerationQueue;
4 use wcf\data\moderation\queue\ViewableModerationQueue;
5 use wcf\data\user\User;
6 use wcf\data\user\UserProfile;
7 use wcf\system\cache\runtime\UserRuntimeCache;
8 use wcf\system\exception\SystemException;
9 use wcf\system\moderation\queue\AbstractModerationQueueHandler;
10 use wcf\system\moderation\queue\ModerationQueueManager;
11 use wcf\system\WCF;
12
13 /**
14 * An implementation of IModerationQueueReportHandler for user profiles.
15 *
16 * @author Marcel Werk
17 * @copyright 2001-2016 WoltLab GmbH
18 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
19 * @package WoltLabSuite\Core\System\Moderation\Queue
20 */
21 class UserModerationQueueReportHandler extends AbstractModerationQueueHandler implements IModerationQueueReportHandler {
22 /**
23 * @inheritDoc
24 */
25 protected $className = User::class;
26
27 /**
28 * @inheritDoc
29 */
30 protected $definitionName = 'com.woltlab.wcf.moderation.report';
31
32 /**
33 * @inheritDoc
34 */
35 protected $objectType = 'com.woltlab.wcf.user';
36
37 /**
38 * @inheritDoc
39 */
40 public function assignQueues(array $queues) {
41 $assignments = [];
42 foreach ($queues as $queue) {
43 $assignUser = false;
44 if (WCF::getSession()->getPermission('mod.general.canUseModeration')) {
45 $assignUser = true;
46 }
47
48 $assignments[$queue->queueID] = $assignUser;
49 }
50
51 ModerationQueueManager::getInstance()->setAssignment($assignments);
52 }
53
54 /**
55 * @inheritDoc
56 */
57 public function canReport($objectID) {
58 if (!$this->isValid($objectID)) {
59 return false;
60 }
61
62 return true;
63 }
64
65 /**
66 * @inheritDoc
67 */
68 public function getContainerID($objectID) {
69 return 0;
70 }
71
72 /**
73 * @inheritDoc
74 */
75 public function getReportedContent(ViewableModerationQueue $queue) {
76 /** @noinspection PhpParamsInspection */
77 WCF::getTPL()->assign([
78 'user' => new UserProfile($queue->getAffectedObject())
79 ]);
80
81 return WCF::getTPL()->fetch('moderationUser');
82 }
83
84 /**
85 * @inheritDoc
86 */
87 public function getReportedObject($objectID) {
88 if ($this->isValid($objectID)) {
89 return $this->getUser($objectID);
90 }
91
92 return null;
93 }
94
95 /**
96 * @inheritDoc
97 */
98 public function isValid($objectID) {
99 if ($this->getUser($objectID) === null) {
100 return false;
101 }
102
103 return true;
104 }
105
106 /**
107 * Returns a user object by user id or null if user id is invalid.
108 *
109 * @param integer $objectID
110 * @return User|null
111 */
112 protected function getUser($objectID) {
113 return UserRuntimeCache::getInstance()->getObject($objectID);
114 }
115
116 /**
117 * @inheritDoc
118 */
119 public function populate(array $queues) {
120 $objectIDs = [];
121 foreach ($queues as $object) {
122 $objectIDs[] = $object->objectID;
123 }
124
125 $users = UserRuntimeCache::getInstance()->getObjects($objectIDs);
126 foreach ($queues as $object) {
127 if ($users[$object->objectID] !== null) {
128 $object->setAffectedObject($users[$object->objectID]);
129 }
130 else {
131 $object->setIsOrphaned();
132 }
133 }
134 }
135
136 /**
137 * @inheritDoc
138 */
139 public function canRemoveContent(ModerationQueue $queue) {
140 return false;
141 }
142
143 /**
144 * @inheritDoc
145 */
146 public function removeContent(ModerationQueue $queue, $message) {
147 throw new SystemException("it's not allowed to delete users using the moderation");
148 }
149 }