Exemplo n.º 1
0
 /**
  * Add a ZendX date picker to the form
  *
  * @param string $name Name of element
  * @param mixed $arrayOrKey1 \MUtil_Ra::pairs() name => value array
  * @return \ZendX_JQuery_Form_Element_DatePicker
  */
 public function addDate($name, $arrayOrKey1 = null, $value1 = null, $key2 = null, $value2 = null)
 {
     $options = func_get_args();
     $options = \MUtil_Ra::pairs($options, 1);
     $options = $this->_mergeOptions($name, $options, self::DATE_OPTIONS, self::DISPLAY_OPTIONS, self::JQUERY_OPTIONS, self::TEXT_OPTIONS);
     // Allow centrally set options
     $type = \MUtil_Date_Format::getDateTimeType(isset($options['dateFormat']) ? $options['dateFormat'] : null);
     self::applyFixedOptions($type, $options);
     if (isset($options['dateFormat'])) {
         // Make sure the model knows the dateFormat (can be important for storage).
         $this->getModel()->set($name, 'dateFormat', $options['dateFormat']);
     }
     // Make sure form knows it is a jQuery form
     $this->form->activateJQuery();
     return $this->_addToForm($name, 'DatePicker', $options);
 }
Exemplo n.º 2
0
 /**
  * A ModelAbstract->setOnLoad() function that takes care of transforming a
  * dateformat read from the database to a \Zend_Date format
  *
  * If empty or \Zend_Db_Expression (after save) it will return just the value
  * currently there are no checks for a valid date format.
  *
  * @see \MUtil_Model_ModelAbstract
  *
  * @param mixed $value The value being saved
  * @param boolean $isNew True when a new item is being saved
  * @param string $name The name of the current field
  * @param array $context Optional, the other values being saved
  * @param boolean $isPost True when passing on post data
  * @return \MUtil_Date|\Zend_Db_Expr|null
  */
 public function formatLoadDate($value, $isNew = false, $name = null, array $context = array(), $isPost = false)
 {
     static $formats;
     // If not empty or zend_db_expression and not already a zend date, we
     // transform to a \Zend_Date using the stored formats
     if (null === $value || $value instanceof \Zend_Date || $value instanceof \Zend_Db_Expr) {
         return $value;
     }
     if (!isset($formats[$name][$isPost])) {
         // Stored the used formats (as they are usually used often within a model)
         if ($isPost) {
             // Add possible custom format
             $formats[$name][$isPost][] = $this->_getKeyValue($name, 'dateFormat');
             // Add default format as a fallback
             $type = \MUtil_Date_Format::getDateTimeType($this->_getKeyValue($name, 'dateFormat'));
             $formats[$name][$isPost][] = \MUtil_Model_Bridge_FormBridge::getFixedOption($type, 'dateFormat');
         }
         $formats[$name][$isPost][] = $this->_getKeyValue($name, 'storageFormat');
     }
     return \MUtil_Date::ifDate($value, $formats[$name][$isPost]);
 }