Completed
Push — develop-3.2.x ( 86239d...17b6f9 )
by Matt
05:09 queued 02:36
created

listener::getSubscribedEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
/**
3
*
4
* Precise Similar Topics
5
*
6
* @copyright (c) 2013 Matt Friedman
7
* @license GNU General Public License, version 2 (GPL-2.0)
8
*
9
*/
10
11
namespace vse\similartopics\event;
12
13
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
14
15
/**
16
* Event listener
17
*/
18
class listener implements EventSubscriberInterface
19
{
20
	/** @var \vse\similartopics\core\similar_topics */
21
	protected $similar_topics;
22
23
	/**
24
	* Constructor
25
	*
26
	* @param \vse\similartopics\core\similar_topics $similar_topics
27
	* @access public
28
	*/
29
	public function __construct(\vse\similartopics\core\similar_topics $similar_topics)
30
	{
31
		$this->similar_topics = $similar_topics;
32
	}
33
34
	/**
35
	* Assign functions defined in this class to event listeners in the core
36
	*
37
	* @return array
38
	* @static
39
	* @access public
40
	*/
41
	static public function getSubscribedEvents()
42
	{
43
		return array(
44
			'core.viewtopic_modify_page_title'		=> 'display_similar_topics',
45
			'core.permissions'						=> 'add_permissions',
46
		);
47
	}
48
49
	/**
50
	* Display similar topics
51
	*
52
	* @param object $event The event object
53
	* @return null
54
	* @access public
55
	*/
56
	public function display_similar_topics($event)
57
	{
58
		// Return early if no reason to display similar topics
59
		if (!$this->similar_topics->is_available() || !$this->similar_topics->forum_available($event['forum_id']))
60
		{
61
			return;
62
		}
63
64
		$this->similar_topics->display_similar_topics($event['topic_data']);
65
	}
66
67
	/**
68
	* Add custom permissions language variables
69
	*
70
	* @param object $event The event object
71
	* @return null
72
	* @access public
73
	*/
74
	public function add_permissions($event)
75
	{
76
		$permissions = $event['permissions'];
77
		$permissions['u_similar_topics'] = array('lang' => 'ACL_U_SIMILARTOPICS', 'cat' => 'misc');
78
		$event['permissions'] = $permissions;
79
	}
80
}
81