2 namespace wcf\system\condition\user;
3 use wcf\data\condition\Condition;
4 use wcf\data\DatabaseObject;
5 use wcf\data\DatabaseObjectList;
6 use wcf\data\user\User;
7 use wcf\data\user\UserList;
8 use wcf\system\condition\AbstractSingleFieldCondition;
9 use wcf\system\condition\IObjectCondition;
10 use wcf\system\condition\IObjectListCondition;
11 use wcf\system\exception\UserInputException;
13 use wcf\util\ClassUtil;
16 * User condition for the interval (in days) of their last activity.
18 * @author Matthias Schmidt
19 * @copyright 2001-2020 WoltLab GmbH
20 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
21 * @package WoltLabSuite\Core\System\Condition\User
24 class UserLastActivityTimeIntervalDaysCondition extends AbstractSingleFieldCondition implements IObjectCondition, IObjectListCondition {
28 protected $label = 'wcf.user.condition.lastActivityTimeIntervalDays';
31 * end value of the days interval
34 protected $endDays = '';
37 * start value of the days interval
40 protected $startDays = '';
45 public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) {
46 if (!($objectList instanceof UserList)) {
47 throw new \InvalidArgumentException("Object list is no instance of '" . UserList::class . "', instance of '".get_class($objectList)."' given.");
50 /** @noinspection PhpUndefinedFieldInspection */
51 if ($this->object->ignoreZeroTime) {
52 $objectList->getConditionBuilder()->add('user_table.lastActivityTime <> ?', [0]);
54 if (isset($conditionData['startDays'])) {
55 $objectList->getConditionBuilder()->add('user_table.lastActivityTime <= ?', [TIME_NOW - $conditionData['startDays'] * 24 * 3600]);
57 if (isset($conditionData['endDays'])) {
58 $objectList->getConditionBuilder()->add('user_table.lastActivityTime >= ?', [TIME_NOW - $conditionData['endDays'] * 24 * 3600]);
65 public function checkObject(DatabaseObject $object, array $conditionData) {
66 if (!($object instanceof User) && !ClassUtil::isDecoratedInstanceOf($object, User::class)) {
67 throw new \InvalidArgumentException("Object is no instance of '" . User::class . "', instance of '".get_class($object)."' given.");
70 if (isset($conditionData['startDays'])) {
71 if ($object->lastActivityTime > TIME_NOW - $conditionData['startDays'] * 24 * 3600) {
75 if (isset($conditionData['endDays'])) {
76 if ($object->lastActivityTime < TIME_NOW - $conditionData['endDays'] * 24 * 3600) {
83 else if (isset($conditionData['endDays']) && $object->lastActivityTime < TIME_NOW - $conditionData['endDays'] * 24 * 3600) {
93 public function getData() {
96 if (strlen($this->startDays)) {
97 $data['startDays'] = $this->startDays;
99 if (strlen($this->endDays)) {
100 $data['endDays'] = $this->endDays;
113 protected function getFieldElement() {
114 $start = WCF::getLanguage()->get('wcf.date.period.start');
115 $end = WCF::getLanguage()->get('wcf.date.period.end');
116 $days = WCF::getLanguage()->get('wcf.acp.option.suffix.days');
119 <div class="inputAddon">
120 <input type="number" id="userLastActivityTimeIntervalStartDays" name="userLastActivityTimeIntervalStartDays" class="short" min="1" value="{$this->startDays}" placeholder="{$start}">
121 <span class="inputSuffix">{$days}</span>
123 <div class="inputAddon">
124 <input type="number" id="userLastActivityTimeIntervalEndDays" name="userLastActivityTimeIntervalEndDays" class="short" min="1" value="{$this->endDays}" placeholder="{$end}">
125 <span class="inputSuffix">{$days}</span>
133 public function readFormParameters() {
134 if (isset($_POST['userLastActivityTimeIntervalEndDays'])) $this->endDays = $_POST['userLastActivityTimeIntervalEndDays'];
135 if (isset($_POST['userLastActivityTimeIntervalStartDays'])) $this->startDays = $_POST['userLastActivityTimeIntervalStartDays'];
141 public function reset() {
143 $this->startDays = '';
149 public function setData(Condition $condition) {
150 /** @noinspection PhpUndefinedFieldInspection */
151 $endDays = $condition->endDays;
153 $this->endDays = $endDays;
156 /** @noinspection PhpUndefinedFieldInspection */
157 $startDays = $condition->startDays;
159 $this->startDays = $startDays;
166 public function validate() {
167 $endDays = $startDays = null;
168 if (strlen($this->startDays)) {
169 $startDays = intval($this->startDays);
170 if ($startDays <= 0) {
171 $this->errorMessage = 'wcf.user.condition.lastActivityTimeIntervalDays.error.invalidStart';
173 throw new UserInputException('userLastActivityTimeIntervalDays', 'invalidStart');
176 if (strlen($this->endDays)) {
177 $endDays = intval($this->endDays);
179 $this->errorMessage = 'wcf.user.condition.lastActivityTimeIntervalDays.error.invalidEnd';
181 throw new UserInputException('userLastActivityTimeIntervalDays', 'invalidEnd');
185 if ($endDays !== null && $startDays !== null && $endDays <= $startDays) {
186 $this->errorMessage = 'wcf.user.condition.lastActivityTimeIntervalDays.error.endBeforeStart';
188 throw new UserInputException('userLastActivityTimeIntervalDays', 'endBeforeStart');