Revert "Revert "Removed obsolete trailing slashes from void elements""
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / system / condition / UserRegistrationDateCondition.class.php
index 626595ca4678a4165d687306fe60bde88dd7c9c8..b23b659b66b30631bc7a57d59e6ff891c349d9a4 100644 (file)
@@ -3,6 +3,7 @@ namespace wcf\system\condition;
 use wcf\data\condition\Condition;
 use wcf\data\user\User;
 use wcf\data\user\UserList;
+use wcf\data\DatabaseObjectList;
 use wcf\system\exception\UserInputException;
 use wcf\system\WCF;
 
@@ -10,15 +11,17 @@ use wcf\system\WCF;
  * Condition implementation for the registration date of a user.
  * 
  * @author     Matthias Schmidt
- * @copyright  2001-2015 WoltLab GmbH
+ * @copyright  2001-2016 WoltLab GmbH
  * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @package    com.woltlab.wcf
  * @subpackage system.condition
  * @category   Community Framework
  */
-class UserRegistrationDateCondition extends AbstractSingleFieldCondition implements IContentCondition, IUserCondition {
+class UserRegistrationDateCondition extends AbstractSingleFieldCondition implements IContentCondition, IObjectListCondition, IUserCondition {
+       use TObjectListUserCondition;
+       
        /**
-        * @see \wcf\system\condition\AbstractSingleFieldCondition::$label
+        * @inheritDoc
         */
        protected $label = 'wcf.user.condition.registrationDate';
        
@@ -35,19 +38,23 @@ class UserRegistrationDateCondition extends AbstractSingleFieldCondition impleme
        protected $registrationDateStart = '';
        
        /**
-        * @see \wcf\system\condition\IUserCondition::addUserCondition()
+        * @inheritDoc
         */
-       public function addUserCondition(Condition $condition, UserList $userList) {
-               if ($condition->registrationDateEnd !== null) {
-                       $userList->getConditionBuilder()->add('user_table.registrationDate < ?', array(strtotime($condition->registrationDateEnd) + 86400));
+       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.");
+               }
+               
+               if (isset($conditionData['registrationDateEnd'])) {
+                       $objectList->getConditionBuilder()->add('user_table.registrationDate < ?', [strtotime($conditionData['registrationDateEnd']) + 86400]);
                }
-               if ($condition->registrationDateStart !== null) {
-                       $userList->getConditionBuilder()->add('user_table.registrationDate >= ?', array(strtotime($condition->registrationDateStart)));
+               if (isset($conditionData['registrationDateStart'])) {
+                       $objectList->getConditionBuilder()->add('user_table.registrationDate >= ?', [strtotime($conditionData['registrationDateStart'])]);
                }
        }
        
        /**
-        * @see \wcf\system\condition\IUserCondition::checkUser()
+        * @inheritDoc
         */
        public function checkUser(Condition $condition, User $user) {
                if ($condition->registrationDateStart !== null && $user->registrationDate < strtotime($condition->registrationDateStart)) {
@@ -61,10 +68,10 @@ class UserRegistrationDateCondition extends AbstractSingleFieldCondition impleme
        }
        
        /**
-        * @see \wcf\system\condition\ICondition::getData()
+        * @inheritDoc
         */
        public function getData() {
-               $data = array();
+               $data = [];
                
                if (strlen($this->registrationDateStart)) {
                        $data['registrationDateStart'] = $this->registrationDateStart;
@@ -81,20 +88,20 @@ class UserRegistrationDateCondition extends AbstractSingleFieldCondition impleme
        }
        
        /**
-        * @see \wcf\system\condition\AbstractSingleFieldCondition::getFieldElement()
+        * @inheritDoc
         */
        protected function getFieldElement() {
                $start = WCF::getLanguage()->get('wcf.date.period.start');
                $end = WCF::getLanguage()->get('wcf.date.period.end');
                
                return <<<HTML
-<input type="date" id="registrationDateStart" name="registrationDateStart" value="{$this->registrationDateStart}" placeholder="{$start}" />
-<input type="date" id="registrationDateEnd" name="registrationDateEnd" value="{$this->registrationDateEnd}" placeholder="{$end}" />
+<input type="date" id="registrationDateStart" name="registrationDateStart" value="{$this->registrationDateStart}" placeholder="{$start}">
+<input type="date" id="registrationDateEnd" name="registrationDateEnd" value="{$this->registrationDateEnd}" placeholder="{$end}">
 HTML;
        }
        
        /**
-        * @see \wcf\system\condition\ICondition::readFormParameters()
+        * @inheritDoc
         */
        public function readFormParameters() {
                if (isset($_POST['registrationDateEnd'])) $this->registrationDateEnd = $_POST['registrationDateEnd'];
@@ -102,7 +109,7 @@ HTML;
        }
        
        /**
-        * @see \wcf\system\condition\ICondition::reset()
+        * @inheritDoc
         */
        public function reset() {
                $this->registrationDateEnd = '';
@@ -110,7 +117,7 @@ HTML;
        }
        
        /**
-        * @see \wcf\system\condition\ICondition::setData()
+        * @inheritDoc
         */
        public function setData(Condition $condition) {
                if ($condition->registrationDateEnd) {
@@ -122,14 +129,14 @@ HTML;
        }
        
        /**
-        * @see \wcf\system\condition\ICondition::validate()
+        * @inheritDoc
         */
        public function validate() {
                $registrationDateEnd = $registrationDateStart = null;
                if (strlen($this->registrationDateStart)) {
                        $registrationDateStart = @strtotime($this->registrationDateStart);
                        if ($registrationDateStart === false) {
-                               $this->errorMessage = 'wcf.user.condition.registrationDate.error.startNotValid';
+                               $this->errorMessage = 'wcf.condition.timestamp.error.startNotValid';
                                
                                throw new UserInputException('registrationDate', 'startNotValid');
                        }
@@ -137,21 +144,21 @@ HTML;
                if (strlen($this->registrationDateEnd)) {
                        $registrationDateEnd = @strtotime($this->registrationDateEnd);
                        if ($registrationDateEnd === false) {
-                               $this->errorMessage = 'wcf.user.condition.registrationDate.error.endNotValid';
+                               $this->errorMessage = 'wcf.condition.timestamp.error.endNotValid';
                                
                                throw new UserInputException('registrationDate', 'endNotValid');
                        }
                }
                
                if ($registrationDateEnd !== null && $registrationDateStart !== null && $registrationDateEnd < $registrationDateStart) {
-                       $this->errorMessage = 'wcf.user.condition.registrationDate.error.endBeforeStart';
+                       $this->errorMessage = 'wcf.condition.timestamp.error.endBeforeStart';
                        
                        throw new UserInputException('registrationDate', 'endBeforeStart');
                }
        }
        
        /**
-        * @see \wcf\system\condition\IContentCondition::showContent()
+        * @inheritDoc
         */
        public function showContent(Condition $condition) {
                if (!WCF::getUser()->userID) return false;