Latest_Member_Block::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 7
rs 10
c 1
b 0
f 0
1
<?php
2
3
/**
4
 * @package SimplePortal
5
 *
6
 * @author SimplePortal Team
7
 * @copyright 2015-2021 SimplePortal Team
8
 * @license BSD 3-clause
9
 * @version 1.0.0
10
 */
11
12
13
/**
14
 * Latest member block, shows name and join date for X latest members
15
 *
16
 * @param mixed[] $parameters
17
 *        'limit' => number of members to show
18
 * @param int $id - not used in this block
19
 * @param boolean $return_parameters if true returns the configuration options for the block
20
 */
21
class Latest_Member_Block extends SP_Abstract_Block
22
{
23
	protected $colorids = array();
24
25
	/**
26
	 * Constructor, used to define block parameters
27
	 *
28
	 * @param Database|null $db
29
	 */
30
	public function __construct($db = null)
31
	{
32
		$this->block_parameters = array(
33
			'limit' => 'int',
34
		);
35
36
		parent::__construct($db);
37
	}
38
39
	/**
40
	 * Initializes a block for use.
41
	 *
42
	 * - Called from portal.subs as part of the sportal_load_blocks process
43
	 *
44
	 * @param mixed[] $parameters
45
	 * @param int $id
46
	 */
47
	public function setup($parameters, $id)
48
	{
49
		global $scripturl;
50
51
		// Load in the latest members
52
		require_once(SUBSDIR . '/Members.subs.php');
53
		$limit = !empty($parameters['limit']) ? (int) $parameters['limit'] : 5;
54
		$rows = recentMembers($limit);
55
56
		// Get them ready the template
57
		$this->data['members'] = array();
58
59
		foreach ($rows as $row)
60
		{
61
			if (!empty($row['id_member']))
62
			{
63
				$this->colorids[$row['id_member']] = $row['id_member'];
64
			}
65
66
			$this->data['members'][] = array(
67
				'id' => $row['id_member'],
68
				'name' => $row['real_name'],
69
				'href' => $scripturl . '?action=profile;u=' . $row['id_member'],
70
				'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>',
71
				'date' => standardTime($row['date_registered'], '%d %b'),
72
			);
73
		}
74
75
		// Using member profile colors
76
		$this->_colorids();
77
78
		$this->setTemplate('template_sp_latestMember');
79
	}
80
81
	/**
82
	 * Provide the color profile id's
83
	 */
84
	private function _colorids()
85
	{
86
		global $color_profile;
87
88
		if (sp_loadColors($this->colorids) !== false)
0 ignored issues
show
introduced by
The condition sp_loadColors($this->colorids) !== false is always true.
Loading history...
89
		{
90
			foreach ($this->data['members'] as $k => $p)
91
			{
92
				if (!empty($color_profile[$p['id']]['link']))
93
				{
94
					$this->data['members'][$k]['link'] = $color_profile[$p['id']]['link'];
95
				}
96
			}
97
		}
98
	}
99
}
100
101
/**
102
 * Main template for this block
103
 *
104
 * @param mixed[] $data
105
 */
106
function template_sp_latestMember($data)
107
{
108
	global $txt;
109
110
	// No recent members, suppose it could happen
111
	if (empty($data['members']))
112
	{
113
		echo '
114
			', $txt['error_sp_no_members_found'];
115
116
		return;
117
	}
118
119
	echo '
120
			<ul class="sp_list">';
121
122
	foreach ($data['members'] as $member)
123
	{
124
		echo '
125
				<li ', sp_embed_class('dot'), '>', $member['link'], ' - <span class="smalltext">', $member['date'], '</span></li>';
126
	}
127
128
	echo '
129
			</ul>';
130
}
131