Completed
Push — master ( edb932...4a8b55 )
by Daniel
08:30
created

menu::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 7
cts 7
cp 1
rs 9.4286
cc 1
eloc 6
nc 1
nop 5
crap 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\blocks;
11
12
use blitze\sitemaker\services\menus\menu_block;
13
14
/**
15
* Menu Block
16
* @package phpBB Sitemaker Main Menu
17
*/
18
class menu extends menu_block
19
{
20
	/** @var \phpbb\user */
21
	protected $user;
22
23
	/** @var \blitze\sitemaker\services\menus\display */
24
	protected $tree;
25
26
	/**
27
	 * {@inheritdoc}
28
	 */
29 1
	public function get_config(array $settings)
30
	{
31 1
		$menu_options = $this->get_menu_options();
32 1
		$depth_options = $this->get_depth_options();
33
34
		return array(
35 1
			'legend1'       => $this->user->lang('SETTINGS'),
36 1
			'menu_id'		=> array('lang' => 'MENU', 'validate' => 'int', 'type' => 'select', 'options' => $menu_options, 'default' => 0, 'explain' => false),
37 1
			'expanded'		=> array('lang' => 'EXPANDED', 'validate' => 'bool', 'type' => 'checkbox', 'options' => array(1 => ''), 'default' => 0, 'explain' => false),
38 1
			'max_depth'		=> array('lang' => 'MAX_DEPTH', 'validate' => 'int', 'type' => 'select', 'options' => $depth_options, 'default' => 3, 'explain' => false),
39 1
		);
40
	}
41
42
	/**
43
	 * {@inheritdoc}
44
	 */
45 9
	public function display(array $db_data, $editing = false)
46
	{
47 9
		$title = $this->user->lang('MENU');
48 9
		$menu_id = $db_data['settings']['menu_id'];
49
50 9
		$data = $this->_get_menu($menu_id);
51
52 9
		if (!sizeof($data))
53 9
		{
54
			return array(
55 4
				'title'		=> $title,
56 4
				'content'	=> $this->_get_message($menu_id, $editing),
57 4
			);
58
		}
59
60 5
		$this->tree->set_params($db_data['settings']);
61 5
		$this->tree->display_navlist($data, $this->ptemplate, 'tree');
62 5
		$this->tree->generate_breadcrumb($data);
63
64
		return array(
65 5
			'title'     => $title,
66 5
			'content'   => $this->ptemplate->render_view('blitze/sitemaker', 'blocks/menu.html', 'menu_block'),
67 5
		);
68
	}
69
70
	/**
71
	 * @return array
72
	 */
73 1
	protected function get_depth_options()
74
	{
75 1
		$options = array();
76 1
		for ($i = 3; $i < 10; $i++)
77
		{
78 1
			$options[$i] = $i;
79 1
		}
80
81 1
		return $options;
82
	}
83
}
84