Gc\Component\TreeView::render PHP Method

render() public static method

Render treeview html
public static render ( array $treeviewData = [], boolean $init = true ) : string
$treeviewData array Contains data as array
$init boolean Initialize
return string
    public static function render(array $treeviewData = array(), $init = true)
    {
        $html = '';
        if ($init) {
            $html .= '<div id="browser">';
        }
        $html .= '<ul>';
        foreach ($treeviewData as $iterator) {
            if (!$iterator instanceof IterableInterface) {
                continue;
            }
            $children = $iterator->getChildren();
            $hasChildren = !empty($children);
            $html .= '<li id="' . $iterator->getIterableId() . '"';
            if ($hasChildren) {
                $rel = ' class="folder"';
                $ins = '<ins class="jstree-icon">&nbsp;</ins>';
                $renderChildren = self::render($children, false);
            } else {
                $renderChildren = '';
                $rel = ' class="default"';
                $ins = '';
                $requestUri = Registry::get('Application')->getRequest()->getUri()->getPath();
                if ($requestUri == $iterator->getEditUrl()) {
                    $rel = ' class="default active"';
                }
            }
            $html .= $rel . '>' . $ins;
            $html .= self::renderLink($iterator);
            $html .= self::renderIcon($iterator);
            $html .= $iterator->getName() . '</a>';
            $html .= $renderChildren;
            $html .= '</li>';
        }
        $html .= '</ul>';
        if ($init) {
            $html .= '</div>';
        }
        return $html;
    }

Usage Example

Esempio n. 1
0
 /**
  * Test
  *
  * @return void
  */
 public function testRender()
 {
     Registry::get('Application')->getRequest()->getUri()->setPath($this->documentChildren->getEditUrl());
     $collection = new DocumentCollection();
     $collection->load(0);
     $array = array_merge(array($collection), array('test' => 'value'));
     $this->assertTrue(strlen($this->object->render($array)) > 0);
 }
All Usage Examples Of Gc\Component\TreeView::render