Passed
Push — master ( 57fe55...ece377 )
by Dark❶
02:17
created

support_listener::mas_similartopics_topic_query()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 13
rs 10
1
<?php
2
/**
3
 *
4
 * Member Avatar & Status [MAS]. An extension for the phpBB Forum Software package.
5
 *
6
 * @copyright (c) 2018-2020, Dark❶ [dark1]
7
 * @license GNU General Public License, version 2 (GPL-2.0-only)
8
 *
9
 */
10
11
namespace dark1\memberavatarstatus\event;
12
13
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
14
use dark1\memberavatarstatus\core\memberavatarstatus;
15
16
/**
17
 * Member Avatar & Status Support Other Extension Event listener.
18
 */
19
class support_listener implements EventSubscriberInterface
20
{
21
	/** @var \dark1\memberavatarstatus\core\memberavatarstatus */
22
	protected $mas;
23
24
	/**
25
	 * Constructor for listener
26
	 *
27
	 * @param \dark1\memberavatarstatus\core\memberavatarstatus		$mas	dark1 mas
28
	 * @access public
29
	 */
30
	public function __construct(memberavatarstatus $mas)
31
	{
32
		$this->mas		= $mas;
33
	}
34
35
	/**
36
	 * Assign functions defined in this class to event listeners in the core
37
	 *
38
	 * @return array
39
	 * @static
40
	 * @access public
41
	 */
42
	static public function getSubscribedEvents()
43
	{
44
		return array(
45
			'paybas.recenttopics.sql_pull_topics_data'	=> 'mas_recenttopics_topic_query',
46
			'paybas.recenttopics.modify_tpl_ary'		=> 'mas_recenttopics_topic_template',
47
			'vse.similartopics.get_topic_data'			=> 'mas_similartopics_topic_query',
48
			'vse.similartopics.modify_topicrow'			=> 'mas_similartopics_topic_template',
49
		);
50
	}
51
52
53
54
	/**
55
	 * MAS RecentTopics SQL Query Setup
56
	 *
57
	 * @param object $event The event object
58
	 * @return null
59
	 * @access public
60
	 */
61
	public function mas_recenttopics_topic_query($event)
62
	{
63
		// Get Event Array `sql_array`
64
		$sql_array = $event['sql_array'];
65
66
		// Add Query Details
67
		$sql_array = $this->mas->mas_avatar_sql_query($sql_array, 'dark1_mas_vf_fp', 't.topic_poster', 'ufp', 'topic_first_poster', '');
68
		$sql_array = $this->mas->mas_online_sql_query($sql_array, 'dark1_mas_vf_fp', 't.topic_poster', 'sfp', 'topic_first_poster', '');
69
		$sql_array = $this->mas->mas_avatar_sql_query($sql_array, 'dark1_mas_vf_lp', 't.topic_last_poster_id', 'ulp', 'topic_last_poster', '');
70
		$sql_array = $this->mas->mas_online_sql_query($sql_array, 'dark1_mas_vf_lp', 't.topic_last_poster_id', 'slp', 'topic_last_poster', '');
71
72
		// Assign sql_ary to event -> sql_array
73
		$event['sql_array'] = $sql_array;
74
	}
75
76
77
78
	/**
79
	 * MAS RecentTopics Template Setup
80
	 *
81
	 * @param object $event The event object
82
	 * @return null
83
	 * @access public
84
	 */
85
	public function mas_recenttopics_topic_template($event)
86
	{
87
		// Get Event Array `row` & `tpl_ary`
88
		$row = $event['row'];
89
		$tpl_ary = $event['tpl_ary'];
90
91
		// Get Both Avatar
92
		$avatar_first_poster = $this->mas->mas_get_avatar('dark1_mas_vf_fp', 'topic_first_poster', $row);
93
		$avatar_last_poster = $this->mas->mas_get_avatar('dark1_mas_vf_lp', 'topic_last_poster', $row);
94
95
		// Get Both Online Status
96
		$online_first_poster = $this->mas->mas_get_online('dark1_mas_vf_fp', 'topic_first_poster', $row);
97
		$online_last_poster = $this->mas->mas_get_online('dark1_mas_vf_lp', 'topic_last_poster', $row);
98
99
		// Add Both of Avatar & Online Status to tpl_ary
100
		$tpl_ary = array_merge(
101
			$tpl_ary,
102
			array(
103
				'TOPIC_AUTHOR_AVATAR_IMG'		=> $avatar_first_poster,
104
				'TOPIC_AUTHOR_S_ONLINE'			=> $online_first_poster,
105
				'LAST_POST_AUTHOR_AVATAR_IMG'	=> $avatar_last_poster,
106
				'LAST_POST_AUTHOR_S_ONLINE'		=> $online_last_poster,
107
			)
108
		);
109
110
		// Assign tpl_ary to event -> tpl_ary
111
		$event['tpl_ary'] = $tpl_ary;
112
	}
113
114
115
116
	/**
117
	 * MAS SimilarTopics SQL Query Setup
118
	 *
119
	 * @param object $event The event object
120
	 * @return null
121
	 * @access public
122
	 */
123
	public function mas_similartopics_topic_query($event)
124
	{
125
		// Get Event Array `sql_array`
126
		$sql_array = $event['sql_array'];
127
128
		// Add Query Details
129
		$sql_array = $this->mas->mas_avatar_sql_query($sql_array, 'dark1_mas_sh_fp', 't.topic_poster', 'ufp', 'topic_first_poster', '');
130
		$sql_array = $this->mas->mas_online_sql_query($sql_array, 'dark1_mas_sh_fp', 't.topic_poster', 'sfp', 'topic_first_poster', '');
131
		$sql_array = $this->mas->mas_avatar_sql_query($sql_array, 'dark1_mas_sh_lp', 't.topic_last_poster_id', 'ulp', 'topic_last_poster', '');
132
		$sql_array = $this->mas->mas_online_sql_query($sql_array, 'dark1_mas_sh_lp', 't.topic_last_poster_id', 'slp', 'topic_last_poster', '');
133
134
		// Assign sql_ary to event -> sql_array
135
		$event['sql_array'] = $sql_array;
136
	}
137
138
139
140
	/**
141
	 * MAS SimilarTopics Template Setup
142
	 *
143
	 * @param object $event The event object
144
	 * @return null
145
	 * @access public
146
	 */
147
	public function mas_similartopics_topic_template($event)
148
	{
149
		// Get Event Array `row` & `topic_row`
150
		$row = $event['row'];
151
		$topic_row = $event['topic_row'];
152
153
		// Get Both Avatar
154
		$avatar_first_poster = $this->mas->mas_get_avatar('dark1_mas_sh_fp', 'topic_first_poster', $row);
155
		$avatar_last_poster = $this->mas->mas_get_avatar('dark1_mas_sh_lp', 'topic_last_poster', $row);
156
157
		// Get Both Online Status
158
		$online_first_poster = $this->mas->mas_get_online('dark1_mas_sh_fp', 'topic_first_poster', $row);
159
		$online_last_poster = $this->mas->mas_get_online('dark1_mas_sh_lp', 'topic_last_poster', $row);
160
161
		// Add Both of Avatar & Online Status to topic_row
162
		$topic_row = array_merge(
163
			$topic_row,
164
			array(
165
				'TOPIC_AUTHOR_AVATAR_IMG'		=> $avatar_first_poster,
166
				'TOPIC_AUTHOR_S_ONLINE'			=> $online_first_poster,
167
				'LAST_POST_AUTHOR_AVATAR_IMG'	=> $avatar_last_poster,
168
				'LAST_POST_AUTHOR_S_ONLINE'		=> $online_last_poster,
169
			)
170
		);
171
172
		// Assign topic_row to event -> topic_row
173
		$event['topic_row'] = $topic_row;
174
	}
175
176
}
177