Пример #1
0
 public function init()
 {
     parent::init();
     $this->setLabel($this->getName());
     $validator = new Application_Form_Validate_Date();
     $validator->setMessages(array(Zend_Validate_Date::INVALID => 'validation_error_date_invalid', Zend_Validate_Date::INVALID_DATE => 'validation_error_date_invaliddate', Zend_Validate_Date::FALSEFORMAT => 'validation_error_date_falseformat'));
     $this->setValidators(array($validator));
     $this->setAttrib('placeholder', $this->getTranslator()->translate('date_format'));
     $this->setAttrib('size', 12);
     $this->setAttrib('maxlength', 10);
 }
Пример #2
0
 /**
  * Converts Opus_Date into string depending on current language.
  * @param Opus_Date $date Date
  * @return Date string for current language
  */
 public function getDateString($date)
 {
     // Protect against invalid dates
     if (!is_null($date) && $date->isValid()) {
         $dateFormat = $this->_validator->getDateFormat();
         $zendDate = $date->getZendDate();
         return $zendDate->get($dateFormat);
     } else {
         return null;
     }
 }
Пример #3
0
 private function _validateDate()
 {
     if (!isset($this->_session->language)) {
         return;
     }
     $lang = $this->_session->language;
     $validators = array();
     $validator = new Application_Form_Validate_Date();
     $validator->setLocale($lang);
     $messages = array(Zend_Validate_Date::INVALID => $this->translate('publish_validation_error_date_invalid'), Zend_Validate_Date::INVALID_DATE => $this->translate('publish_validation_error_date_invaliddate'), Zend_Validate_Date::FALSEFORMAT => $this->translate('publish_validation_error_date_falseformat'));
     $validator->setMessages($messages);
     $validators[] = $validator;
     return $validators;
 }
Пример #4
0
 public function testSetLocale()
 {
     $validator = new Application_Form_Validate_Date();
     $validator->setLocale('de');
     $this->assertEquals(self::DE_FORMAT, $validator->getFormat());
     $this->assertEquals(self::DE_PATTERN, $validator->getInputPattern());
     $validator->setLocale('en');
     $this->assertEquals(self::EN_FORMAT, $validator->getFormat());
     $this->assertEquals(self::EN_PATTERN, $validator->getInputPattern());
 }