Completed
Push — master ( 788440...382d5e )
by Daniel
08:36
created

menu_module::main()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 48
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 34
CRAP Score 5

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 48
ccs 34
cts 34
cp 1
rs 8.551
cc 5
eloc 28
nc 3
nop 0
crap 5
1
<?php
2
/**
3
 *
4
 * @package sitemaker
5
 * @copyright (c) 2013 Daniel A. (blitze)
6
 * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7
 *
8
 */
9
10
namespace blitze\sitemaker\acp;
11
12
use blitze\sitemaker\services\menus\nestedset;
13
14
/**
15
* @package acp
16
*/
17
class menu_module
18
{
19
	/** @var \phpbb\request\request_interface */
20
	protected $request;
21
22
	/** @var \phpbb\template\template */
23
	protected $template;
24
25
	/** @var \blitze\sitemaker\services\icon_picker */
26
	protected $icon;
27
28
	/** @var \blitze\sitemaker\model\mapper_factory */
29
	protected $mapper_factory;
30
31
	/** @var \blitze\sitemaker\services\util */
32
	protected $util;
33
34
	/** @var string phpBB root path */
35
	protected $phpbb_root_path;
36
37
	/** @var string phpEx */
38
	protected $php_ext;
39
40
	/** @var string */
41
	public $tpl_name;
42
43
	/** @var string */
44
	public $page_title;
45
46
	/** @var string */
47
	public $u_action;
48
49 2
	public function __construct()
50
	{
51 2
		global $phpbb_container, $request, $template, $phpbb_root_path, $phpEx;
52
53 2
		$this->request = $request;
54 2
		$this->template = $template;
55 2
		$this->phpbb_root_path = $phpbb_root_path;
56 2
		$this->php_ext = $phpEx;
57
58 2
		$this->mapper_factory = $phpbb_container->get('blitze.sitemaker.mapper.factory');
59 2
		$this->icon = $phpbb_container->get('blitze.sitemaker.icon_picker');
60 2
		$this->util = $phpbb_container->get('blitze.sitemaker.util');
61 2
	}
62
63 2
	public function main()
64
	{
65 2
		$menu_id = $this->request->variable('menu_id', 0);
66
67 2
		$menu_mapper = $this->mapper_factory->create('menus', 'menus');
68
69
		// Get all menus
70 2
		$collection = $menu_mapper->find();
71
72 2
		if ($collection->valid())
73 2
		{
74 2
			$menu = (isset($collection[$menu_id])) ? $collection[$menu_id] : $collection->current();
75 2
			$menu_id = $menu->get_menu_id();
76
77 2
			foreach ($collection as $entity)
78
			{
79 2
				$id = $entity->get_menu_id();
80 2
				$this->template->assign_block_vars('menu', array(
81 2
					'ID'		=> $id,
82 2
					'NAME'		=> $entity->get_menu_name(),
83 2
					'S_ACTIVE'	=> ($id == $menu_id) ? true : false,
84 2
				));
85 2
			}
86 2
		}
87
88 2
		nestedset::load_scripts($this->util);
89
90 2
		$this->util->add_assets(array(
91
			'js'	=> array(
92 2
				'@blitze_sitemaker/assets/menu/admin.min.js',
93 2
			),
94
			'css'	=> array(
95 2
				'@blitze_sitemaker/assets/menu/admin.min.css',
96
			)
97 2
		));
98
99 2
		$this->template->assign_vars(array(
100 2
			'S_MENU'		=> true,
101 2
			'MENU_ID'		=> $menu_id,
102 2
			'ICON_PICKER'	=> $this->icon->picker(),
103 2
			'T_PATH'		=> $this->phpbb_root_path,
104 2
			'UA_MENU_ID'	=> $menu_id,
105 2
			'UA_AJAX_URL'   => "{$this->phpbb_root_path}app.{$this->php_ext}/menu/admin/")
106 2
		);
107
108 2
		$this->tpl_name = 'acp_menu';
109 2
		$this->page_title = 'ACP_MENU';
110 2
	}
111
}
112