Passed
Push — development ( 69387f...a254f4 )
by Spuds
01:03 queued 20s
created

template_memberlist()   C

Complexity

Conditions 14
Paths 84

Size

Total Lines 118
Code Lines 50

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 14
eloc 50
c 0
b 0
f 0
nc 84
nop 0
dl 0
loc 118
rs 6.2666

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * @package   ElkArte Forum
5
 * @copyright ElkArte Forum contributors
6
 * @license   BSD http://opensource.org/licenses/BSD-3-Clause (see accompanying LICENSE.txt file)
7
 *
8
 * This file contains code covered by:
9
 * copyright: 2011 Simple Machines (http://www.simplemachines.org)
10
 *
11
 * @version 2.0 Beta 1
12
 *
13
 */
14
15
/**
16
 * Memberlist search form
17
 */
18
function template_mlsearch_above()
19
{
20
	global $context, $txt;
21
22
	$extra = '
23
	<form id="mlsearch" action="' . getUrl('action', ['action' => 'memberlist', 'sa' => 'search']) . '" method="post" accept-charset="UTF-8">
24
		<ul>
25
			<li>
26
				<input id="mlsearch_input" class="input_text" onfocus="toggle_mlsearch_opt();" type="text" name="search" autocomplete="off" value="' . $context['old_search_value'] . '" placeholder="' . $txt['mlist_search'] . '" />
27
				<button type="submit" name="search2" class="with_select"><i class="icon i-search"></i></button>
28
				<ul id="mlsearch_options" class="nojs">';
29
30
	foreach ($context['search_fields'] as $id => $title)
31
	{
32
		$extra .= '
33
					<li class="mlsearch_option">
34
						<label for="fields-' . $id . '">
35
							<input type="checkbox" name="fields[]" id="fields-' . $id . '" value="' . $id . '" ' . (in_array($id, $context['search_defaults']) ? 'checked="checked"' : '') . ' />' . $title . '
36
						</label>
37
					</li>';
38
	}
39
40
	$extra .= '
41
				</ul>
42
			</li>
43
		</ul>
44
	</form>';
45
46
	template_pagesection('memberlist_buttons', 'right', ['extra' => $extra]);
47
48
	echo '
49
	<script type="module">
50
		// Removes the nojs class to properly style the dropdown according to js availability
51
		document.getElementById("mlsearch_options").classList.remove("nojs");
52
	</script>';
53
}
54
55
/**
56
 * Displays a sortable listing of all members registered on the forum.
57
 */
58
function template_memberlist()
59
{
60
	global $context, $txt;
61
62
	echo '
63
	<div id="memberlist">
64
		<h2 class="category_header">
65
			<span class="floatleft">', $txt['members_list'], '</span>';
66
67
	if (!empty($context['letter_links']))
68
	{
69
		echo '
70
				<span class="floatright letter_links">', $context['letter_links'], '</span>';
71
	}
72
73
	echo '
74
		</h2>
75
		<div class="mlist_container">
76
			<ul class="mlist">
77
				<li class="mlist_header">';
78
79
	// Display each of the column headers of the table.
80
	foreach ($context['columns'] as $key => $column)
81
	{
82
		$sorticon = match ($key)
83
		{
84
			'posts', 'date_registered' => 'numeric',
85
			default => 'alpha',
86
		};
87
88
		// This is a selected column, so underline it or some such.
89
		if ($column['selected'])
90
		{
91
			echo '
92
					<div class="' . $column['class'] . '">
93
						<a href="' . $column['href'] . '">' . $column['label'] . '<i class="icon icon-small i-sort-' . $sorticon . '-' . $context['sort_direction'] . '"></i></a>
94
					</div>';
95
		}
96
		// This is just some column... show the link and be done with it.
97
		else
98
		{
99
			echo '
100
					<div class="' . $column['class'] . '">
101
						', $column['link'], '
102
					</div>';
103
		}
104
	}
105
106
	echo '
107
				</li>';
108
109
	// Assuming there are members loop through each one displaying their data.
110
	$alternate = true;
111
	if (!empty($context['members']))
112
	{
113
		foreach ($context['members'] as $member)
114
		{
115
			if (!empty($member['sort_letter']))
116
			{
117
				echo '
118
			<li class="letter_row" id="letter', $member['sort_letter'], '">
119
				<h3>', $member['sort_letter'], '</h3>
120
			</li>';
121
			}
122
123
			echo '
124
				<li class="', $alternate ? 'alternate_' : 'standard_', 'row">';
125
126
			foreach ($context['columns'] as $column => $values)
127
			{
128
				if (isset($member[$column]))
129
				{
130
					echo '
131
					<div class="' . $values['class'] . '">';
132
133
					if ($column === 'online')
134
					{
135
						echo template_member_online($member);
136
					}
137
					elseif ($column === 'email_address')
138
					{
139
						echo template_member_email($member);
140
					}
141
					else
142
					{
143
						echo '
144
					', $member[$column];
145
					}
146
147
					echo '
148
					</div>';
149
				}
150
				// Any custom fields on display?
151
				elseif (!empty($context['custom_profile_fields']['columns']) && isset($context['custom_profile_fields']['columns'][$column]))
152
				{
153
					echo '
154
					<div class="' . $values['class'] . '">', $member['options'][substr($column, 5)], '</div>';
155
				}
156
			}
157
158
			echo '
159
				</li>';
160
161
			$alternate = !$alternate;
0 ignored issues
show
introduced by
The condition $alternate is always true.
Loading history...
162
		}
163
164
		echo '
165
			</ul>
166
		</div>';
167
	}
168
	// No members?
169
	else
170
	{
171
		echo '
172
			</ul>
173
		</div>
174
		<div class="infobox">
175
			', $txt['find_no_results'], '
176
		</div>';
177
	}
178
}
179
180
/**
181
 * Shows the pagination
182
 */
183
function template_mlsearch_below()
184
{
185
	// Show the page numbers again. (makes 'em easier to find!)
186
	template_pagesection();
187
188
	echo '
189
	</div>';
190
}
191