From 324aa486d32e0d1e7021385657fd1388d00403ca Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Sat, 13 Jun 2020 13:40:08 +0200 Subject: [PATCH] Add last user activity time condition for today's birthday box Close #3249 --- com.woltlab.wcf/objectType.xml | 16 ++ com.woltlab.wcf/objectTypeDefinition.xml | 8 + .../TodaysBirthdaysBoxController.class.php | 17 ++ ...sFollowingBirthdaysBoxController.class.php | 6 + ...ctivityTimeIntervalDaysCondition.class.php | 191 ++++++++++++++++++ wcfsetup/install/lang/de.xml | 4 + wcfsetup/install/lang/en.xml | 4 + 7 files changed, 246 insertions(+) create mode 100644 wcfsetup/install/files/lib/system/condition/user/UserLastActivityTimeIntervalDaysCondition.class.php diff --git a/com.woltlab.wcf/objectType.xml b/com.woltlab.wcf/objectType.xml index 98963f777e..74a2caf60b 100644 --- a/com.woltlab.wcf/objectType.xml +++ b/com.woltlab.wcf/objectType.xml @@ -1595,6 +1595,22 @@ wcf\system\condition\user\trophy\UserTrophyExcludedTrophyCategoriesCondition + + + com.woltlab.wcf.lastActivityTimeIntervalDays + com.woltlab.wcf.box.todaysBirthdays.condition + wcf\system\condition\user\UserLastActivityTimeIntervalDaysCondition + 1 + + + + + com.woltlab.wcf.lastActivityTimeIntervalDays + com.woltlab.wcf.box.todaysFollowingBirthdays.condition + wcf\system\condition\user\UserLastActivityTimeIntervalDaysCondition + 1 + + com.woltlab.wcf.userGroup diff --git a/com.woltlab.wcf/objectTypeDefinition.xml b/com.woltlab.wcf/objectTypeDefinition.xml index 62bee674bf..356ef92b23 100644 --- a/com.woltlab.wcf/objectTypeDefinition.xml +++ b/com.woltlab.wcf/objectTypeDefinition.xml @@ -182,6 +182,14 @@ com.woltlab.wcf.box.recentActivityList.condition wcf\system\condition\IObjectListCondition + + com.woltlab.wcf.box.todaysBirthdays.condition + wcf\system\condition\IObjectCondition + + + com.woltlab.wcf.box.todaysFollowingBirthdays.condition + wcf\system\condition\IObjectCondition + com.woltlab.wcf.box.userList.condition wcf\system\condition\IObjectListCondition diff --git a/wcfsetup/install/files/lib/system/box/TodaysBirthdaysBoxController.class.php b/wcfsetup/install/files/lib/system/box/TodaysBirthdaysBoxController.class.php index c25cb7b644..51af2173f9 100644 --- a/wcfsetup/install/files/lib/system/box/TodaysBirthdaysBoxController.class.php +++ b/wcfsetup/install/files/lib/system/box/TodaysBirthdaysBoxController.class.php @@ -4,6 +4,9 @@ use wcf\data\DatabaseObject; use wcf\data\user\option\UserOption; use wcf\system\cache\builder\UserOptionCacheBuilder; use wcf\system\cache\runtime\UserProfileRuntimeCache; +use wcf\system\condition\ICondition; +use wcf\system\condition\IObjectCondition; +use wcf\system\condition\IObjectListCondition; use wcf\system\user\UserBirthdayCache; use wcf\system\WCF; use wcf\util\DateUtil; @@ -23,6 +26,12 @@ class TodaysBirthdaysBoxController extends AbstractDatabaseObjectListBoxControll */ protected static $supportedPositions = ['sidebarLeft', 'sidebarRight']; + /** + * @inheritDoc + * @since 5.3 + */ + protected $conditionDefinition = 'com.woltlab.wcf.box.todaysBirthdays.condition'; + /** * template name * @var string @@ -96,6 +105,14 @@ class TodaysBirthdaysBoxController extends AbstractDatabaseObjectListBoxControll // show a maximum of x users if ($i == $this->limit) break; + foreach ($this->box->getConditions() as $condition) { + /** @var IObjectCondition $processor */ + $processor = $condition->getObjectType()->getProcessor(); + if (!$processor->checkObject($userProfile->getDecoratedObject(), $condition->conditionData)) { + continue 2; + } + } + $birthdayUserOption->setUser($userProfile->getDecoratedObject()); if (!$userProfile->isProtected() && $birthdayUserOption->isVisible() && substr($userProfile->birthday, 5) == $currentDay) { diff --git a/wcfsetup/install/files/lib/system/box/TodaysFollowingBirthdaysBoxController.class.php b/wcfsetup/install/files/lib/system/box/TodaysFollowingBirthdaysBoxController.class.php index ffbf21308e..65a7ca0f76 100644 --- a/wcfsetup/install/files/lib/system/box/TodaysFollowingBirthdaysBoxController.class.php +++ b/wcfsetup/install/files/lib/system/box/TodaysFollowingBirthdaysBoxController.class.php @@ -12,6 +12,12 @@ use wcf\system\WCF; * @since 3.0 */ class TodaysFollowingBirthdaysBoxController extends TodaysBirthdaysBoxController { + /** + * @inheritDoc + * @since 5.3 + */ + protected $conditionDefinition = 'com.woltlab.wcf.box.todaysFollowingBirthdays.condition'; + /** * @inheritDoc */ diff --git a/wcfsetup/install/files/lib/system/condition/user/UserLastActivityTimeIntervalDaysCondition.class.php b/wcfsetup/install/files/lib/system/condition/user/UserLastActivityTimeIntervalDaysCondition.class.php new file mode 100644 index 0000000000..18665dd4ad --- /dev/null +++ b/wcfsetup/install/files/lib/system/condition/user/UserLastActivityTimeIntervalDaysCondition.class.php @@ -0,0 +1,191 @@ + + * @package WoltLabSuite\Core\System\Condition\User + * @since 5.3 + */ +class UserLastActivityTimeIntervalDaysCondition extends AbstractSingleFieldCondition implements IObjectCondition, IObjectListCondition { + /** + * @inheritDoc + */ + protected $label = 'wcf.user.condition.lastActivityTimeIntervalDays'; + + /** + * end value of the days interval + * @var int|string + */ + protected $endDays = ''; + + /** + * start value of the days interval + * @var int|string + */ + protected $startDays = ''; + + /** + * @inheritDoc + */ + public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) { + if (!($objectList instanceof UserList)) { + throw new \InvalidArgumentException("Object list is no instance of '" . UserList::class . "', instance of '".get_class($objectList)."' given."); + } + + /** @noinspection PhpUndefinedFieldInspection */ + if ($this->object->ignoreZeroTime) { + $objectList->getConditionBuilder()->add('user_table.lastActivityTime <> ?', [0]); + } + if (isset($conditionData['startDays'])) { + $objectList->getConditionBuilder()->add('user_table.lastActivityTime <= ?', [TIME_NOW - $conditionData['startDays'] * 24 * 3600]); + } + if (isset($conditionData['endDays'])) { + $objectList->getConditionBuilder()->add('user_table.lastActivityTime >= ?', [TIME_NOW - $conditionData['endDays'] * 24 * 3600]); + } + } + + /** + * @inheritDoc + */ + public function checkObject(DatabaseObject $object, array $conditionData) { + if (!($object instanceof User) && !ClassUtil::isDecoratedInstanceOf($object, User::class)) { + throw new \InvalidArgumentException("Object is no instance of '" . User::class . "', instance of '".get_class($object)."' given."); + } + + if (isset($conditionData['startDays'])) { + if ($object->lastActivityTime > TIME_NOW - $conditionData['startDays'] * 24 * 3600) { + return false; + } + + if (isset($conditionData['endDays'])) { + if ($object->lastActivityTime < TIME_NOW - $conditionData['endDays'] * 24 * 3600) { + return false; + } + } + + return true; + } + else if (isset($conditionData['endDays']) && $object->lastActivityTime < TIME_NOW - $conditionData['endDays'] * 24 * 3600) { + return false; + } + + return true; + } + + /** + * @inheritDoc + */ + public function getData() { + $data = []; + + if (strlen($this->startDays)) { + $data['startDays'] = $this->startDays; + } + if (strlen($this->endDays)) { + $data['endDays'] = $this->endDays; + } + + if (!empty($data)) { + return $data; + } + + return null; + } + + /** + * @inheritDoc + */ + protected function getFieldElement() { + $start = WCF::getLanguage()->get('wcf.date.period.start'); + $end = WCF::getLanguage()->get('wcf.date.period.end'); + $days = WCF::getLanguage()->get('wcf.acp.option.suffix.days'); + + return << + + {$days} + +
+ + {$days} +
+HTML; + } + + /** + * @inheritDoc + */ + public function readFormParameters() { + if (isset($_POST['userLastActivityTimeIntervalEndDays'])) $this->endDays = $_POST['userLastActivityTimeIntervalEndDays']; + if (isset($_POST['userLastActivityTimeIntervalStartDays'])) $this->startDays = $_POST['userLastActivityTimeIntervalStartDays']; + } + + /** + * @inheritDoc + */ + public function reset() { + $this->endDays = ''; + $this->startDays = ''; + } + + /** + * @inheritDoc + */ + public function setData(Condition $condition) { + /** @noinspection PhpUndefinedFieldInspection */ + $endDays = $condition->endDays; + if ($endDays) { + $this->endDays = $endDays; + } + + /** @noinspection PhpUndefinedFieldInspection */ + $startDays = $condition->startDays; + if ($startDays) { + $this->startDays = $startDays; + } + } + + /** + * @inheritDoc + */ + public function validate() { + $endDays = $startDays = null; + if (strlen($this->startDays)) { + $startDays = intval($this->startDays); + if ($startDays <= 0) { + $this->errorMessage = 'wcf.user.condition.lastActivityTimeIntervalDays.error.invalidStart'; + + throw new UserInputException('userLastActivityTimeIntervalDays', 'invalidStart'); + } + } + if (strlen($this->endDays)) { + $endDays = intval($this->endDays); + if ($endDays <= 0) { + $this->errorMessage = 'wcf.user.condition.lastActivityTimeIntervalDays.error.invalidEnd'; + + throw new UserInputException('userLastActivityTimeIntervalDays', 'invalidEnd'); + } + } + + if ($endDays !== null && $startDays !== null && $endDays <= $startDays) { + $this->errorMessage = 'wcf.user.condition.lastActivityTimeIntervalDays.error.endBeforeStart'; + + throw new UserInputException('userLastActivityTimeIntervalDays', 'endBeforeStart'); + } + } +} diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index b3ba3bb063..74b9fbabfb 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -4976,6 +4976,10 @@ Die E-Mail-Adresse des neuen Benutzers lautet: {@$user->email} + + + + diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index ada3909315..61a25e3bf7 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -4971,6 +4971,10 @@ Open the link below to access the user profile: + + + + -- 2.20.1