/** * @see \wcf\system\option\ISearchableConditionUserOption::checkUser() */ public function checkUser(User $user, Option $option, $value) { if (!$user->birthdayShowYear || !$user->birthday) { return false; } $ageFrom = intval($value['ageFrom']); $ageTo = intval($value['ageTo']); $userAge = DateUtil::getAge($user->birthday); if ($ageFrom && $ageTo) { return $userAge >= $ageFrom && $userAge <= $ageTo; } else { if ($ageFrom) { return $userAge >= $ageFrom; } else { return $userAge <= $ageTo; } } }
/** * @see \wcf\system\option\OptionHandler::validateOption() */ protected function validateOption(Option $option) { parent::validateOption($option); if ($option->required && $option->optionType != 'boolean' && empty($this->optionValues[$option->optionName])) { throw new UserInputException($option->optionName); } if (REGISTER_MIN_USER_AGE) { if ($this->inRegistration && $option->optionName == 'birthday') { if (empty($this->optionValues[$option->optionName])) { throw new UserInputException($option->optionName); } if (DateUtil::getAge($this->optionValues[$option->optionName]) < REGISTER_MIN_USER_AGE) { throw new UserInputException($option->optionName, 'birthdayTooYoung'); } } } }
/** * Returns the age of this user. * * @param integer $year * @return integer */ public function getAge($year = null) { if ($year !== null) { if ($this->birthdayShowYear) { $birthdayYear = 0; $value = explode('-', $this->birthday); if (isset($value[0])) { $birthdayYear = intval($value[0]); } if ($birthdayYear) { return $year - $birthdayYear; } } return 0; } else { if ($this->__age === null) { if ($this->birthday && $this->birthdayShowYear) { $this->__age = DateUtil::getAge($this->birthday); } else { $this->__age = 0; } } return $this->__age; } }