_options) { $this->_options = Qs_Array::exclude($this->getElement()->getAttribs(), 'helper', 'options'); } return $this->_options; } public function setOptions(array $options) { if (isset($options['options'])) { unset($options['options']); } foreach ($options as $key => $value) { $method = 'set' . ucfirst($key); if (method_exists($this, $method)) { $this->$method($value); } else { $this->_options[$key] = $value; } } return $this; } public function initRender() { /** @var Qs_Doc $doc */ $doc = Zend_Registry::get('doc'); $doc->addScript('js/jquery-ui.js'); $doc->addScript('js/lib/form/element/date.js'); $doc->addCriticalStylesheet('css/thirdpart/jquery-ui.css'); $id = $this->getElement()->getId(); $displayId = $this->getDisplayId(); $options = $this->_getScriptOptions(); $doc->addInitObject('lib.form.element.Date', [$id, $displayId, $options]); return $this; } public function getDisplayId() { $id = $this->getElement()->getId(); if (false !== strpos($this->getElement()->getFullyQualifiedName(), '[')) { $name = $this->getElement()->getName(); if ('[]' == substr($name, -2)) { $name = substr($name, 0, strlen($name) - 2); } $pos = strrpos($id, $name); $id = substr($id, 0, $pos) . '_' . substr($id, $pos); } else { $id = '_' . $id; } return $id; } public function getDisplayName() { $name = $this->getElement()->getFullyQualifiedName(); if (false !== ($pos = strrpos($name, '['))) { $pos++; $name = substr($name, 0, $pos) . '_' . substr($name, $pos); } else { $name = '_' . $name; } return $name; } public function render($content) { // init options $this->getOptions(); $element = $this->getElement(); /** @var Qs_View $view */ $view = $element->getView(); $placement = $this->getPlacement(); $separator = $this->getSeparator(); $name = $element->getFullyQualifiedName(); $id = $element->getId(); $elementContent = $view->formHidden($name, $element->getValue(), ['id' => $id]); $_name = $this->getDisplayName(); $_id = $this->getDisplayId(); $elementContent .= $view->formText($_name, '', ['class' => 'date', 'id' => $_id]); switch ($placement) { case self::APPEND: $content = $content . $separator . $elementContent; break; case self::PREPEND: $content = $elementContent . $separator . $content; break; } return $content; } protected function _renderScriptOptions() { $options = $this->_getScriptOptions(); return json_encode($options); } protected function _getScriptOptions() { $options = [ 'altField' => '#' . $this->getElement()->getId(), 'altFormat' => 'yy-mm-dd', 'dateFormat' => $this->getElement()->getFormat(), 'duration' => 0, 'changeMonth' => true, 'changeYear' => true, 'showOn' => 'button', 'buttonImage' => 'images/calendar.gif', 'buttonText' => 'Click to open/close Calendar', 'buttonImageOnly' => true, ]; $allowedOptions = [ 'altField', 'altFormat', 'appendText', 'buttonImage', 'buttonImageOnly', 'buttonText', 'changeMonth', 'changeYear', 'closeText', 'constrainInput', 'currentText', 'dateFormat', 'dayNames', 'dayNamesMin', 'dayNamesShort', 'defaultDate', 'duration', 'firstDay', 'gotoCurrent', 'hideIfNoPrevNext', 'isRTL', 'maxDate', 'minDate', 'monthNames', 'monthNamesShort', 'navigationAsDateFormat', 'nextText', 'numberOfMonths', 'prevText', 'shortYearCutoff', 'showAnim', 'showButtonPanel', 'showCurrentAtPos', 'showMonthAfterYear', 'showOn', 'showOptions', 'showOtherMonths', 'stepMonths', 'yearRange', ]; foreach ($this->getOptions() as $name => $value) { if (false !== array_search($name, $allowedOptions)) { $options[$name] = $value; } } return $options; } }