| Conditions | 7 |
| Paths | 12 |
| Total Lines | 99 |
| Code Lines | 48 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
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:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 47 | public function setup($parameters, $id) |
||
| 48 | { |
||
| 49 | global $scripturl; |
||
| 50 | |||
| 51 | require_once(SUBSDIR . '/Members.subs.php'); |
||
| 52 | |||
| 53 | // Including local board moderators |
||
| 54 | if (empty($parameters['lmod'])) |
||
| 55 | { |
||
| 56 | $request = $this->_db->query('', ' |
||
| 57 | SELECT |
||
| 58 | id_member |
||
| 59 | FROM {db_prefix}moderators', |
||
| 60 | array() |
||
| 61 | ); |
||
| 62 | $local_mods = array(); |
||
| 63 | while ($row = $this->_db->fetch_assoc($request)) |
||
| 64 | { |
||
| 65 | $local_mods[$row['id_member']] = $row['id_member']; |
||
| 66 | } |
||
| 67 | $this->_db->free_result($request); |
||
| 68 | |||
| 69 | if (count($local_mods) > 10) |
||
| 70 | { |
||
| 71 | $local_mods = array(); |
||
| 72 | } |
||
| 73 | } |
||
| 74 | else |
||
| 75 | { |
||
| 76 | $local_mods = array(); |
||
| 77 | } |
||
| 78 | |||
| 79 | // Admins and global moderator list |
||
| 80 | $global_mods = membersAllowedTo('moderate_board', 0); |
||
| 81 | $admins = membersAllowedTo('admin_forum'); |
||
| 82 | |||
| 83 | // You only get one listing, highest authority |
||
| 84 | $all_staff = array_merge($local_mods, $global_mods, $admins); |
||
| 85 | $all_staff = array_unique($all_staff); |
||
| 86 | |||
| 87 | $request = $this->_db->query('', ' |
||
| 88 | SELECT |
||
| 89 | m.id_member, m.real_name, m.avatar, m.email_address, |
||
| 90 | mg.group_name, |
||
| 91 | a.id_attach, a.attachment_type, a.filename |
||
| 92 | FROM {db_prefix}members AS m |
||
| 93 | LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = m.id_member) |
||
| 94 | LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = CASE WHEN m.id_group = {int:reg_group_id} THEN m.id_post_group ELSE m.id_group END) |
||
| 95 | WHERE m.id_member IN ({array_int:staff_list})', |
||
| 96 | array( |
||
| 97 | 'staff_list' => $all_staff, |
||
| 98 | 'reg_group_id' => 0, |
||
| 99 | ) |
||
| 100 | ); |
||
| 101 | $this->data['staff_list'] = array(); |
||
| 102 | while ($row = $this->_db->fetch_assoc($request)) |
||
| 103 | { |
||
| 104 | $this->color_ids[$row['id_member']] = $row['id_member']; |
||
| 105 | |||
| 106 | if (in_array($row['id_member'], $admins)) |
||
| 107 | { |
||
| 108 | $row['type'] = 1; |
||
| 109 | } |
||
| 110 | elseif (in_array($row['id_member'], $global_mods)) |
||
| 111 | { |
||
| 112 | $row['type'] = 2; |
||
| 113 | } |
||
| 114 | else |
||
| 115 | { |
||
| 116 | $row['type'] = 3; |
||
| 117 | } |
||
| 118 | |||
| 119 | $this->data['staff_list'][$row['type'] . '-' . $row['id_member']] = array( |
||
| 120 | 'id' => $row['id_member'], |
||
| 121 | 'name' => $row['real_name'], |
||
| 122 | 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>', |
||
| 123 | 'group' => $row['group_name'], |
||
| 124 | 'type' => $row['type'], |
||
| 125 | 'avatar' => determineAvatar(array( |
||
| 126 | 'avatar' => $row['avatar'], |
||
| 127 | 'filename' => $row['filename'], |
||
| 128 | 'id_attach' => $row['id_attach'], |
||
| 129 | 'email_address' => $row['email_address'], |
||
| 130 | 'attachment_type' => $row['attachment_type'], |
||
| 131 | )), |
||
| 132 | ); |
||
| 133 | } |
||
| 134 | $this->_db->free_result($request); |
||
| 135 | |||
| 136 | // Get this in an order or importance |
||
| 137 | ksort($this->data['staff_list']); |
||
| 138 | $this->data['staff_count'] = count($this->data['staff_list']); |
||
| 139 | $this->data['icons'] = array(1 => 'admin', 'gmod', 'lmod'); |
||
| 140 | |||
| 141 | // Color ID's |
||
| 142 | $this->_color_ids(); |
||
| 143 | |||
| 144 | // How we will display the data |
||
| 145 | $this->setTemplate('template_sp_staff'); |
||
| 146 | } |
||
| 199 |