Completed
Push — develop ( 18ce4b...3c36de )
by Daniel
11:04
created

menu::get_depth_options()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

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