833d4d101298f843320850e5a8dabd145f7a90ad
[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\UserList;
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-2016 WoltLab GmbH
19 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
20 * @package com.woltlab.wcf
21 * @subpackage system.moderation.queue
22 * @category Community Framework
23 */
24 class UserModerationQueueReportHandler extends AbstractModerationQueueHandler implements IModerationQueueReportHandler {
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 $assignments = [];
45 foreach ($queues as $queue) {
46 $assignUser = false;
47 if (WCF::getSession()->getPermission('mod.general.canUseModeration')) {
48 $assignUser = true;
49 }
50
51 $assignments[$queue->queueID] = $assignUser;
52 }
53
54 ModerationQueueManager::getInstance()->setAssignment($assignments);
55 }
56
57 /**
58 * @inheritDoc
59 */
60 public function canReport($objectID) {
61 if (!$this->isValid($objectID)) {
62 return false;
63 }
64
65 return true;
66 }
67
68 /**
69 * @inheritDoc
70 */
71 public function getContainerID($objectID) {
72 return 0;
73 }
74
75 /**
76 * @inheritDoc
77 */
78 public function getReportedContent(ViewableModerationQueue $queue) {
79 WCF::getTPL()->assign([
80 'user' => new UserProfile($queue->getAffectedObject())
81 ]);
82
83 return WCF::getTPL()->fetch('moderationUser');
84 }
85
86 /**
87 * @inheritDoc
88 */
89 public function getReportedObject($objectID) {
90 if ($this->isValid($objectID)) {
91 return $this->getUser($objectID);
92 }
93
94 return null;
95 }
96
97 /**
98 * @inheritDoc
99 */
100 public function isValid($objectID) {
101 if ($this->getUser($objectID) === null) {
102 return false;
103 }
104
105 return true;
106 }
107
108 /**
109 * Returns a user object by user id or null if user id is invalid.
110 *
111 * @param integer $objectID
112 * @return User|null
113 */
114 protected function getUser($objectID) {
115 return UserRuntimeCache::getInstance()->getObject($objectID);
116 }
117
118 /**
119 * @inheritDoc
120 */
121 public function populate(array $queues) {
122 $objectIDs = [];
123 foreach ($queues as $object) {
124 $objectIDs[] = $object->objectID;
125 }
126
127 $users = UserRuntimeCache::getInstance()->getObjects($objectIDs);
128 foreach ($queues as $object) {
129 if ($users[$object->objectID] !== null) {
130 $object->setAffectedObject($users[$object->objectID]);
131 }
132 else {
133 $object->setIsOrphaned();
134 }
135 }
136 }
137
138 /**
139 * @inheritDoc
140 */
141 public function canRemoveContent(ModerationQueue $queue) {
142 return false;
143 }
144
145 /**
146 * @inheritDoc
147 */
148 public function removeContent(ModerationQueue $queue, $message) {
149 throw new SystemException("it's not allowed to delete users using the moderation");
150 }
151 }