Add last user activity time condition for today's birthday box
authorMatthias Schmidt <gravatronics@live.com>
Sat, 13 Jun 2020 11:40:08 +0000 (13:40 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Sat, 13 Jun 2020 11:40:08 +0000 (13:40 +0200)
Close #3249

com.woltlab.wcf/objectType.xml
com.woltlab.wcf/objectTypeDefinition.xml
wcfsetup/install/files/lib/system/box/TodaysBirthdaysBoxController.class.php
wcfsetup/install/files/lib/system/box/TodaysFollowingBirthdaysBoxController.class.php
wcfsetup/install/files/lib/system/condition/user/UserLastActivityTimeIntervalDaysCondition.class.php [new file with mode: 0644]
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index 98963f777ecd672789c1ff741ef423d3c4839728..74a2caf60b0932f6966dcdeb650f39770f0203c3 100644 (file)
                        <classname>wcf\system\condition\user\trophy\UserTrophyExcludedTrophyCategoriesCondition</classname>
                </type>
                <!-- /trophy list box condition -->
+               <!-- today's birthday list box condition -->
+               <type>
+                       <name>com.woltlab.wcf.lastActivityTimeIntervalDays</name>
+                       <definitionname>com.woltlab.wcf.box.todaysBirthdays.condition</definitionname>
+                       <classname>wcf\system\condition\user\UserLastActivityTimeIntervalDaysCondition</classname>
+                       <ignoreZeroTime>1</ignoreZeroTime>
+               </type>
+               <!-- /today's birthday box condition -->
+               <!-- today's birthday of followed users list box condition -->
+               <type>
+                       <name>com.woltlab.wcf.lastActivityTimeIntervalDays</name>
+                       <definitionname>com.woltlab.wcf.box.todaysFollowingBirthdays.condition</definitionname>
+                       <classname>wcf\system\condition\user\UserLastActivityTimeIntervalDaysCondition</classname>
+                       <ignoreZeroTime>1</ignoreZeroTime>
+               </type>
+               <!-- /today's birthday of followed box condition -->
                <!-- user list box condition -->
                <type>
                        <name>com.woltlab.wcf.userGroup</name>
index 62bee674bf2edc1f4c1d1a2f1dc46df8371ae5ed..356ef92b23ed76ea34d9f36b9d487043f7bf5228 100644 (file)
                        <name>com.woltlab.wcf.box.recentActivityList.condition</name>
                        <interfacename>wcf\system\condition\IObjectListCondition</interfacename>
                </definition>
+               <definition>
+                       <name>com.woltlab.wcf.box.todaysBirthdays.condition</name>
+                       <interfacename>wcf\system\condition\IObjectCondition</interfacename>
+               </definition>
+               <definition>
+                       <name>com.woltlab.wcf.box.todaysFollowingBirthdays.condition</name>
+                       <interfacename>wcf\system\condition\IObjectCondition</interfacename>
+               </definition>
                <definition>
                        <name>com.woltlab.wcf.box.userList.condition</name>
                        <interfacename>wcf\system\condition\IObjectListCondition</interfacename>
index c25cb7b6447c85ccd51814e5d4fae4aa8ea3b6d5..51af2173f90c300c219face9f9ad858a7e605ef0 100644 (file)
@@ -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) {
index ffbf21308e81c4c72e3b5063b804230a9fcf2ef3..65a7ca0f76ec97b2556b68f4078ec619f9c1f548 100644 (file)
@@ -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 (file)
index 0000000..18665dd
--- /dev/null
@@ -0,0 +1,191 @@
+<?php
+namespace wcf\system\condition\user;
+use wcf\data\condition\Condition;
+use wcf\data\DatabaseObject;
+use wcf\data\DatabaseObjectList;
+use wcf\data\user\User;
+use wcf\data\user\UserList;
+use wcf\system\condition\AbstractSingleFieldCondition;
+use wcf\system\condition\IObjectCondition;
+use wcf\system\condition\IObjectListCondition;
+use wcf\system\exception\UserInputException;
+use wcf\system\WCF;
+use wcf\util\ClassUtil;
+
+/**
+ * User condition for the interval (in days) of their last activity.
+ * 
+ * @author      Matthias Schmidt
+ * @copyright   2001-2020 WoltLab GmbH
+ * @license     GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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 <<<HTML
+<div class="inputAddon">
+       <input type="number" id="userLastActivityTimeIntervalStartDays" name="userLastActivityTimeIntervalStartDays" class="short" min="1" value="{$this->startDays}" placeholder="{$start}">
+       <span class="inputSuffix">{$days}</span>
+</div>
+<div class="inputAddon">
+       <input type="number" id="userLastActivityTimeIntervalEndDays" name="userLastActivityTimeIntervalEndDays" class="short" min="1" value="{$this->endDays}" placeholder="{$end}">
+       <span class="inputSuffix">{$days}</span>
+</div>
+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');
+               }
+       }
+}
index b3ba3bb06330d143b4237df9a8d1808c0652fe7a..74b9fbabfb36b79cd9b324617a3442a06a4636b4 100644 (file)
@@ -4976,6 +4976,10 @@ Die E-Mail-Adresse des neuen Benutzers lautet: {@$user->email}
                <item name="wcf.user.condition.signature"><![CDATA[Signatur]]></item>
                <item name="wcf.user.condition.signature.signature"><![CDATA[Hat Signatur]]></item>
                <item name="wcf.user.condition.signature.noSignature"><![CDATA[Hat kein Signatur]]></item>
+               <item name="wcf.user.condition.lastActivityTimeIntervalDays"><![CDATA[Letzten Aktivität vor … Tagen]]></item>
+               <item name="wcf.user.condition.lastActivityTimeIntervalDays.error.endBeforeStart"><![CDATA[Der Endwert ist kleiner als der Startwert.]]></item>
+               <item name="wcf.user.condition.lastActivityTimeIntervalDays.error.invalidEnd"><![CDATA[Der Endwert ist ungültig.]]></item>
+               <item name="wcf.user.condition.lastActivityTimeIntervalDays.error.invalidStart"><![CDATA[Der Startwert ist ungültig.]]></item>
        </category>
        <category name="wcf.user.coverPhoto">
                <item name="wcf.user.coverPhoto"><![CDATA[Titelbild]]></item>
index ada3909315d94a57b6e7d939506f4c966263d3e8..61a25e3bf7672aa254694b1692bb08853f4d90ec 100644 (file)
@@ -4971,6 +4971,10 @@ Open the link below to access the user profile:
                <item name="wcf.user.condition.signature"><![CDATA[Signature]]></item>
                <item name="wcf.user.condition.signature.signature"><![CDATA[Has Signature]]></item>
                <item name="wcf.user.condition.signature.noSignature"><![CDATA[Has no Signature]]></item>
+               <item name="wcf.user.condition.lastActivityTimeIntervalDays"><![CDATA[Last Activity … Days Ago]]></item>
+               <item name="wcf.user.condition.lastActivityTimeIntervalDays.error.startBeforeEnd"><![CDATA[The end value is less than the start value.]]></item>
+               <item name="wcf.user.condition.lastActivityTimeIntervalDays.error.invalidEnd"><![CDATA[The end value is invalid.]]></item>
+               <item name="wcf.user.condition.lastActivityTimeIntervalDays.error.invalidStart"><![CDATA[The start value is invalid.]]></item>
        </category>
        <category name="wcf.user.coverPhoto">
                <item name="wcf.user.coverPhoto"><![CDATA[Cover Photo]]></item>