/**
  * Render a form <input> element from the provided $element
  *
  * @param  ElementInterface $element
  * @throws Exception\DomainException
  * @return string
  */
 public function render(\Zf2datatable\Form\Element\DateTimeCalendar $element)
 {
     $name = $element->getName();
     if ($name === null || $name === '') {
         throw new Exception\DomainException(sprintf('%s requires that the element has an assigned name; none discovered', __METHOD__));
     }
     $dateFormatValue = \DateTime::createFromFormat(\Zf2datatable\Form\Element\DateTimeCalendar::$DATE_FORMAT_IN, $element->getValue());
     $attributes = $element->getAttributes();
     $attributes['name'] = $name;
     $attributes['type'] = $this->getType($element);
     $date = new \DateTime('NOW');
     $dateFormat = $date->format('d/m/Y');
     if (preg_match(\Zf2datatable\Form\Element\DateTimeCalendar::$DATE_FORMAT_OUT_MASK, $element->getValue(), $match)) {
         $dateFormatValue = \DateTime::createFromFormat(\Zf2datatable\Form\Element\DateTimeCalendar::$DATE_FORMAT_OUT, $element->getValue());
     } else {
         $dateFormatValue = \DateTime::createFromFormat(\Zf2datatable\Form\Element\DateTimeCalendar::$DATE_FORMAT_IN, $element->getValue());
     }
     if ($dateFormatValue instanceof \DateTime) {
         $attributes['value'] = $dateFormatValue->format(\Zf2datatable\Form\Element\DateTimeCalendar::$DATE_FORMAT_IN);
     } else {
         $attributes['value'] = '';
     }
     return sprintf("\n\t\t\t\t<div class='input-group date'  id='{$name}' data-date={$dateFormat}\tdata-date-format='dd/mm/yyyy H:i'>\n\t\t\t\t<input %s%s", $this->createAttributesString($attributes), $this->getInlineClosingBracket());
 }
Пример #2
0
 protected function generateFormElementByType($name, $type, $values = array(), $priority)
 {
     switch ($type) {
         case 'FILE':
             $elm = new Element\File();
             $elm->setLabel(strtoupper($name));
             break;
         case 'SELECT':
             $elm = new Element\Select($name);
             $elm->setLabel(strtoupper($name));
             $elm->setAttribute('id', $name . '_ID');
             if ($values instanceof \Traversable || is_array($values)) {
                 $elm->setValueOptions($values);
             }
             break;
         case 'DATE':
             if (isset($option_elements['DateTimePicker']) && $option_elements['DateTimePicker']['status'] == 'enabled') {
                 $elm = new \Zf2datatable\Form\Element\DateCalendar($name);
                 $elm->setAttribute('id', $name . '_ID');
                 $elm->setAttribute('class', 'form-control');
                 $elm->setLabel($name);
                 $elm->setAttribute('jsOption', $option_elements['DateTimePicker']['options']['date_js_properties']);
                 \Zf2datatable\Form\Element\DateCalendar::setDateFormatIn($option_elements['DateTimePicker']['options']['date_format_in']);
                 \Zf2datatable\Form\Element\DateCalendar::setDateFormatOut($option_elements['DateTimePicker']['options']['date_format_out']);
             } else {
                 $elm = new Element\Date($name);
                 $elm->setLabel(strtoupper($name));
                 $elm->setAttributes(array('type' => 'date'));
                 $elm->setFormat('Y-m-d');
             }
             break;
         case 'DATETIME':
             if (isset($option_elements['DateTimePicker']) && $option_elements['DateTimePicker']['status'] == 'enabled') {
                 $elm = new \Zf2datatable\Form\Element\DateTimeCalendar($name);
                 $elm->setAttribute('id', $name . '_ID');
                 $elm->setAttribute('class', 'form-control');
                 $elm->setLabel($name);
                 $elm->setAttribute('jsOption', $option_elements['DateTimePicker']['options']['datetime_js_properties']);
                 \Zf2datatable\Form\Element\DateTimeCalendar::setDateFormatIn($option_elements['DateTimePicker']['options']['datetime_format_in']);
                 \Zf2datatable\Form\Element\DateTimeCalendar::setDateFormatOut($option_elements['DateTimePicker']['options']['datetime_format_out']);
             } else {
                 $elm = new Element\DateTimeSelect($name);
                 $elm->setLabel(strtoupper($name));
             }
             break;
         default:
             $elm = new Element($name);
             $elm->setLabel(strtoupper($name));
             $elm->setAttributes(array('type' => 'text'));
             break;
     }
     $elm->setOption('priority', $priority);
     return $elm;
 }