Completed
Push — develop ( 9e183f...0abb5c )
by Daniel
08:58
created

links::get_message()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 2
crap 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
	/** @var bool */
33
	protected $is_navigation = false;
34
35
	/**
36
	 * Constructor
37
	 *
38
	 * @param \phpbb\language\language						$language		Language object
39
	 * @param \blitze\sitemaker\services\menus\navigation	$navigation		sitemaker navigation object
40
	 */
41 19
	public function __construct(\phpbb\language\language $language, \blitze\sitemaker\services\menus\navigation $navigation)
42
	{
43 19
		$this->language = $language;
44 19
		$this->navigation = $navigation;
45 19
	}
46
47
	/**
48
	 * {@inheritdoc}
49
	 */
50 1
	public function get_config(array $settings)
51
	{
52 1
		$menu_options = $this->navigation->get_menu_options();
53
54
		return array(
55 1
			'legend1'       => 'SETTINGS',
56 1
			'menu_id'		=> array('lang' => 'MENU', 'validate' => 'int', 'type' => 'select', 'options' => $menu_options, 'default' => 0, 'explain' => false),
57 1
		);
58
	}
59
60
	/**
61
	 * {@inheritdoc}
62
	 */
63 17
	public function display(array $db_data, $editing = false)
64
	{
65 17
		$menu_id = $db_data['settings']['menu_id'];
66
67 17
		if (!$this->navigation->build_menu($this->ptemplate, $menu_id, $this->is_navigation, $db_data['settings']))
68 17
		{
69
			return array(
70 8
				'title'		=> $this->title,
71 8
				'content'	=> $this->get_message($menu_id, $editing),
72 8
				'status'	=> (int) !$editing,
73 8
			);
74
		}
75
76
		return array(
77 9
			'title'     => $this->title,
78 9
			'content'   => $this->ptemplate->render_view('blitze/sitemaker', 'blocks/' . $this->tpl_name . '.html', $this->tpl_name . '_block'),
79 10
		);
80
	}
81
82
	/**
83
	 * @param int $menu_id
84
	 * @param bool $editing
85
	 * @return string
86
	 */
87 8
	protected function get_message($menu_id, $editing)
88
	{
89 8
		$msg_key = '';
90
		if ($editing)
91 8
		{
92 4
			$msg_key = ($menu_id) ? 'MENU_NO_ITEMS' : 'SELECT_MENU';
93 4
		}
94
95 8
		return $this->language->lang($msg_key);
96
	}
97
}
98