_index; } public function setIndex($index) { $this->_index = $index; return $this; } public function isLast() { return $this->last; } public function setLast($last) { $this->last = $last; return $this; } public function isFirst() { return $this->first; } public function setFirst($first) { $this->first = $first; return $this; } protected function _initElements() { if ($this->isNumerable()) { $this->addRowNumber(); } $this->bindElements(); $this->addOptionsColumn(); return parent::_initElements(); } abstract protected function bindElements(); public function isIsDataCollectionItem() { return $this->_isDataCollectionItem; } public function setIsDataCollectionItem($dataCollectionItem) { $this->_isDataCollectionItem = $dataCollectionItem; return $this; } public function hasOptionsColumn() { return $this->isSortable() || $this->isRemovable(); } public function loadDefaultDecorators() { if ($this->loadDefaultDecoratorsIsDisabled()) { return $this; } $decorators = $this->getDecorators(); if (empty($decorators)) { $this->addDecorator('FormElements'); $self = $this; $attributes = [ 'tag' => 'tr', 'id' => ['callback' => function () use ($self) { return $self->getId(); }], ]; if ($this->isIsDataCollectionItem()) { $attributes['data-collection-item'] = $this->getName(); } $this->addDecorator(['tr' => 'HtmlTag'], $attributes); } return $this; } public function render(Zend_View_Interface $view = null) { if ($this->getOrientation() == Table::ORIENTATION_VERTICAL) { $elements = []; foreach ($this as $item) { $elements[] = $item->getName(); } if ($this->hasOptionsColumn() && false !== ($index = array_search('options', $elements))) { unset($elements[$index]); } /** @var \Qs_Form_Decorator_FormElements $decorator */ if (($decorator = $this->getDecorator('FormElements'))) { $decorator->setOption('wrappers', [ [ 'elements' => $elements, 'decorators' => [ ['HtmlTag', ['tag' => 'dl']], ['HtmlTag', ['tag' => 'td', 'class' => 'c_elements']], ], ], ]); } } return parent::render($view); } public function addElement($element, $name = null, $options = null) { if ($this->getOrientation() == Table::ORIENTATION_VERTICAL) { return parent::addElement($element, $name, $options); } if (is_string($element)) { if (!is_array($options) || !array_key_exists('decorators', $options)) { $class = 'c_' . $name; if ($element == 'hidden') { $class .= ' hidden'; } switch ($element) { case 'numeric': $options['decorators'] = ['Numeric']; break; case 'date': $options['decorators'] = ['JQuery_Datepicker']; break; default: $options['decorators'] = ['ViewHelper']; break; } if (0 === strcasecmp($element, 'HtmlEditor')) { $options['decorators'][] = 'CkEditor'; } if ($element == 'phone') { $options['decorators'][] = 'Phone'; } $options['decorators'] = array_merge($options['decorators'], [ 'Errors', 'Description', [ 'HtmlTag', [ 'tag' => 'td', 'class' => $class, 'id' => ['callback' => ['Zend_Form_Element', 'resolveElementId']], ], ], ]); } } return parent::addElement($element, $name, $options); } public function addRowNumber() { $this->addElement('static', 'rowNumber', ['label' => '#', 'value' => $this->getIndex() + 1]); if (($decorator = $this->getElement('rowNumber')->getDecorator('HtmlTag'))) { $decorator->setOption('data-row-number', ''); } return $this; } public function addOptionsColumn() { $group = []; $classes = ['c_options']; if ($this->isSortable()) { $classes[] = 'c_sortable'; $this->addElement( 'button', 'moveUp', [ 'label' => '', 'title' => 'Move Up', 'data-action-up' => '', 'class' => 'btn btn-small fa fa-long-arrow-up', 'decorators' => ['ViewHelper'], ] ); $this->addElement( 'button', 'moveDown', [ 'label' => '', 'title' => 'Move Down', 'data-action-down' => '', 'class' => 'btn btn-small fa fa-long-arrow-down', 'decorators' => ['ViewHelper'], ] ); $group[] = 'moveUp'; $group[] = 'moveDown'; } if ($this->isRemovable()) { $this->addElement( 'button', 'delete', [ 'label' => 'Delete', 'data-action-delete' => '', 'class' => 'btn btn-small btn-danger btn-delete', 'decorators' => ['ViewHelper'], ] ); $group[] = 'delete'; } if (empty($group)) { return $this; } $this->addDisplayGroup( $group, 'options', [ 'legend' => 'Options', 'class' => 'options', 'decorators' => [ 'FormElements', [ 'HtmlTag', [ 'tag' => 'td', 'data-options-cell' => '', 'class' => implode(' ', $classes), ], ], ], ] ); return $this; } }