menu_module   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 155
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 63
dl 0
loc 155
ccs 64
cts 64
cp 1
rs 10
c 0
b 0
f 0
wmc 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 1
A list_menus() 0 20 5
A main() 0 20 1
A get_forums_string() 0 12 2
A build_bulk_options() 0 19 1
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 Symfony\Component\Routing\Generator\UrlGeneratorInterface;
13
14
/**
15
* @package acp
16
*/
17
class menu_module
18
{
19
	/** @var \phpbb\controller\helper */
20
	protected $controller_helper;
21
22
	/** @var \phpbb\event\dispatcher_interface */
23
	protected $phpbb_dispatcher;
24
25
	/** @var \phpbb\request\request_interface */
26
	protected $request;
27
28
	/** @var \phpbb\template\template */
29
	protected $template;
30
31
	/** @var \blitze\sitemaker\services\icons\picker */
32
	protected $icon;
33
34
	/** @var \phpbb\language\language */
35
	protected $language;
36
37
	/** @var \phpbb\user */
38
	protected $user;
39
40
	/** @var \blitze\sitemaker\model\mapper_factory */
41
	protected $mapper_factory;
42
43
	/** @var string phpBB root path */
44
	protected $phpbb_root_path;
45
46
	/** @var string phpEx */
47
	protected $php_ext;
48
49
	/** @var string */
50
	public $tpl_name;
51
52
	/** @var string */
53
	public $page_title;
54
55
	/** @var string */
56
	public $u_action;
57
58
	/**
59
	 * menu_module constructor.
60
	 */
61
	public function __construct()
62 2
	{
63
		global $phpbb_container, $phpbb_dispatcher, $request, $template, $user, $phpbb_root_path, $phpEx;
64 2
65
		$this->phpbb_dispatcher = $phpbb_dispatcher;
66 2
		$this->request = $request;
67 2
		$this->template = $template;
68 2
		$this->user = $user;
69 2
		$this->phpbb_root_path = $phpbb_root_path;
70 2
		$this->php_ext = $phpEx;
71
72 2
		$this->controller_helper = $phpbb_container->get('controller.helper');
73 2
		$this->language = $phpbb_container->get('language');
74 2
		$this->mapper_factory = $phpbb_container->get('blitze.sitemaker.mapper.factory');
75 2
		$this->icon = $phpbb_container->get('blitze.sitemaker.icons.picker');
76 2
	}
77 2
78
	/**
79
	 * @return void
80
	 */
81
	public function main()
82 2
	{
83
		$menu_id = $this->request->variable('menu_id', 0);
84 2
85
		$this->list_menus($menu_id);
86 2
		$this->build_bulk_options();
87 2
88 2
		$this->template->assign_vars(array(
89 2
			'S_MENU'		=> true,
90 2
			'GROUP_ID'		=> $menu_id,
91
			'ICON_PICKER'	=> $this->icon->picker(),
92 2
			'SM_USER_LANG'	=> $this->user->data['user_lang'],
93 2
			'SCRIPT_PATH'	=> $this->user->page['root_script_path'],
94
			'SESSION_ID'	=> $this->user->data['session_id'],
95 2
			'T_PATH'		=> $this->phpbb_root_path,
96 2
			'UA_AJAX_URL'   => $this->controller_helper->route('blitze_sitemaker_menus_admin', array(), true, '') . '/',
97 2
		));
98 2
99 2
		$this->tpl_name = 'acp_menu';
100 2
		$this->page_title = 'ACP_MENU';
101 2
	}
102
103 2
	/**
104 2
	 * @param int $menu_id
105 2
	 * @return void
106
	 */
107
	protected function list_menus(&$menu_id)
108
	{
109
		$menu_mapper = $this->mapper_factory->create('menus');
110
111 2
		// Get all menus
112
		$collection = $menu_mapper->find();
113 2
114
		if ($collection->valid())
115
		{
116 2
			/** @var \blitze\sitemaker\model\entity\menu $menu */
117
			$menu = (isset($collection[$menu_id])) ? $collection[$menu_id] : $collection->current();
118 2
			$menu_id = $menu->get_menu_id();
119 2
120 2
			foreach ($collection as $entity)
121 2
			{
122
				$id = $entity->get_menu_id();
123 2
				$this->template->assign_block_vars('groups', array(
124
					'ID'		=> $id,
125 2
					'NAME'		=> $entity->get_menu_name(),
126 2
					'S_ACTIVE'	=> ($id == $menu_id) ? true : false,
127 2
				));
128 2
			}
129 2
		}
130 2
	}
131 2
132 2
	/**
133 2
	 * @return void
134
	 */
135
	protected function build_bulk_options()
136
	{
137
		$bulk_options = array();
138 2
		$forumslist = (array) make_forum_select(false, false, true, false, false, false, true);
139
140 2
		/**
141 2
		 * Event to add bulk menu options
142
		 *
143
		 * @event blitze.sitemaker.acp_add_bulk_menu_options
144
		 * @var	array	bulk_options	Array of bulk menu options
145
		 * @var	array	forumslist		Array of phpBB forums
146
		 * @since 3.1.0
147
		 */
148
		$vars = array('bulk_options', 'forumslist');
149
		extract($this->phpbb_dispatcher->trigger_event('blitze.sitemaker.acp_add_bulk_menu_options', compact($vars)));
150
151 2
		$bulk_options['FORUMS']	= $this->get_forums_string($forumslist);
152 2
153
		$this->template->assign_var('bulk_options', $bulk_options);
154 2
	}
155
156 2
	/**
157 2
	 * @param array $forumslist
158
	 * @return string
159
	 */
160
	protected function get_forums_string(array $forumslist)
161
	{
162
		$forum_url = $this->controller_helper->route('blitze_sitemaker_forum', array(), true, '', UrlGeneratorInterface::RELATIVE_PATH);
163 2
		$text = $this->language->lang('FORUM') . '|' . $forum_url . "\n";
164
		foreach ($forumslist as $forum_id => $row)
165 2
		{
166 2
			$text .= "\t" . str_replace('&nbsp; &nbsp;', "\t", $row['padding']);
167 2
			$text .= $row['forum_name'] . '|';
168
			$text .= "viewforum.{$this->php_ext}?f=$forum_id\n";
169 2
		}
170 2
171 2
		return trim($text);
172 2
	}
173
}
174