ACC SHELL

Path : /srv/www/vhosts/ambfinance/admin/library/TF/View/Helper/
File Upload :
Current File : /srv/www/vhosts/ambfinance/admin/library/TF/View/Helper/TreeMenu.php

<?php
/**
 * Tree Menu view helper - takes array ("title","depth") on input and
 * returns HTML source of menu as nested ULs
 *
 * @author Tomas Fejfar
 * @example $this->helper->TreeMenu($menu);
 * @package TF
 *
 */
class TF_View_Helper_TreeMenu
{
    private $_result = "";
    private $_iterator = null;
    public $itemTemplate = '';
    public $boxTemplate = '';
    /**
     * Main fcn
     *
     * @return string HTML source code
     */
    public function treeMenu ($tree = array(), $itemTemplate = "treeItem.phtml", $boxTemplate = "box.phtml")
    {
        $this->itemTemplate = $itemTemplate;
        $this->boxTemplate = $boxTemplate;
        if($tree[0]['depth']==0){
            unset($tree[0]);
        }
        $this->iterator = new ArrayIterator($tree);
        $this->_result = '';
        $content = $this->generateMenu($this->iterator);
        $finalView = new Zend_View();
        $finalView->setScriptPath('application/shop/views/partials/menu/');
        $finalView->boxTitle = 'Zboží';
        $finalView->boxContent = $content;
        return $finalView->render($this->boxTemplate);
    }
    /**
     * Internal generator fcn
     *
     * @return string $result HTML source code
     * @param ArrayIterator &$iterator
     * @param int $lastdepth
     */
    function generateMenu (&$iterator, $lastdepth = 1)
    {
    	$result = '';
        $view = new Zend_View();
        $view->setScriptPath('application/shop/views/partials/menu/');
        $item = $iterator->current();
        $lastItem['depth'] = $lastdepth;
        while ($iterator->valid() && ($item['depth'] == $lastItem['depth'])) {
            $view->subMenu = '';
            $uH = new Zend_View_Helper_Url();
            if ($item['url'] != "") {
                $path = $uH->url(array("categoryUrl" => $item['url'] , 'page' => null),
                    "Category");
            } else {
                $path = $uH->url(array("root" => "" , 'page' => null), "base");
            }
            $view->href = $path;
            $view->title = $item['title'];
            $view->active = null;//$item['active'];
            $view->depth = $item['depth'];
            $view->query = (isset($item['query'])?$item['query']:'');
            $lastItem = $item;
            $iterator->next();
            $item = $iterator->current();
            if ($item['depth'] > $lastItem['depth']) {
                $view->subMenu = $this->generateMenu($iterator, $item['depth']);
                $item = $iterator->current();
            }
            $tmp = $view->render($this->itemTemplate);
            $result .= $tmp;
        }
        return $result;
    }
}

ACC SHELL 2018