TYPO3 CMS  TYPO3_6-2
BetweenValidator.php
Go to the documentation of this file.
1 <?php
3 
24 
30  const LOCALISATION_OBJECT_NAME = 'tx_form_system_validate_between';
31 
37  protected $minimum;
38 
44  protected $maximum;
45 
51  protected $inclusive;
52 
58  public function __construct($arguments) {
59  $this->setMinimum($arguments['minimum'])->setMaximum($arguments['maximum'])->setInclusive($arguments['inclusive']);
60  parent::__construct($arguments);
61  }
62 
69  public function isValid() {
70  if ($this->requestHandler->has($this->fieldName)) {
71  $value = $this->requestHandler->getByMethod($this->fieldName);
72  if ($this->inclusive) {
73  if ($value < $this->minimum || $value > $this->maximum) {
74  return FALSE;
75  }
76  } else {
77  if ($value <= $this->minimum || $value >= $this->maximum) {
78  return FALSE;
79  }
80  }
81  }
82  return TRUE;
83  }
84 
91  public function setMinimum($minimum) {
92  $this->minimum = $minimum;
93  return $this;
94  }
95 
102  public function setMaximum($maximum) {
103  $this->maximum = $maximum;
104  return $this;
105  }
106 
113  public function setInclusive($inclusive) {
114  if ($inclusive === NULL) {
115  $this->inclusive = FALSE;
116  } else {
117  $this->inclusive = (bool) $inclusive;
118  }
119  return $this;
120  }
121 
130  protected function getLocalLanguageLabel($type) {
131  $label = static::LOCALISATION_OBJECT_NAME . '.' . $type;
132  $messages[] = $this->localizationHandler->getLocalLanguageLabel($label);
133  if ($this->inclusive) {
134  $messages[] = $this->localizationHandler->getLocalLanguageLabel($label . '2');
135  }
136  $message = implode(', ', $messages);
137  return $message;
138  }
139 
147  protected function substituteValues($message) {
148  return str_replace(
149  array('%minimum', '%maximum'),
150  array($this->minimum, $this->maximum),
151  $message
152  );
153  }
154 
155 }