|
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\services\menus; |
|
11
|
|
|
|
|
12
|
|
|
abstract class menu_block extends \blitze\sitemaker\services\blocks\driver\block |
|
13
|
|
|
{ |
|
14
|
|
|
/** @var \phpbb\cache\driver\driver_interface */ |
|
15
|
|
|
protected $cache; |
|
16
|
|
|
|
|
17
|
|
|
/** @var \phpbb\config\config */ |
|
18
|
|
|
protected $config; |
|
19
|
|
|
|
|
20
|
|
|
/** @var \phpbb\user */ |
|
21
|
|
|
protected $user; |
|
22
|
|
|
|
|
23
|
|
|
/** @var \blitze\sitemaker\model\mapper_factory */ |
|
24
|
|
|
protected $mapper_factory; |
|
25
|
|
|
|
|
26
|
|
|
/** @var \blitze\sitemaker\services\menus\display */ |
|
27
|
|
|
protected $tree; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Constructor |
|
31
|
|
|
* |
|
32
|
|
|
* @param \phpbb\cache\driver\driver_interface $cache Cache driver interface |
|
33
|
|
|
* @param \phpbb\config\config $config Config object |
|
34
|
|
|
* @param \phpbb\user $user User object |
|
35
|
|
|
* @param \blitze\sitemaker\model\mapper_factory $mapper_factory Mapper factory object |
|
36
|
|
|
* @param \blitze\sitemaker\services\menus\display $tree Menu tree display object |
|
37
|
|
|
*/ |
|
38
|
16 |
|
public function __construct(\phpbb\cache\driver\driver_interface $cache, \phpbb\config\config $config, \phpbb\user $user, \blitze\sitemaker\model\mapper_factory $mapper_factory, \blitze\sitemaker\services\menus\display $tree) |
|
39
|
|
|
{ |
|
40
|
16 |
|
$this->cache = $cache; |
|
41
|
16 |
|
$this->config = $config; |
|
42
|
16 |
|
$this->user = $user; |
|
43
|
16 |
|
$this->mapper_factory = $mapper_factory; |
|
44
|
16 |
|
$this->tree = $tree; |
|
45
|
16 |
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @param int $menu_id |
|
49
|
|
|
* @return array |
|
50
|
|
|
*/ |
|
51
|
14 |
|
protected function _get_menu($menu_id) |
|
52
|
|
|
{ |
|
53
|
14 |
|
if (($data = $this->cache->get('sitemaker_menus')) === false) |
|
54
|
14 |
|
{ |
|
55
|
14 |
|
$data = $this->_get_all_menus(); |
|
56
|
|
|
|
|
57
|
14 |
|
$this->cache->put('sitemaker_menus', $data); |
|
58
|
14 |
|
} |
|
59
|
|
|
|
|
60
|
14 |
|
return (isset($data[$menu_id])) ? $data[$menu_id] : array(); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @return array |
|
65
|
|
|
*/ |
|
66
|
14 |
|
protected function _get_all_menus() |
|
67
|
|
|
{ |
|
68
|
14 |
|
$item_mapper = $this->mapper_factory->create('menus', 'items'); |
|
69
|
|
|
|
|
70
|
14 |
|
$collection = $item_mapper->find(); |
|
71
|
|
|
|
|
72
|
14 |
|
$data = array(); |
|
73
|
14 |
|
foreach ($collection as $entity) |
|
74
|
14 |
|
{ |
|
75
|
14 |
|
$row = $entity->to_array(); |
|
76
|
14 |
|
$this->_set_path_info($row); |
|
77
|
|
|
|
|
78
|
14 |
|
$data[$row['menu_id']][$row['item_id']] = $row; |
|
79
|
14 |
|
} |
|
80
|
|
|
|
|
81
|
14 |
|
return $data; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @param int $menu_id |
|
86
|
|
|
* @param bool $editing |
|
87
|
|
|
* @return string |
|
88
|
|
|
*/ |
|
89
|
8 |
|
protected function _get_message($menu_id, $editing) |
|
90
|
|
|
{ |
|
91
|
8 |
|
$msg_key = ''; |
|
92
|
|
|
if ($editing) |
|
93
|
8 |
|
{ |
|
94
|
4 |
|
$msg_key = ($menu_id) ? 'MENU_NO_ITEMS' : 'SELECT_MENU'; |
|
95
|
4 |
|
} |
|
96
|
|
|
|
|
97
|
8 |
|
return $this->user->lang($msg_key); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @param array $data |
|
102
|
|
|
*/ |
|
103
|
14 |
|
protected function _set_path_info(array &$data) |
|
104
|
|
|
{ |
|
105
|
14 |
|
$url_info = parse_url($data['item_url']); |
|
106
|
|
|
|
|
107
|
14 |
|
$data['url_path'] = (isset($url_info['path'])) ? $url_info['path'] : ''; |
|
108
|
14 |
|
$data['url_query'] = (isset($url_info['query'])) ? explode('&', $url_info['query']) : array(); |
|
109
|
14 |
|
$data['item_target'] = ($data['item_target']) ? ' target="_blank"' : ''; |
|
110
|
14 |
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @return array |
|
114
|
|
|
*/ |
|
115
|
2 |
|
protected function get_menu_options() |
|
116
|
|
|
{ |
|
117
|
2 |
|
$collection = $this->mapper_factory->create('menus', 'menus')->find(); |
|
118
|
|
|
|
|
119
|
2 |
|
$options = array(); |
|
120
|
2 |
|
foreach ($collection as $entity) |
|
121
|
|
|
{ |
|
122
|
2 |
|
$options[$entity->get_menu_id()] = $entity->get_menu_name(); |
|
123
|
2 |
|
} |
|
124
|
|
|
|
|
125
|
2 |
|
return $options; |
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
|