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