3 namespace wcf\system\bulk\processing\user;
5 use wcf\data\DatabaseObject;
6 use wcf\data\DatabaseObjectList;
7 use wcf\data\user\group\UserGroup;
8 use wcf\data\user\UserEditor;
9 use wcf\data\user\UserList;
10 use wcf\system\exception\UserInputException;
11 use wcf\system\user\storage\UserStorageHandler;
13 use wcf\util\ArrayUtil;
16 * Abstract implementation of a user bulk processing action related to selecting
19 * @author Matthias Schmidt
20 * @copyright 2001-2019 WoltLab GmbH
21 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
22 * @package WoltLabSuite\Core\System\Bulk\Processing\User
25 abstract class AbstractUserGroupsUserBulkProcessingAction extends AbstractUserBulkProcessingAction
28 * list of available user groups
31 public $availableUserGroups = [];
34 * name of the inputs used to store the selected user group ids
37 public $inputName = '';
40 * ids of selected user groups
43 public $userGroupIDs = [];
48 public function __construct(DatabaseObject $object)
50 parent::__construct($object);
52 $this->availableUserGroups = UserGroup::getSortedAccessibleGroups(
54 [UserGroup::GUESTS, UserGroup::EVERYONE, UserGroup::OWNER, UserGroup::USERS]
61 public function executeAction(DatabaseObjectList $objectList)
63 if (!($objectList instanceof UserList)) {
64 throw new \InvalidArgumentException("Object list is no instance of '" . UserList::class . "', instance of '" . \get_class($objectList) . "' given.");
67 $users = $this->getAccessibleUsers($objectList);
70 WCF::getDB()->beginTransaction();
71 foreach ($users as $user) {
72 $user = new UserEditor($user);
73 $this->executeUserAction($user);
75 WCF::getDB()->commitTransaction();
77 UserStorageHandler::getInstance()->reset(\array_keys($users), 'groupIDs');
82 * Execute the action for the given user.
84 * @param UserEditor $user
86 abstract protected function executeUserAction(UserEditor $user);
91 public function getHTML()
93 return WCF::getTPL()->fetch('userGroupListUserBulkProcessing', 'wcf', [
94 'availableUserGroups' => $this->availableUserGroups,
95 'inputName' => $this->inputName,
96 'selectedUserGroupIDs' => $this->userGroupIDs,
103 public function isAvailable()
105 return !empty($this->availableUserGroups);
111 public function readFormParameters()
113 if (isset($_POST[$this->inputName])) {
114 $this->userGroupIDs = ArrayUtil::toIntegerArray($_POST[$this->inputName]);
121 public function reset()
123 $this->userGroupIDs = [];
129 public function validate()
131 if (empty($this->userGroupIDs)) {
132 throw new UserInputException($this->inputName);
135 foreach ($this->userGroupIDs as $groupID) {
136 if (!isset($this->availableUserGroups[$groupID])) {
137 throw new UserInputException($this->inputName, 'noValidSelection');