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