| | 55 | * 'min' Either an string or an array. When its a string the the |
| | 56 | * its assumed to be in the format 'yyyy-MM-dd[ HH:mm:ss[.S]]'. |
| | 57 | * When its an array it will take the minimum value from a |
| | 58 | * request field. These indizes apply: |
| | 59 | * 'format' A custom format string which should be used when the field |
| | 60 | * is an string. |
| | 61 | * 'field' The name of the field to use as minimum value (could be a |
| | 62 | * previous exported calendar object). Do NOT use unvalidated |
| | 63 | * fields here. Lax parsing will be used. |
| | 64 | * This value is inclusive. |
| | 65 | * 'max' The same as min except that the max is exclusive. |
| | 188 | $defaultParseFormat = new AgaviDateFormat('yyyy-MM-dd HH:mm:ss.S'); |
| | 189 | |
| | 190 | if($this->hasParameter('min')) { |
| | 191 | $min = $this->getMinOrMaxValue('min', $defaultParseFormat, $locale); |
| | 192 | |
| | 193 | $isAfterEqual = $cal->after($min) || $cal->equals($min); |
| | 194 | if(!$isAfterEqual) { |
| | 195 | $this->throwError('min'); |
| | 196 | return false; |
| | 197 | } |
| | 198 | } |
| | 199 | |
| | 200 | if($this->hasParameter('max')) { |
| | 201 | $max = $this->getMinOrMaxValue('max', $defaultParseFormat, $locale); |
| | 202 | |
| | 203 | $isBefore = $cal->before($max); |
| | 204 | if(!$isBefore) { |
| | 205 | $this->throwError('max'); |
| | 206 | return false; |
| | 207 | } |
| | 208 | } |
| | 209 | |
| | 225 | |
| | 226 | /** |
| | 227 | * Returns the calendar object for a max or min definition. |
| | 228 | * |
| | 229 | * @param string 'min' or 'max' |
| | 230 | * @param AgaviDateFormat The default format when parsing strings. |
| | 231 | * @param AgaviLocale The locale to use. |
| | 232 | * |
| | 233 | * @return AgaviCalendar The calendar object storing the date. |
| | 234 | * |
| | 235 | * @author Dominik del Bondio <ddb@bitxtender.com> |
| | 236 | * @since 0.11.0 |
| | 237 | */ |
| | 238 | protected function getMinOrMaxValue($minMax, $defaultParseFormat, $locale) |
| | 239 | { |
| | 240 | $format = $defaultParseFormat; |
| | 241 | |
| | 242 | $minMax = $this->getParameter($minMax); |
| | 243 | if(is_array($minMax)) { |
| | 244 | $minMaxValue = $this->validationParameters->getParameter($minMax['field']); |
| | 245 | if(!$minMaxValue instanceof AgaviCalendar) { |
| | 246 | if(isset($minMax['format'])) { |
| | 247 | $format = new AgaviDateFormat($minMax['format']); |
| | 248 | } |
| | 249 | $result = $format->parse($minMaxValue, $locale, false); |
| | 250 | } else { |
| | 251 | $result = $minMaxValue; |
| | 252 | } |
| | 253 | } else { |
| | 254 | $result = $format->parse($minMax, $locale, false); |
| | 255 | } |
| | 256 | |
| | 257 | return $result; |
| | 258 | } |
| | 259 | |