Merge branch '3.0'
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / data / user / group / assignment / UserGroupAssignmentAction.class.php
1 <?php
2 namespace wcf\data\user\group\assignment;
3 use wcf\data\AbstractDatabaseObjectAction;
4 use wcf\data\IToggleAction;
5 use wcf\system\condition\ConditionHandler;
6
7 /**
8 * Executes user group assignment-related actions.
9 *
10 * @author Matthias Schmidt
11 * @copyright 2001-2018 WoltLab GmbH
12 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
13 * @package WoltLabSuite\Core\Data\User\Group\Assignment
14 *
15 * @method UserGroupAssignment create()
16 * @method UserGroupAssignmentEditor[] getObjects()
17 * @method UserGroupAssignmentEditor getSingleObject()
18 */
19 class UserGroupAssignmentAction extends AbstractDatabaseObjectAction implements IToggleAction {
20 /**
21 * @inheritDoc
22 */
23 protected $permissionsDelete = ['admin.user.canManageGroupAssignment'];
24
25 /**
26 * @inheritDoc
27 */
28 protected $permissionsUpdate = ['admin.user.canManageGroupAssignment'];
29
30 /**
31 * @inheritDoc
32 */
33 protected $requireACP = ['create', 'delete', 'toggle', 'update'];
34
35 /**
36 * @inheritDoc
37 */
38 public function delete() {
39 ConditionHandler::getInstance()->deleteConditions('com.woltlab.wcf.condition.userGroupAssignment', $this->objectIDs);
40
41 return parent::delete();
42 }
43
44 /**
45 * @inheritDoc
46 */
47 public function toggle() {
48 foreach ($this->getObjects() as $assignment) {
49 $assignment->update([
50 'isDisabled' => $assignment->isDisabled ? 0 : 1
51 ]);
52 }
53 }
54
55 /**
56 * @inheritDoc
57 */
58 public function validateToggle() {
59 parent::validateUpdate();
60 }
61 }