Completed
Push — develop ( 86b038...fd19b8 )
by Daniel
09:51
created

sitemaker::getSubscribedEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
crap 1
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\event;
11
12
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
13
14
class sitemaker implements EventSubscriberInterface
15
{
16
	/** @var \phpbb\cache\driver\driver_interface */
17
	protected $cache;
18
19
	/** @var \phpbb\config\config */
20
	protected $config;
21
22
	/** @var \phpbb\template\template */
23
	protected $template;
24
25
	/** @var \phpbb\language\language */
26
	protected $translator;
27
28
	/** @var \phpbb\user */
29
	protected $user;
30
31
	/* @var \blitze\sitemaker\services\util */
32
	protected $util;
33
34
	/* @var \blitze\sitemaker\services\blocks\display */
35
	protected $blocks;
36
37
	/** @var \blitze\sitemaker\services\menus\navigation */
38
	protected $navigation;
39
40
	/**
41
	 * Constructor
42
	 *
43
	 * @param \phpbb\cache\driver\driver_interface			$cache				Cache driver interface
44
	 * @param \phpbb\config\config							$config				Config object
45
	 * @param \phpbb\template\template						$template			Template object
46
	 * @param \phpbb\language\language						$translator			Language object
47
	 * @param \phpbb\user									$user				User object
48
	 * @param \blitze\sitemaker\services\util				$util				Sitemaker utility object
49
	 * @param \blitze\sitemaker\services\blocks\display		$blocks				Blocks display object
50
	 * @param \blitze\sitemaker\services\menus\navigation	$navigation			Sitemaker navigation object
51
	 */
52 8
	public function __construct(\phpbb\cache\driver\driver_interface $cache, \phpbb\config\config $config, \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)
53
	{
54 8
		$this->cache = $cache;
55 8
		$this->config = $config;
56 8
		$this->template = $template;
57 8
		$this->translator = $translator;
58 8
		$this->user = $user;
59 8
		$this->util = $util;
60 8
		$this->blocks = $blocks;
61 8
		$this->navigation = $navigation;
62 8
	}
63
64
	/**
65
	 * @return array
66
	 */
67 1
	public static function getSubscribedEvents()
68
	{
69
		return array(
70 1
			'core.page_footer'			=> 'show_sitemaker',
71 1
			'core.adm_page_footer'		=> 'set_assets',
72 1
			'core.submit_post_end'		=> 'clear_cached_queries',
73 1
			'core.delete_posts_after'	=> 'clear_cached_queries',
74 1
			'core.display_forums_modify_sql'	=> 'hide_hidden_forums',
75 1
		);
76
	}
77
78
	/**
79
	 * Show sitemaker blocks on front page
80
	 * @return void
81
	 */
82 4
	public function show_sitemaker()
83
	{
84 4
		$this->blocks->show();
85 4
		$this->show_hide_index_blocks();
86
87 4
		if ($this->config['sm_navbar_menu'])
88 4
		{
89 2
			$this->navigation->build_menu($this->template, $this->config['sm_navbar_menu']);
90 2
		}
91
92 4
		$this->set_assets();
93 4
	}
94
95
	/**
96
	 * Send assets to template
97
	 * @return void
98
	 */
99 4
	public function set_assets()
100
	{
101 4
		$this->util->set_assets();
102 4
	}
103
104
	/**
105
	 * Queries for forum data are cached unless a post is created/edited
106
	 * The defined constant is used as an indicator of this change so a new request is made instead
107
	 * @see \blitze\sitemaker\services\forum\data
108
	 * @return void
109
	 */
110 1
	public function clear_cached_queries()
111
	{
112 1
		define('SITEMAKER_FORUM_CHANGED', true);
113 1
		$this->cache->destroy('sql', array(FORUMS_TABLE, TOPICS_TABLE, POSTS_TABLE, USERS_TABLE));
114 1
	}
115
116
	/**
117
	 * @param \phpbb\event\data $event
118
	 * @return void
119
	 */
120 2
	public function hide_hidden_forums(\phpbb\event\data $event)
121
	{
122 2
		$sql_ary = $event['sql_ary'];
123
124 2
		$sql_ary['WHERE'] .= ($sql_ary['WHERE']) ? ' AND ' : '';
125 2
		$sql_ary['WHERE'] .= 'f.hidden_forum <> 1';
126
127 2
		$event['sql_ary'] = $sql_ary;
128 2
	}
129
130
	/**
131
	 * Show or hide birthday_list, online users list, and login box on forum index
132
	 * @return void
133
	 */
134 4
	protected function show_hide_index_blocks()
135
	{
136 4
		$hide_login = (bool) $this->config['sm_hide_login'];
137 4
		$hide_online = (bool) $this->config['sm_hide_online'];
138 4
		$hide_birthday = (bool) $this->config['sm_hide_birthday'];
139
140 4
		if ($this->config['sitemaker_startpage_controller'])
141 4
		{
142 2
			$hide_online = $hide_birthday = true;
143 2
			$this->template->assign_var('L_INDEX', $this->translator->lang('HOME'));
144 2
		}
145
146 4
		$this->template->assign_vars(array(
147 4
			'S_USER_LOGGED_IN'			=> ($hide_login || $this->user->data['is_registered']),
148 4
			'S_DISPLAY_ONLINE_LIST'		=> !$hide_online,
149 4
			'S_DISPLAY_BIRTHDAY_LIST'	=> !$hide_birthday,
150 4
		));
151 4
	}
152
}
153