Mokuji /www/app/FrontModule/components/Menu.php

Language PHP Lines 88
MD5 Hash 6947b487f71557a4ba3e29cb1f7a63fc
Repository https://github.com/bazo/Mokuji.git View Raw File View Project SPDX
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
class Menu extends Control
{
	protected $model, $translator, $navigation;
        
	public function __construct()
	{
            $this->model = new Front_MenuModel();
            $this->navigation = new NavigationBuilder();
            return $this;
	}
	
	public function setTranslator(ITranslator $translator)
	{
            $this->translator = $translator;
            return $this;
	}
	
	public function render($menu_name)
	{
            $this->navigation->items = array();
            $this->navigation->template->setTranslator($this->translator);
            $menu = $this->model->getByName($menu_name);
            if($menu->template != '') $this->navigation->setTemplate(APP_DIR.$this->getPresenter()->pathToTheme.'/templates/Menus/menu-'.$menu->template.'.phtml');
            if($menu != false)
            {
                $items = $this->getItems($menu->id);
                $this->fillNavigation($items);
                $this->navigation->render();
            }
        
	}
		
	private function getItems($menu_id, $parent = 0)
	{
            return $this->model->getMenuItems($menu_id);
	}
	
	private function fillNavigation($items)
	{
            foreach($items as $key => $item)
            {
                $lang = $this->getPresenter()->lang;
                $parts = explode('/', $item->url);
                if($item->level == 1)
                {
                    if($item->link_type == 'internal')
                    {
                        if($item->url == 'homepagelink')
                            $this->navigation->add($item->title, $this->getPresenter()
                            ->link(':Front:HomePage:homepage'));
                        elseif ( count($parts) == 1 )
                            $this->navigation->add($item->title, $this->getPresenter()
                            ->link(':Front:page:categoryView', array('category' => $item->url, 'lang' => $lang)));
                        elseif ( count($parts) == 2 )
                            $this->navigation->add($item->title, $this->getPresenter()
                            ->link(':Front:page:pageView', array('category' => $parts[0], 'page' => $parts[1], 'lang' => $lang)));
                    }
                    else $this->navigation->add($item->title, $item->url);
                }
                else
                {
                    try
                    {
                        if($item->link_type == 'internal')
                        {
                            if($item->url == 'homepagelink')
                                $this->navigation->getR($item->parent)->add($item->title, $this->getPresenter()
                                ->link(':Front:HomePage:homepage'));
                            elseif ( count($parts) == 1 )
                                $this->navigation->getR($item->parent)->add($item->title, $this->getPresenter()
                                ->link(':Front:page:categoryView', array('category' => $item->url, 'lang' => $lang)));
                            elseif ( count($parts) == 2 )
                                $this->navigation->getR($item->parent)->add($item->title, $this->getPresenter()
                                ->link(':Front:page:pageView', array('category' => $parts[0], 'page' => $parts[1], 'lang' => $lang)));
                        }
                        else $this->navigation->getR($item->parent)->add($item->title, $item->url);
                    }
                    catch(Exception $e)
                    {
                        echo $e->getMessage();
                    }
                }
            }
	}
}
?>
Back to Top