Passed
Push — develop ( 968c4b...624076 )
by Daniel
19:04
created

sitemaker::hide_hidden_forums()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 8
ccs 6
cts 6
cp 1
crap 2
rs 10
1
<?php
2
3
/**
4
 *
5
 * @package sitemaker
6
 * @copyright (c) 2013 Daniel A. (blitze)
7
 * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
8
 *
9
 */
10
11
namespace blitze\sitemaker\event;
12
13
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
14
15
class sitemaker implements EventSubscriberInterface
16
{
17
	/** @var \phpbb\cache\driver\driver_interface */
18
	protected $cache;
19
20
	/** @var \phpbb\config\config */
21
	protected $config;
22
23
	/** @var \phpbb\controller\helper */
24
	protected $controller_helper;
25
26
	/** @var \phpbb\template\template */
27
	protected $template;
28
29
	/** @var \phpbb\language\language */
30
	protected $translator;
31
32
	/** @var \phpbb\user */
33
	protected $user;
34
35
	/* @var \blitze\sitemaker\services\util */
36
	protected $util;
37
38
	/* @var \blitze\sitemaker\services\blocks\display */
39
	protected $blocks;
40
41
	/** @var \blitze\sitemaker\services\menus\navigation */
42
	protected $navigation;
43
44
	/**
45
	 * Constructor
46
	 *
47
	 * @param \phpbb\cache\driver\driver_interface			$cache				Cache driver interface
48
	 * @param \phpbb\config\config							$config				Config object
49
	 * @param \phpbb\controller\helper						$controller_helper	Controller Helper object
50
	 * @param \phpbb\template\template						$template			Template object
51
	 * @param \phpbb\language\language						$translator			Language object
52 8
	 * @param \phpbb\user									$user				User object
53
	 * @param \blitze\sitemaker\services\util				$util				Sitemaker utility object
54 8
	 * @param \blitze\sitemaker\services\blocks\display		$blocks				Blocks display object
55 8
	 * @param \blitze\sitemaker\services\menus\navigation	$navigation			Sitemaker navigation object
56 8
	 */
57 8
	public function __construct(\phpbb\cache\driver\driver_interface $cache, \phpbb\config\config $config, \phpbb\controller\helper $controller_helper, \phpbb\template\template $template, \phpbb\language\language $translator, \phpbb\user $user, \blitze\sitemaker\services\util $util, \blitze\sitemaker\services\blocks\display $blocks, \blitze\sitemaker\services\menus\navigation $navigation)
58 8
	{
59 8
		$this->cache = $cache;
60 8
		$this->config = $config;
61 8
		$this->controller_helper = $controller_helper;
62 8
		$this->template = $template;
63
		$this->translator = $translator;
64
		$this->user = $user;
65
		$this->util = $util;
66
		$this->blocks = $blocks;
67 1
		$this->navigation = $navigation;
68
	}
69
70 1
	/**
71 1
	 * @return array
72 1
	 */
73 1
	public static function getSubscribedEvents()
74 1
	{
75 1
		return array(
76
			'core.page_footer'			=> 'show_sitemaker',
77
			'core.adm_page_footer'		=> 'set_assets',
78
			'core.submit_post_end'		=> 'clear_cached_queries',
79
			'core.delete_posts_after'	=> 'clear_cached_queries',
80
			'core.display_forums_modify_sql'	=> 'hide_hidden_forums',
81
		);
82 4
	}
83
84 4
	/**
85 4
	 * Show sitemaker blocks on front page
86
	 * @return void
87 4
	 */
88 4
	public function show_sitemaker()
89 2
	{
90 2
		$this->blocks->show();
91
		$this->show_hide_index_blocks();
92 4
93 4
		[$style_name] = $this->template->get_user_style();
94
		$navbar = $this->navigation->get_settings($style_name);
95
96
		if ($this->config['sm_navbar_menu'] && $navbar['location'])
97
		{
98
			$this->template->assign_vars(array_merge(
99 4
				array(
100
					'STYLE_NAME'		=> $style_name,
101 4
					'NAVBAR_LOCATION'	=> $navbar['location'],
102 4
					'NAVBAR_CSS'		=> $this->controller_helper->route('blitze_sitemaker_navbar_css', array(
103
						'style'	=> $style_name,
104
						'hash'	=> $navbar['modified']
105
					)),
106
				),
107
				$this->navigation->build_menu($this->config['sm_navbar_menu'], true)
0 ignored issues
show
Bug introduced by
$this->config['sm_navbar_menu'] of type string is incompatible with the type integer expected by parameter $menu_id of blitze\sitemaker\service...avigation::build_menu(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

107
				$this->navigation->build_menu(/** @scrutinizer ignore-type */ $this->config['sm_navbar_menu'], true)
Loading history...
108
			));
109
		}
110 1
111
		$this->set_assets();
112 1
	}
113 1
114 1
	/**
115
	 * Send assets to template
116
	 * @return void
117
	 */
118
	public function set_assets()
119
	{
120 2
		$this->util->set_assets();
121
	}
122 2
123
	/**
124 2
	 * Queries for forum data are cached unless a post is created/edited
125 2
	 * The defined constant is used as an indicator of this change so a new request is made instead
126
	 * @see \blitze\sitemaker\services\forum\data
127 2
	 * @return void
128 2
	 */
129
	public function clear_cached_queries()
130
	{
131
		define('SITEMAKER_FORUM_CHANGED', true);
132
		$this->cache->destroy('sql', array(FORUMS_TABLE, TOPICS_TABLE, POSTS_TABLE, USERS_TABLE));
133
	}
134 4
135
	/**
136 4
	 * @param \phpbb\event\data $event
137 4
	 * @return void
138 4
	 */
139
	public function hide_hidden_forums(\phpbb\event\data $event)
140 4
	{
141 4
		$sql_ary = $event['sql_ary'];
142 2
143 2
		$sql_ary['WHERE'] .= ($sql_ary['WHERE']) ? ' AND ' : '';
144 2
		$sql_ary['WHERE'] .= 'f.hidden_forum <> 1';
145
146 4
		$event['sql_ary'] = $sql_ary;
147 4
	}
148 4
149 4
	/**
150 4
	 * Show or hide birthday_list, online users list, and login box on forum index
151 4
	 * @return void
152
	 */
153
	protected function show_hide_index_blocks()
154
	{
155
		$hide_login = (bool) $this->config['sm_hide_login'];
156
		$hide_online = (bool) $this->config['sm_hide_online'];
157
		$hide_birthday = (bool) $this->config['sm_hide_birthday'];
158
159
		if ($this->config['sitemaker_startpage_controller'])
160
		{
161
			$hide_online = $hide_birthday = true;
162
			$this->template->assign_var('L_INDEX', $this->translator->lang('HOME'));
163
		}
164
165
		$this->template->assign_vars(array(
166
			'S_USER_LOGGED_IN'			=> ($hide_login || $this->user->data['is_registered']),
167
			'S_DISPLAY_ONLINE_LIST'		=> !$hide_online,
168
			'S_DISPLAY_BIRTHDAY_LIST'	=> !$hide_birthday,
169
		));
170
	}
171
}
172