memberlist_listener   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
dl 0
loc 64
rs 10
c 1
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A mas_memberlist_team_template() 0 20 2
A getSubscribedEvents() 0 4 1
1
<?php
2
/**
3
 *
4
 * Member Avatar & Status [MAS]. An extension for the phpBB Forum Software package.
5
 *
6
 * @copyright (c) 2018-forever, Dark❶ [dark1]
7
 * @license GNU General Public License, version 2 (GPL-2.0-only)
8
 *
9
 */
10
11
namespace dark1\memberavatarstatus\event;
12
13
/**
14
 * @ignore
15
 */
16
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
17
use dark1\memberavatarstatus\core\avatar;
18
use dark1\memberavatarstatus\core\status;
19
20
/**
21
 * Member Avatar & Status Event listener.
22
 */
23
class memberlist_listener implements EventSubscriberInterface
24
{
25
	/** @var avatar*/
26
	protected $avatar;
27
28
	/** @var status*/
29
	protected $status;
30
31
	/**
32
	 * Constructor for listener
33
	 *
34
	 * @param avatar	$avatar		dark1 avatar
35
	 * @param status	$status		dark1 status
36
	 * @access public
37
	 */
38
	public function __construct(avatar $avatar, status $status)
39
	{
40
		$this->avatar	= $avatar;
41
		$this->status	= $status;
42
	}
43
44
	/**
45
	 * Assign functions defined in this class to event listeners in the core
46
	 *
47
	 * @return array
48
	 * @static
49
	 * @access public
50
	 */
51
	static public function getSubscribedEvents()
52
	{
53
		return [
54
			'core.memberlist_team_modify_template_vars'		=> 'mas_memberlist_team_template',
55
		];
56
	}
57
58
59
60
	/**
61
	 * MAS MemberList Team Template Setup
62
	 *
63
	 * @param object $event The event object
64
	 * @return null
65
	 * @access public
66
	 */
67
	public function mas_memberlist_team_template($event)
68
	{
69
		// Get Event Array `row` & `template_vars`
70
		$row = $event['row'];
71
		$template_vars = $event['template_vars'];
72
73
		// Set Avatar
74
		$avatar = $this->avatar->mas_get_avatar('dark1_mas_ml', $row['user_id']);
75
76
		// Get Online Status
77
		$online = (!($row['user_type'] == USER_INACTIVE)) ? $this->status->mas_get_online('dark1_mas_ml', $row['user_id']) : '';
78
79
		// Add Avatar & Online Status to template_vars
80
		$template_vars = array_merge($template_vars, [
81
			'AVATAR_IMG'	=> $avatar,
82
			'S_ONLINE'		=> $online,
83
		]);
84
85
		// Assign template_vars to event -> template_vars
86
		$event['template_vars'] = $template_vars;
87
	}
88
89
}
90