Add bulk reverting frontend
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / acp / form / UserContentRevertChangesForm.class.php
CommitLineData
7bbcd781
TD
1<?php
2namespace wcf\acp\form;
3use wcf\data\object\type\ObjectTypeCache;
4use wcf\form\AbstractForm;
5use wcf\system\clipboard\ClipboardHandler;
6use wcf\system\edit\EditHistoryManager;
7use wcf\system\exception\IllegalLinkException;
8use wcf\system\exception\UserInputException;
9use wcf\system\WCF;
10
11/**
12 * Shows the user content revert changes form.
13 *
14 * @author Tim Duesterhus
15 * @copyright 2001-2014 WoltLab GmbH
16 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
17 * @package com.woltlab.wcf
18 * @subpackage acp.form
19 * @category Community Framework
20 */
21class UserContentRevertChangesForm extends AbstractForm {
22 /**
23 * @see \wcf\page\AbstractPage::$neededPermissions
24 */
25 public $neededPermissions = array('admin.content.canBulkRevertContentChanges');
26
27 /**
28 * @see \wcf\page\AbstractPage::$activeMenuItem
29 */
30 public $activeMenuItem = 'wcf.acp.menu.link.user.management';
31
32 /**
33 * ids of the relevant users
34 * @var array<integer>
35 */
36 public $userIDs = array();
37
38 /**
39 * relevant users
40 * @var array<\wcf\data\user\User>
41 */
42 public $users = array();
43
44 /**
45 * timeframe to consider
46 * @var integer
47 */
48 public $timeframe = 7;
49
50 /**
51 * id of the user clipboard item object type
52 * @var integer
53 */
54 protected $objectTypeID = null;
55
56 /**
57 * @see \wcf\page\IPage::readParameters()
58 */
59 public function readParameters() {
60 parent::readParameters();
61
62 // get object type id
63 $this->objectTypeID = ClipboardHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.user');
64 // get user
65 $this->users = ClipboardHandler::getInstance()->getMarkedItems($this->objectTypeID);
66 if (empty($this->users)) {
67 throw new IllegalLinkException();
68 }
69 $this->userIDs = array_keys($this->users);
70 }
71
72 /**
73 * @see \wcf\form\IForm::readFormParameters()
74 */
75 public function readFormParameters() {
76 parent::readFormParameters();
77
78 if (isset($_POST['timeframe'])) $this->timeframe = intval($_POST['timeframe']);
79 }
80
81 /**
82 * @see \wcf\form\IForm::validate()
83 */
84 public function validate() {
85 parent::validate();
86
87 if ($this->timeframe < 1) {
88 throw new UserInputException('timeframe');
89 }
90 }
91
92 /**
93 * @see \wcf\form\IForm::save()
94 */
95 public function save() {
96 parent::save();
97
98 EditHistoryManager::getInstance()->bulkRevert($this->userIDs, $this->timeframe * 86400);
99
100 // reset clipboard
101 ClipboardHandler::getInstance()->removeItems($this->objectTypeID);
102 $this->saved();
103
104 // show success message
105 WCF::getTPL()->assign('message', 'wcf.global.success');
106 WCF::getTPL()->display('success');
107 exit;
108 }
109
110 /**
111 * @see \wcf\page\IPage::assignVariables()
112 */
113 public function assignVariables() {
114 parent::assignVariables();
115
116 WCF::getTPL()->assign(array(
117 'users' => $this->users,
118 'userIDs' => $this->userIDs,
119 'timeframe' => $this->timeframe
120 ));
121 }
122}