3 namespace wcf\system\condition\user;
5 use wcf\data\condition\Condition;
6 use wcf\data\DatabaseObject;
7 use wcf\data\DatabaseObjectList;
8 use wcf\data\user\User;
9 use wcf\data\user\UserList;
10 use wcf\system\condition\AbstractSingleFieldCondition;
11 use wcf\system\condition\IObjectCondition;
12 use wcf\system\condition\IObjectListCondition;
13 use wcf\system\exception\InvalidObjectArgument;
14 use wcf\system\exception\UserInputException;
16 use wcf\util\ClassUtil;
19 * User condition for the interval (in days) of their last activity.
21 * @author Matthias Schmidt
22 * @copyright 2001-2020 WoltLab GmbH
23 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
24 * @package WoltLabSuite\Core\System\Condition\User
27 class UserLastActivityTimeIntervalDaysCondition extends AbstractSingleFieldCondition implements
34 protected $label = 'wcf.user.condition.lastActivityTimeIntervalDays';
37 * end value of the days interval
40 protected $endDays = '';
43 * start value of the days interval
46 protected $startDays = '';
51 public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData)
53 if (!($objectList instanceof UserList)) {
54 throw new InvalidObjectArgument($objectList, UserList::class, 'Object list');
57 /** @noinspection PhpUndefinedFieldInspection */
58 if ($this->object->ignoreZeroTime) {
59 $objectList->getConditionBuilder()->add('user_table.lastActivityTime <> ?', [0]);
61 if (isset($conditionData['startDays'])) {
62 $objectList->getConditionBuilder()->add(
63 'user_table.lastActivityTime <= ?',
64 [TIME_NOW - $conditionData['startDays'] * 24 * 3600]
67 if (isset($conditionData['endDays'])) {
68 $objectList->getConditionBuilder()->add(
69 'user_table.lastActivityTime >= ?',
70 [TIME_NOW - $conditionData['endDays'] * 24 * 3600]
78 public function checkObject(DatabaseObject $object, array $conditionData)
80 if (!($object instanceof User) && !ClassUtil::isDecoratedInstanceOf($object, User::class)) {
81 throw new InvalidObjectArgument($object, User::class);
84 if (isset($conditionData['startDays'])) {
85 if ($object->lastActivityTime > TIME_NOW - $conditionData['startDays'] * 24 * 3600) {
89 if (isset($conditionData['endDays'])) {
90 if ($object->lastActivityTime < TIME_NOW - $conditionData['endDays'] * 24 * 3600) {
97 isset($conditionData['endDays'])
98 && $object->lastActivityTime < TIME_NOW - $conditionData['endDays'] * 24 * 3600
109 public function getData()
113 if (\strlen($this->startDays)) {
114 $data['startDays'] = $this->startDays;
116 if (\strlen($this->endDays)) {
117 $data['endDays'] = $this->endDays;
128 protected function getFieldElement()
130 $start = WCF::getLanguage()->get('wcf.date.period.start');
131 $end = WCF::getLanguage()->get('wcf.date.period.end');
132 $days = WCF::getLanguage()->get('wcf.acp.option.suffix.days');
135 <div class="inputAddon">
136 <input type="number" id="userLastActivityTimeIntervalStartDays" name="userLastActivityTimeIntervalStartDays" class="short" min="1" value="{$this->startDays}" placeholder="{$start}">
137 <span class="inputSuffix">{$days}</span>
139 <div class="inputAddon">
140 <input type="number" id="userLastActivityTimeIntervalEndDays" name="userLastActivityTimeIntervalEndDays" class="short" min="1" value="{$this->endDays}" placeholder="{$end}">
141 <span class="inputSuffix">{$days}</span>
149 public function readFormParameters()
151 if (isset($_POST['userLastActivityTimeIntervalEndDays'])) {
152 $this->endDays = $_POST['userLastActivityTimeIntervalEndDays'];
154 if (isset($_POST['userLastActivityTimeIntervalStartDays'])) {
155 $this->startDays = $_POST['userLastActivityTimeIntervalStartDays'];
162 public function reset()
165 $this->startDays = '';
171 public function setData(Condition $condition)
173 /** @noinspection PhpUndefinedFieldInspection */
174 $endDays = $condition->endDays;
176 $this->endDays = $endDays;
179 /** @noinspection PhpUndefinedFieldInspection */
180 $startDays = $condition->startDays;
182 $this->startDays = $startDays;
189 public function validate()
191 $endDays = $startDays = null;
192 if (\strlen($this->startDays)) {
193 $startDays = \intval($this->startDays);
194 if ($startDays <= 0) {
195 $this->errorMessage = 'wcf.user.condition.lastActivityTimeIntervalDays.error.invalidStart';
197 throw new UserInputException('userLastActivityTimeIntervalDays', 'invalidStart');
200 if (\strlen($this->endDays)) {
201 $endDays = \intval($this->endDays);
203 $this->errorMessage = 'wcf.user.condition.lastActivityTimeIntervalDays.error.invalidEnd';
205 throw new UserInputException('userLastActivityTimeIntervalDays', 'invalidEnd');
209 if ($endDays !== null && $startDays !== null && $endDays <= $startDays) {
210 $this->errorMessage = 'wcf.user.condition.lastActivityTimeIntervalDays.error.endBeforeStart';
212 throw new UserInputException('userLastActivityTimeIntervalDays', 'endBeforeStart');