3960385c0fbd737e783f9a23bd838c9620ac0e81
[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\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-2014 WoltLab GmbH
18 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
19 * @package com.woltlab.wcf
20 * @subpackage system.moderation.queue
21 * @category Community Framework
22 */
23 class UserModerationQueueReportHandler extends AbstractModerationQueueHandler implements IModerationQueueReportHandler {
24 /**
25 * @see \wcf\system\moderation\queue\AbstractModerationQueueHandler::$className
26 */
27 protected $className = 'wcf\data\user\User';
28
29 /**
30 * @see \wcf\system\moderation\queue\AbstractModerationQueueHandler::$definitionName
31 */
32 protected $definitionName = 'com.woltlab.wcf.moderation.report';
33
34 /**
35 * @see \wcf\system\moderation\queue\AbstractModerationQueueHandler::$objectType
36 */
37 protected $objectType = 'com.woltlab.wcf.user';
38
39 /**
40 * list of users
41 * @var array<\wcf\data\user\User>
42 */
43 protected static $users = array();
44
45 /**
46 * @see \wcf\system\moderation\queue\IModerationQueueHandler::assignQueues()
47 */
48 public function assignQueues(array $queues) {
49 $assignments = array();
50 foreach ($queues as $queue) {
51 $assignUser = false;
52 if (WCF::getSession()->getPermission('mod.general.canUseModeration')) {
53 $assignUser = true;
54 }
55
56 $assignments[$queue->queueID] = $assignUser;
57 }
58
59 ModerationQueueManager::getInstance()->setAssignment($assignments);
60 }
61
62 /**
63 * @see \wcf\system\moderation\queue\report\IModerationQueueReportHandler::canReport()
64 */
65 public function canReport($objectID) {
66 if (!$this->isValid($objectID)) {
67 return false;
68 }
69
70 return true;
71 }
72
73 /**
74 * @see \wcf\system\moderation\queue\IModerationQueueHandler::getContainerID()
75 */
76 public function getContainerID($objectID) {
77 return 0;
78 }
79
80 /**
81 * @see \wcf\system\moderation\queue\report\IModerationQueueReportHandler::getReportedContent()
82 */
83 public function getReportedContent(ViewableModerationQueue $queue) {
84 WCF::getTPL()->assign(array(
85 'user' => new UserProfile($queue->getAffectedObject())
86 ));
87
88 return WCF::getTPL()->fetch('moderationUser');
89 }
90
91 /**
92 * @see \wcf\system\moderation\queue\report\IModerationQueueReportHandler::getReportedObject()
93 */
94 public function getReportedObject($objectID) {
95 if ($this->isValid($objectID)) {
96 return $this->getUser($objectID);
97 }
98
99 return null;
100 }
101
102 /**
103 * @see \wcf\system\moderation\queue\IModerationQueueHandler::isValid()
104 */
105 public function isValid($objectID) {
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 integer $objectID
117 * @return \wcf\data\user\User
118 */
119 protected function getUser($objectID) {
120 if (!array_key_exists($objectID, self::$users)) {
121 self::$users[$objectID] = new User($objectID);
122 if (!self::$users[$objectID]->userID) {
123 self::$users[$objectID] = null;
124 }
125 }
126
127 return self::$users[$objectID];
128 }
129
130 /**
131 * @see \wcf\system\moderation\queue\IModerationQueueHandler::populate()
132 */
133 public function populate(array $queues) {
134 $objectIDs = array();
135 foreach ($queues as $object) {
136 $objectIDs[] = $object->objectID;
137 }
138
139 // fetch users
140 $userList = new UserList();
141 $userList->setObjectIDs($objectIDs);
142 $userList->readObjects();
143 $users = $userList->getObjects();
144
145 foreach ($queues as $object) {
146 if (isset($users[$object->objectID])) {
147 $object->setAffectedObject($users[$object->objectID]);
148 }
149 else {
150 $object->setIsOrphaned();
151 }
152 }
153 }
154
155 /**
156 * @see \wcf\system\moderation\queue\IModerationQueueHandler::removeContent()
157 */
158 public function removeContent(ModerationQueue $queue, $message) {
159 throw new SystemException("it's not allowed to delete users using the moderation");
160 }
161 }