/** * Generate two date selectors and - depending on the number of $dates passed - * either a hidden element containing the field name or an radio button or * dropdown selector for the type of date to use. * * @param mixed $dates A string fieldName to use or an array of fieldName => Label * @param string $defaultDate Optional element, otherwise first is used. * @param int $switchToSelect The number of dates where this function should switch to select display */ protected function getPeriodSelectors($dates, $defaultDate = null, $switchToSelect = 4) { $elements = array(); if (is_array($dates) && 1 === count($dates)) { $fromLabel = reset($dates); $dates = key($dates); } else { $fromLabel = $this->_('From'); } if (is_string($dates)) { $element = $this->form->createElement('hidden', 'dateused'); $element->setValue($dates); } else { if (count($dates) >= $switchToSelect) { $element = $this->form->createElement('select', 'dateused', array('label' => $this->_('For date'), 'multiOptions' => $dates)); $fromLabel = ''; } else { $element = $this->form->createElement('radio', 'dateused', array('label' => $this->_('For date'), 'multiOptions' => $dates)); $element->setSeparator(' '); $fromLabel = html_entity_decode(' » ', ENT_QUOTES, 'UTF-8'); } $fromLabel .= $this->_('from'); if (null === $defaultDate || !isset($dates[$defaultDate])) { // Set value to first key reset($dates); $defaultDate = key($dates); } $element->setValue($defaultDate); } $elements['dateused'] = $element; $type = 'date'; if ($this->dateFormat) { $options['dateFormat'] = $this->dateFormat; list($dateFormat, $separator, $timeFormat) = \MUtil_Date_Format::splitDateTimeFormat($options['dateFormat']); if ($timeFormat) { if ($dateFormat) { $type = 'datetime'; } else { $type = 'time'; } } } $options['label'] = $fromLabel; \MUtil_Model_Bridge_FormBridge::applyFixedOptions($type, $options); $elements['datefrom'] = new \Gems_JQuery_Form_Element_DatePicker('datefrom', $options); $options['label'] = ' ' . $this->_('until'); $elements['dateuntil'] = new \Gems_JQuery_Form_Element_DatePicker('dateuntil', $options); return $elements; }
/** * Generate two date selectors and - depending on the number of $dates passed - * either a hidden element containing the field name or an radio button or * dropdown selector for the type of date to use. * * @param array $elements Search element array to which the element are added. * @param mixed $dates A string fieldName to use or an array of fieldName => Label * @param string $defaultDate Optional element, otherwise first is used. * @param int $switchToSelect The number of dates where this function should switch to select display */ protected function _addPeriodSelectors(array &$elements, $dates, $defaultDate = null, $switchToSelect = 4) { if (is_array($dates) && 1 === count($dates)) { $fromLabel = reset($dates); $dates = key($dates); } else { $fromLabel = $this->_('From'); } if (is_string($dates)) { $element = new \Zend_Form_Element_Hidden(self::PERIOD_DATE_USED); $element->setValue($dates); } else { if (count($dates) >= $switchToSelect) { $element = $this->_createSelectElement(self::PERIOD_DATE_USED, $dates); $element->setLabel($this->_('For date')); $fromLabel = ''; } else { $element = $this->_createRadioElement(self::PERIOD_DATE_USED, $dates); $element->setSeparator(' '); $fromLabel = html_entity_decode(' » ', ENT_QUOTES, 'UTF-8'); } $fromLabel .= $this->_('from'); if (null === $defaultDate || !isset($dates[$defaultDate])) { // Set value to first key reset($dates); $defaultDate = key($dates); } $element->setValue($defaultDate); } $elements[self::PERIOD_DATE_USED] = $element; $type = 'date'; if ($this->dateFormat) { $options['dateFormat'] = $this->dateFormat; list($dateFormat, $separator, $timeFormat) = \MUtil_Date_Format::splitDateTimeFormat($options['dateFormat']); if ($timeFormat) { if ($dateFormat) { $type = 'datetime'; } else { $type = 'time'; } } } $options['label'] = $fromLabel; \MUtil_Model_Bridge_FormBridge::applyFixedOptions($type, $options); $elements['datefrom'] = new \Gems_JQuery_Form_Element_DatePicker('datefrom', $options); $options['label'] = ' ' . $this->_('until'); $elements['dateuntil'] = new \Gems_JQuery_Form_Element_DatePicker('dateuntil', $options); }
/** * This function splits a date time format into a date, separator and time part; the last two * only when there are time parts in the format. * * The results are formats readable by the jQuery Date/Time Picker. * * No date formats are allowed after the start of the time parts. (A future extension * might be to allow either option, but datetimepicker does not understand that.) * * Some examples: * - "yyyy-MM-dd HH:mm" => array("yy-mm-dd", " ", "hh:mm") * - "X yyyy-MM-dd X" => array("X yy-mm-dd X", false, false) * - "yy \"hi': mm\" MM" => array("y 'hi'': mm' mm", false, false) * - "yyyy-MM-dd 'date: yyyy-MM-dd' HH:mm 'time'': hh:mm' HH:mm Q", => array("yy-mm-dd", " 'date: yyyy-MM-dd' ", "HH:mm 'time'': HH:mm' z Q") * - "HH:mm:ss" => array(false, false, "HH:mm:ss") * - \Zend_Date::ISO_8601 => array("ISO_8601", "T", "HH:mm:ssZ") * * @deprecated since version 1.4 * @param string $format Or \Zend_Locale_Format::getDateFormat($locale) * @return array dateFormat, seperator, timeFormat */ public static function splitZendLocaleToDateTimePickerFormat($format = null) { return \MUtil_Date_Format::splitDateTimeFormat($format); }
/** * Set the date view format: how the user gets to see te date / datetime * * @param string $format * @return \MUtil_JQuery_Form_Element_DatePicker (continuation patern) */ public function setDateFormat($format) { $view = $this->getView(); list($dateFormat, $separator, $timeFormat) = \MUtil_Date_Format::splitDateTimeFormat($format); if ($dateFormat) { $this->setJQueryParam('dateFormat', $dateFormat); } if ($separator) { $this->setJQueryParam('separator', $separator); } if ($timeFormat) { $this->setJQueryParam('timeFormat', $timeFormat); } $this->_dateFormat = $format; $this->_applyDateFormat(); return $this; }