[ 'addAll' => 'Add all', 'removeAll' => 'Remove all', 'itemsSelected' => 'items selected', ], ]; protected function _extractOptions(array &$attribs, array $names, array $defaults = []) { $options = []; foreach ($names as $name) { if (array_key_exists($name, $attribs)) { if (array_key_exists($name, $defaults) && is_array($defaults[$name])) { $options[$name] = array_merge($defaults[$name], (array) $attribs[$name]); } else { $options[$name] = $attribs[$name]; } unset($attribs[$name]); } elseif (array_key_exists($name, $defaults)) { $options[$name] = $defaults[$name]; } } return $options; } protected function _extractSpecialOptions(array &$attribs) { $this->_specialOptions = $this->_extractOptions( $attribs, $this->_specialOptionNames, $this->_specialOptionDefaults ); return $this->_specialOptions; } /** * Renders * * @param string $name * @param array|null $value Indexed array with ids of selected options * @param array|null $attribs * @param array|null $options Associative array with all available options (id => title) * @param string $listsep * @return string Html */ public function formMultiDraggableSelect($name, $value = null, $attribs = null, $options = null, $listsep = null) { $info = $this->_getInfo($name, $value, $attribs, $options, $listsep); $id = $disable = $escape = null; extract($info); // name, id, value, attribs, options, listsep, disable, escape $value = (array) $value; $options = (array) $options; $name .= ('[]' === substr($name, -2)) ? '' : '[]'; $this->_name = $name; $attribs['id'] = $this->_id = $id; $this->_extractSpecialOptions($attribs); $separatedOptions = ['available' => [], 'selected' => []]; $order = 0; foreach ($options as $optValue => $optTitle) { $type = (in_array($optValue, $value)) ? 'selected' : 'available'; $separatedOptions[$type][$order++] = ['value' => $optValue, 'title' => $optTitle]; } return $this->_renderElement($attribs, $separatedOptions['available'], $separatedOptions['selected']); } protected function _renderElement(array $attribs, array $available, array $selected) { if (($width = $this->_getWidth())) { $attribs['style'] = 'width: ' . $width; } $xhtml = '_htmlAttribs($attribs) . '>' . '
' . $this->_renderAvailableHeader() . $this->_renderItemsList($available) . '
' . '
' . $this->_renderSelectedHeader(count($selected)) . $this->_renderItemsList($selected, true) . '
' . '
' . ''; return $xhtml; } protected function _renderAvailableHeader() { $xhtml = '
' . '' . '' . $this->_label('addAll') . '' . '
'; return $xhtml; } protected function _renderSelectedHeader($selectedCount = 0) { $xhtml = '
' . '' . '' . (int) $selectedCount . ' ' . $this->_label('itemsSelected') . '' . '' . $this->_label('removeAll') . '' . '
'; return $xhtml; } /** * @param array $options array($order => array('value' => $id, 'title' => $title), ...) * @param bool $selected * @return string */ protected function _renderItemsList(array $options, $selected = false) { $listClass = ($selected ? 'selectedList' : 'availableList'); $xhtml = ''; return $xhtml; } protected function _label($name) { if (isset($this->_specialOptions['labels']) && array_key_exists($name, $this->_specialOptions['labels'])) { return $this->_specialOptions['labels'][$name]; } throw new Exception('Unknown label name "' . $name . '"'); } protected function _getWidth() { return $this->_getDimension('width'); } protected function _getHeight() { return $this->_getDimension('height'); } protected function _getDimension($name) { if (isset($this->_specialOptions[$name])) { $value = (string) $this->_specialOptions[$name]; $value = (preg_match('/%|px|em|pt$/', $value)) ? $value : (float) $value . 'px'; return $this->view->escape($value); } return null; } }