1 | <?php |
||
12 | class routes |
||
13 | { |
||
14 | /** @var \phpbb\cache\driver\driver_interface */ |
||
15 | protected $cache; |
||
16 | |||
17 | /** @var \phpbb\config\config */ |
||
18 | protected $config; |
||
19 | |||
20 | /** @var \blitze\sitemaker\services\blocks\factory */ |
||
21 | protected $block_factory; |
||
22 | |||
23 | /** @var \blitze\sitemaker\model\mapper_factory */ |
||
24 | protected $mapper_factory; |
||
25 | |||
26 | /** |
||
27 | * Constructor |
||
28 | * |
||
29 | * @param \phpbb\cache\driver\driver_interface $cache Cache driver interface |
||
30 | * @param \phpbb\config\config $config Config object |
||
31 | * @param \blitze\sitemaker\services\blocks\factory $block_factory Blocks factory object |
||
32 | * @param \blitze\sitemaker\model\mapper_factory $mapper_factory Mapper factory object |
||
33 | */ |
||
34 | 22 | public function __construct(\phpbb\cache\driver\driver_interface $cache, \phpbb\config\config $config, \blitze\sitemaker\services\blocks\factory $block_factory, \blitze\sitemaker\model\mapper_factory $mapper_factory) |
|
41 | |||
42 | /** |
||
43 | * @param string $current_route |
||
44 | * @param int $style_id |
||
45 | * @param bool|false $edit_mode |
||
46 | * @return array |
||
47 | */ |
||
48 | 7 | public function get_route_info($current_route, $style_id, $edit_mode = false) |
|
49 | { |
||
50 | 7 | $all_routes = $this->get_all_routes(); |
|
51 | |||
52 | 7 | if (isset($all_routes[$style_id][$current_route])) |
|
53 | 7 | { |
|
54 | 7 | return $all_routes[$style_id][$current_route]; |
|
55 | } |
||
56 | else |
||
57 | { |
||
58 | 2 | return $this->get_default_route_info($all_routes, $current_route, $style_id, $edit_mode); |
|
59 | } |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * @param array $route_info |
||
64 | * @param int $style_id |
||
65 | * @param bool $edit_mode |
||
66 | * @return array |
||
67 | */ |
||
68 | 7 | public function get_blocks_for_route(array $route_info, $style_id, $edit_mode) |
|
69 | { |
||
70 | 7 | $blocks = $this->get_cached_blocks($edit_mode); |
|
71 | 7 | $route_id = $this->get_display_route_id($route_info, $style_id, $edit_mode); |
|
72 | |||
73 | 7 | return (isset($blocks[$style_id][$route_id]) && !$route_info['hide_blocks']) ? $blocks[$style_id][$route_id] : array(); |
|
74 | } |
||
75 | |||
76 | /** |
||
77 | * @param array $df_settings |
||
78 | * @param array $db_settings |
||
79 | * @return array |
||
80 | */ |
||
81 | 21 | public function sync_settings(array $df_settings, array $db_settings = array()) |
|
95 | |||
96 | /** |
||
97 | * Clear blocks cache |
||
98 | */ |
||
99 | 1 | public function clear_cache() |
|
100 | { |
||
101 | 1 | $this->cache->destroy('sitemaker_blocks'); |
|
102 | 1 | $this->cache->destroy('sitemaker_block_routes'); |
|
103 | 1 | } |
|
104 | |||
105 | /** |
||
106 | * @param bool $edit_mode |
||
107 | * @return array |
||
108 | */ |
||
109 | 7 | protected function get_cached_blocks($edit_mode) |
|
119 | |||
120 | /** |
||
121 | * @return array |
||
122 | */ |
||
123 | 7 | protected function get_all_blocks() |
|
148 | |||
149 | /** |
||
150 | * @return array|mixed |
||
151 | */ |
||
152 | 7 | protected function get_all_routes() |
|
172 | |||
173 | /** |
||
174 | * @param array $all_routes |
||
175 | * @param string $current_route |
||
176 | * @param int $style_id |
||
177 | * @param bool $edit_mode |
||
178 | * @return array |
||
179 | */ |
||
180 | 2 | protected function get_default_route_info(array $all_routes, $current_route, $style_id, $edit_mode) |
|
194 | |||
195 | /** |
||
196 | * @param array $route_info |
||
197 | * @param int $style_id |
||
198 | * @param bool $edit_mode |
||
199 | * @return int |
||
200 | */ |
||
201 | 7 | protected function get_display_route_id(array $route_info, $style_id, $edit_mode) |
|
212 | |||
213 | /** |
||
214 | * @param array $blocks |
||
215 | * @param bool $edit_mode |
||
216 | */ |
||
217 | 7 | protected function cache_block(array $blocks, $edit_mode) |
|
224 | } |
||
225 |