From 73b8f68171cc0b1a8810f2664bc91bc204395d2a Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Sun, 1 Jun 2014 15:09:26 +0200 Subject: [PATCH] Improve integer conditions --- .../AbstractIntegerCondition.class.php | 77 ++++++------------- .../UserIntegerPropertyCondition.class.php | 25 +----- ...egistrationDateIntervalCondition.class.php | 27 +------ wcfsetup/install/lang/de.xml | 24 +++--- wcfsetup/install/lang/en.xml | 24 +++--- 5 files changed, 54 insertions(+), 123 deletions(-) diff --git a/wcfsetup/install/files/lib/system/condition/AbstractIntegerCondition.class.php b/wcfsetup/install/files/lib/system/condition/AbstractIntegerCondition.class.php index 7320c1ce5d..e380d8f683 100644 --- a/wcfsetup/install/files/lib/system/condition/AbstractIntegerCondition.class.php +++ b/wcfsetup/install/files/lib/system/condition/AbstractIntegerCondition.class.php @@ -14,7 +14,7 @@ use wcf\system\WCF; * @subpackage system.condition * @category Community Framework */ -abstract class AbstractIntegerCondition extends AbstractMultipleFieldsCondition { +abstract class AbstractIntegerCondition extends AbstractSingleFieldCondition { /** * property value has to be greater than the given value * @var integer @@ -27,12 +27,6 @@ abstract class AbstractIntegerCondition extends AbstractMultipleFieldsCondition */ protected $identifier = ''; - /** - * prefix used for error message language items - * @var string - */ - protected $languageItemPrefix = ''; - /** * property value has to be less than the given value * @var integer @@ -45,24 +39,12 @@ abstract class AbstractIntegerCondition extends AbstractMultipleFieldsCondition */ protected $maxValue = null; - /** - * language item with the global maximum value error message - * @var string - */ - protected $maxValueErrorMessage = null; - /** * minimum value the property can have * @var integer */ protected $minValue = null; - /** - * language item with the global minimum value error message - * @var string - */ - protected $minValueErrorMessage = null; - /** * name of the integer user property * @var string @@ -92,28 +74,29 @@ abstract class AbstractIntegerCondition extends AbstractMultipleFieldsCondition /** * @see \wcf\system\condition\AbstractMultipleFieldsCondition::getData() */ - protected function getErrorMessageElement($identifier) { - if (isset($this->errorMessages[$identifier])) { + protected function getErrorMessageElement() { + if ($this->errorMessage) { $errorMessage = ''; - switch ($this->errorMessages[$identifier]) { - case $this->languageItemPrefix.'.greaterThan.error.maxValue': - case $this->languageItemPrefix.'.lessThan.error.maxValue': - $errorMessage = WCF::getLanguage()->getDynamicVariable($this->maxValueErrorMessage ? $this->maxValueErrorMessage : $this->errorMessages[$identifier], array( + switch ($this->errorMessage) { + case 'wcf.condition.greaterThan.error.maxValue': + case 'wcf.condition.lessThan.error.maxValue': + $errorMessage = WCF::getLanguage()->getDynamicVariable($this->errorMessage, array( 'maxValue' => $this->maxValue )); break; - case $this->languageItemPrefix.'.greaterThan.error.minValue': - case $this->languageItemPrefix.'.lessThan.error.minValue': - $errorMessage = WCF::getLanguage()->getDynamicVariable($this->minValueErrorMessage ? $this->minValueErrorMessage : $this->errorMessages[$identifier], array( + case 'wcf.condition.greaterThan.error.minValue': + case 'wcf.condition.lessThan.error.minValue': + $errorMessage = WCF::getLanguage()->getDynamicVariable($this->errorMessage, array( 'minValue' => $this->minValue )); break; default: - $errorMessage = WCF::getLanguage()->get($this->errorMessages[$identifier]); + $errorMessage = WCF::getLanguage()->get($this->errorMessage); break; } + return ''.$errorMessage.''; } @@ -121,27 +104,15 @@ abstract class AbstractIntegerCondition extends AbstractMultipleFieldsCondition } /** - * @see \wcf\system\condition\ICondition::getHTML() + * @see \wcf\system\condition\AbstractSingleFieldCondition::getFieldElement() */ - public function getHTML() { + public function getFieldElement() { + $greaterThanPlaceHolder = WCF::getLanguage()->get('wcf.condition.greaterThan'); + $lessThanPlaceHolder = WCF::getLanguage()->get('wcf.condition.lessThan'); + return << -
{$this->getLabel('lessThan')}
-
- getMinMaxAttributes('lessThan')} /> - {$this->getDescriptionElement('lessThan')} - {$this->getErrorMessageElement('lessThan')} -
- - -
-
{$this->getLabel('greaterThan')}
-
- getMinMaxAttributes('greaterThan')} /> - {$this->getDescriptionElement('greaterThan')} - {$this->getErrorMessageElement('greaterThan')} -
-
+getMinMaxAttributes('greaterThan')} /> +getMinMaxAttributes('lessThan')} /> HTML; } @@ -238,31 +209,31 @@ HTML; public function validate() { if ($this->lessThan !== null) { if ($this->getMinValue() !== null && $this->lessThan <= $this->getMinValue()) { - $this->errorMessages['lessThan'] = $this->languageItemPrefix.'.lessThan.error.minValue'; + $this->errorMessage = 'wcf.condition.lessThan.error.minValue'; throw new UserInputException('lessThan', 'minValue'); } else if ($this->getMaxValue() !== null && $this->lessThan > $this->getMaxValue()) { - $this->errorMessages['lessThan'] = $this->languageItemPrefix.'.lessThan.error.maxValue'; + $this->errorMessages['lessThan'] = 'wcf.condition.lessThan.error.maxValue'; throw new UserInputException('lessThan', 'maxValue'); } } if ($this->greaterThan !== null) { if ($this->getMinValue() !== null && $this->greaterThan < $this->getMinValue()) { - $this->errorMessages['greaterThan'] = $this->languageItemPrefix.'.greaterThan.error.minValue'; + $this->errorMessages['greaterThan'] = 'wcf.condition.greaterThan.error.minValue'; throw new UserInputException('greaterThan', 'minValue'); } else if ($this->getMaxValue() !== null && $this->greaterThan >= $this->getMaxValue()) { - $this->errorMessages['greaterThan'] = $this->languageItemPrefix.'.greaterThan.error.maxValue'; + $this->errorMessages['greaterThan'] = 'wcf.condition.greaterThan.error.maxValue'; throw new UserInputException('greaterThan', 'maxValue'); } } if ($this->lessThan !== null && $this->greaterThan !== null && $this->greaterThan + 1 >= $this->lessThan) { - $this->errorMessages['greaterThan'] = $this->languageItemPrefix.'.greaterThan.error.lessThan'; + $this->errorMessage = 'wcf.condition.greaterThan.error.lessThan'; throw new UserInputException('greaterThan', 'lessThan'); } diff --git a/wcfsetup/install/files/lib/system/condition/UserIntegerPropertyCondition.class.php b/wcfsetup/install/files/lib/system/condition/UserIntegerPropertyCondition.class.php index 089610d964..894fcda431 100644 --- a/wcfsetup/install/files/lib/system/condition/UserIntegerPropertyCondition.class.php +++ b/wcfsetup/install/files/lib/system/condition/UserIntegerPropertyCondition.class.php @@ -18,25 +18,6 @@ use wcf\system\WCF; * @category Community Framework */ class UserIntegerPropertyCondition extends AbstractIntegerCondition implements IContentCondition, IUserCondition { - /** - * @see \wcf\system\condition\AbstractIntegerCondition::$maxValueErrorMessage - */ - protected $maxValueErrorMessage = 'wcf.user.condition.integerProperty.error.maxValue'; - - /** - * @see \wcf\system\condition\AbstractIntegerCondition::$minValueErrorMessage - */ - protected $minValueErrorMessage = 'wcf.user.condition.integerProperty.error.minValue'; - - /** - * @see \wcf\data\DatabaseObjectDecorator::__construct() - */ - public function __construct(DatabaseObject $object) { - parent::__construct($object); - - $this->languageItemPrefix = 'wcf.user.condition.'.$this->getDecoratedObject()->propertyname; - } - /** * @see \wcf\system\condition\IUserCondition::addUserCondition() */ @@ -71,10 +52,10 @@ class UserIntegerPropertyCondition extends AbstractIntegerCondition implements I } /** - * @see \wcf\system\condition\AbstractMultipleFieldsCondition::getLabel() + * @see \wcf\system\condition\AbstractSingleFieldCondition::getLabel() */ - protected function getLabel($identifier) { - return WCF::getLanguage()->get('wcf.user.condition.'.$this->getDecoratedObject()->propertyname.'.'.$identifier); + protected function getLabel() { + return WCF::getLanguage()->get('wcf.user.condition.'.$this->getDecoratedObject()->propertyname); } /** diff --git a/wcfsetup/install/files/lib/system/condition/UserRegistrationDateIntervalCondition.class.php b/wcfsetup/install/files/lib/system/condition/UserRegistrationDateIntervalCondition.class.php index 5b96c682ea..b5005b4fc5 100644 --- a/wcfsetup/install/files/lib/system/condition/UserRegistrationDateIntervalCondition.class.php +++ b/wcfsetup/install/files/lib/system/condition/UserRegistrationDateIntervalCondition.class.php @@ -22,31 +22,13 @@ class UserRegistrationDateIntervalCondition extends AbstractIntegerCondition imp /** * @see \wcf\system\condition\AbstractMultipleFieldsCondition::$languageItemPrefix */ - protected $labels = array( - 'greaterThan' => 'wcf.user.condition.registrationDateInterval.greaterThan', - 'lessThan' => 'wcf.user.condition.registrationDateInterval.lessThan' - ); - - /** - * @see \wcf\system\condition\AbstractIntegerCondition::$languageItemPrefix - */ - protected $languageItemPrefix = 'wcf.user.condition.registrationDateInterval'; - - /** - * @see \wcf\system\condition\AbstractIntegerCondition::$maxValueErrorMessage - */ - protected $maxValueErrorMessage = 'wcf.user.condition.integerProperty.error.maxValue'; + protected $label = 'wcf.user.condition.registrationDateInterval'; /** * @see \wcf\system\condition\AbstractIntegerCondition::$minValue */ protected $minValue = 0; - /** - * @see \wcf\system\condition\AbstractIntegerCondition::$minValueErrorMessage - */ - protected $minValueErrorMessage = 'wcf.user.condition.integerProperty.error.minValue'; - /** * @see \wcf\system\condition\IUserCondition::addUserCondition() */ @@ -80,13 +62,6 @@ class UserRegistrationDateIntervalCondition extends AbstractIntegerCondition imp return 'user_registrationDateInterval'; } - /** - * @see \wcf\system\condition\AbstractMultipleFieldsCondition::getLabel() - */ - protected function getLabel($identifier) { - return WCF::getLanguage()->get('wcf.user.condition.registrationDateInterval.'.$identifier); - } - /** * @see \wcf\system\condition\IContentCondition::showContent() */ diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 858251f62d..d594c2f8fc 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -1634,6 +1634,16 @@ Fehler sind beispielsweise: + + + + + + + + + + @@ -2690,9 +2700,7 @@ Sollten Sie sich nicht auf der Website: {@PAGE_TITLE|language} angemeldet haben, - - - + @@ -2702,12 +2710,8 @@ Sollten Sie sich nicht auf der Website: {@PAGE_TITLE|language} angemeldet haben, - - - - - + @@ -2715,9 +2719,7 @@ Sollten Sie sich nicht auf der Website: {@PAGE_TITLE|language} angemeldet haben, - - - + diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index b0a213331d..7c5e5bb07e 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -1575,6 +1575,16 @@ Errors are: + + + + + + + + + + @@ -2510,9 +2520,7 @@ You can safely ignore this email if you did not register with the website: {@PAG - - - + @@ -2522,12 +2530,8 @@ You can safely ignore this email if you did not register with the website: {@PAG - - - - - + @@ -2535,9 +2539,7 @@ You can safely ignore this email if you did not register with the website: {@PAG - - - + -- 2.20.1