2 namespace wcf\system\condition
;
3 use wcf\data\condition\Condition
;
4 use wcf\data\user\User
;
5 use wcf\data\user\UserList
;
6 use wcf\system\exception\UserInputException
;
10 * Condition implementation for the registration date of a user.
12 * @author Matthias Schmidt
13 * @copyright 2001-2015 WoltLab GmbH
14 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
15 * @package com.woltlab.wcf
16 * @subpackage system.condition
17 * @category Community Framework
19 class UserRegistrationDateCondition
extends AbstractSingleFieldCondition
implements IContentCondition
, IUserCondition
{
21 * @see \wcf\system\condition\AbstractSingleFieldCondition::$label
23 protected $label = 'wcf.user.condition.registrationDate';
26 * registration start date
29 protected $registrationDateEnd = '';
32 * registration start date
35 protected $registrationDateStart = '';
38 * @see \wcf\system\condition\IUserCondition::addUserCondition()
40 public function addUserCondition(Condition
$condition, UserList
$userList) {
41 if ($condition->registrationDateEnd
!== null) {
42 $userList->getConditionBuilder()->add('user_table.registrationDate < ?', array(strtotime($condition->registrationDateEnd
) +
86400));
44 if ($condition->registrationDateStart
!== null) {
45 $userList->getConditionBuilder()->add('user_table.registrationDate >= ?', array(strtotime($condition->registrationDateStart
)));
50 * @see \wcf\system\condition\IUserCondition::checkUser()
52 public function checkUser(Condition
$condition, User
$user) {
53 if ($condition->registrationDateStart
!== null && $user->registrationDate
< strtotime($condition->registrationDateStart
)) {
56 if ($condition->registrationDateEnd
!== null && $user->registrationDate
>= strtotime($condition->registrationDateEnd
) +
86400) {
64 * @see \wcf\system\condition\ICondition::getData()
66 public function getData() {
69 if (strlen($this->registrationDateStart
)) {
70 $data['registrationDateStart'] = $this->registrationDateStart
;
72 if (strlen($this->registrationDateEnd
)) {
73 $data['registrationDateEnd'] = $this->registrationDateEnd
;
84 * @see \wcf\system\condition\AbstractSingleFieldCondition::getFieldElement()
86 protected function getFieldElement() {
87 $start = WCF
::getLanguage()->get('wcf.date.period.start');
88 $end = WCF
::getLanguage()->get('wcf.date.period.end');
91 <input type="date" id="registrationDateStart" name="registrationDateStart" value="{$this->registrationDateStart}" placeholder="{$start}" />
92 <input type="date" id="registrationDateEnd" name="registrationDateEnd" value="{$this->registrationDateEnd}" placeholder="{$end}" />
97 * @see \wcf\system\condition\ICondition::readFormParameters()
99 public function readFormParameters() {
100 if (isset($_POST['registrationDateEnd'])) $this->registrationDateEnd
= $_POST['registrationDateEnd'];
101 if (isset($_POST['registrationDateStart'])) $this->registrationDateStart
= $_POST['registrationDateStart'];
105 * @see \wcf\system\condition\ICondition::reset()
107 public function reset() {
108 $this->registrationDateEnd
= '';
109 $this->registrationDateStart
= '';
113 * @see \wcf\system\condition\ICondition::setData()
115 public function setData(Condition
$condition) {
116 if ($condition->registrationDateEnd
) {
117 $this->registrationDateEnd
= $condition->registrationDateEnd
;
119 if ($condition->registrationDateStart
) {
120 $this->registrationDateStart
= $condition->registrationDateStart
;
125 * @see \wcf\system\condition\ICondition::validate()
127 public function validate() {
128 $registrationDateEnd = $registrationDateStart = null;
129 if (strlen($this->registrationDateStart
)) {
130 $registrationDateStart = @strtotime
($this->registrationDateStart
);
131 if ($registrationDateStart === false) {
132 $this->errorMessage
= 'wcf.user.condition.registrationDate.error.startNotValid';
134 throw new UserInputException('registrationDate', 'startNotValid');
137 if (strlen($this->registrationDateEnd
)) {
138 $registrationDateEnd = @strtotime
($this->registrationDateEnd
);
139 if ($registrationDateEnd === false) {
140 $this->errorMessage
= 'wcf.user.condition.registrationDate.error.endNotValid';
142 throw new UserInputException('registrationDate', 'endNotValid');
146 if ($registrationDateEnd !== null && $registrationDateStart !== null && $registrationDateEnd < $registrationDateStart) {
147 $this->errorMessage
= 'wcf.user.condition.registrationDate.error.endBeforeStart';
149 throw new UserInputException('registrationDate', 'endBeforeStart');
154 * @see \wcf\system\condition\IContentCondition::showContent()
156 public function showContent(Condition
$condition) {
157 if (!WCF
::getUser()->userID
) return false;
159 return $this->checkUser($condition, WCF
::getUser());