[], // links that will be added above the element 'treeViewOptions' => [], // options that will be passed to jQuery TreeView element ]; protected $_name; /** * Recursively renders tree of checkboxes * * @param $name * @param array|null $value Indexed array of ids * @param array|null $attribs * @param array|null $options array('id' => int, 'title' => string, 'sub' => array(...)) * @param string $listsep * @return string Html */ public function formCheckboxTree($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 $options = (array) $options; $value = (array) $value; $name = $this->view->escape($name); $name .= ('[]' === substr($name, -2)) ? '' : '[]'; $this->_name = $name; foreach ($this->_specialOptionNames as $specialName) { if (isset($attribs[$specialName])) { $this->_specialOptions[$specialName] = $attribs[$specialName]; unset($attribs[$specialName]); } } $attribs['id'] = $id; $treeId = $id . '-tree'; $xhtml = '_htmlAttribs($attribs) . '>' . $this->_renderLinks($this->_specialOptions['links']) . $this->_renderTree($options, $value, ['id' => $treeId]) . ''; return $xhtml; } /** * @param array $options array('id' => int, 'title' => string, 'sub' => array(...)) * @param array $value [OPTIONAL] * @param array $attribs [OPTIONAL] * @return string */ protected function _renderTree(array $options, array $value = null, array $attribs = null) { $xhtml = ''; foreach ($options as $node) { $nodeId = (int) $node['id']; $nodeAttribs = (isset($node['attribs'])) ? (array) $node['attribs'] : []; if ($value && in_array($nodeId, $value)) { $nodeAttribs['checked'] = 'checked'; } $xhtml .= '
  • ' . '' . (!empty($node['sub']) ? $this->_renderTree($node['sub'], $value) : '') . '
  • '; } $xhtml = $xhtml ? '_htmlAttribs($attribs) . '>' . $xhtml . '' : ''; return $xhtml; } /** * Creates an input element * * @param string $type * @param string $name * @param string|null $value * @param array|null $attribs * @return string */ protected function _input($type, $name, $value = null, $attribs = null) { return '_htmlAttribs($attribs) . $this->getClosingBracket(); } protected function _renderLinks(array $links) { if (end($links) && null !== ($lastKey = key($links))) { if (!empty($links[$lastKey]['class'])) { $links[$lastKey]['class'] .= ' last'; } else { $links[$lastKey]['class'] = 'last'; } } $linksHtml = []; foreach ($links as $link) { $title = ''; if (isset($link['title'])) { $title = $link['title']; unset($link['title']); } $linksHtml[] = '
  • ' . '_htmlAttribs($link) . '>' . $this->view->escape($title) . '' . '
  • '; } if (empty($linksHtml)) { return ''; } $xhtml = ''; return $xhtml; } }