Completed
Push — develop ( e1201f...9e183f )
by Daniel
10:47
created

links::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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