Completed
Push — develop ( 86b038...fd19b8 )
by Daniel
09:51
created

links   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 77
ccs 27
cts 27
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A get_config() 0 9 1
A display() 0 18 2
A get_message() 0 10 3
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\blocks\driver\block;
13
14
/**
15
* Links Block
16
* @package phpBB Sitemaker
17
*/
18
class links extends block
19
{
20
	/** @var \phpbb\language\language */
21
	protected $language;
22
23
	/** @var \blitze\sitemaker\services\menus\navigation */
24
	protected $navigation;
25
26
	/** @var string */
27
	protected $title = 'LINKS';
28
29
	/** @var string */
30
	protected $tpl_name = 'links';
31
32
	/**
33
	 * Constructor
34
	 *
35
	 * @param \phpbb\language\language						$language		Language object
36
	 * @param \blitze\sitemaker\services\menus\navigation	$navigation		sitemaker navigation object
37
	 */
38 19
	public function __construct(\phpbb\language\language $language, \blitze\sitemaker\services\menus\navigation $navigation)
39
	{
40 19
		$this->language = $language;
41 19
		$this->navigation = $navigation;
42 19
	}
43
44
	/**
45
	 * {@inheritdoc}
46
	 */
47 1
	public function get_config(array $settings)
48
	{
49 1
		$menu_options = $this->navigation->get_menu_options();
50
51
		return array(
52 1
			'legend1'       => 'SETTINGS',
53 1
			'menu_id'		=> array('lang' => 'MENU', 'validate' => 'int', 'type' => 'select', 'options' => $menu_options, 'default' => 0, 'explain' => false),
54 1
		);
55
	}
56
57
	/**
58
	 * {@inheritdoc}
59
	 */
60 17
	public function display(array $db_data, $editing = false)
61
	{
62 17
		$menu_id = $db_data['settings']['menu_id'];
63
64 17
		if (!$this->navigation->build_menu($this->ptemplate, $menu_id, $db_data['settings']))
65 17
		{
66
			return array(
67 8
				'title'		=> $this->title,
68 8
				'content'	=> $this->get_message($menu_id, $editing),
69 8
				'status'	=> (int) !$editing,
70 8
			);
71 1
		}
72
73
		return array(
74 9
			'title'     => $this->title,
75 9
			'content'   => $this->ptemplate->render_view('blitze/sitemaker', 'blocks/' . $this->tpl_name . '.html', $this->tpl_name . '_block'),
76 9
		);
77
	}
78
79
	/**
80
	 * @param int $menu_id
81
	 * @param bool $editing
82
	 * @return string
83
	 */
84 8
	protected function get_message($menu_id, $editing)
85
	{
86 8
		$msg_key = '';
87
		if ($editing)
88 8
		{
89 4
			$msg_key = ($menu_id) ? 'MENU_NO_ITEMS' : 'SELECT_MENU';
90 4
		}
91
92 8
		return $this->language->lang($msg_key);
93
	}
94
}
95