| Conditions | 56 |
| Paths | > 20000 |
| Total Lines | 215 |
| Code Lines | 87 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 20 | function template_show_list($list_id = null) |
||
| 21 | { |
||
| 22 | global $context, $txt; |
||
| 23 | |||
| 24 | // Get a shortcut to the current list. |
||
| 25 | $list_id = $list_id ?? $context['default_list']; |
||
| 26 | $cur_list = &$context[$list_id]; |
||
| 27 | |||
| 28 | if (isset($cur_list['form'])) |
||
| 29 | { |
||
| 30 | echo ' |
||
| 31 | <form class="generic_list_wrapper" action="', $cur_list['form']['href'], '" method="post"', empty($cur_list['form']['name']) ? '' : ' name="' . $cur_list['form']['name'] . '" id="' . $cur_list['form']['name'] . '"', ' accept-charset="UTF-8"> |
||
| 32 | <div class="generic_list">'; |
||
| 33 | } |
||
| 34 | else |
||
| 35 | { |
||
| 36 | echo ' |
||
| 37 | <div id="wrapper_', $list_id, '" class="generic_list_wrapper">'; |
||
| 38 | } |
||
| 39 | |||
| 40 | // Show the title of the table (if any), with an icon (if defined) |
||
| 41 | if (!empty($cur_list['title'])) |
||
| 42 | { |
||
| 43 | echo ' |
||
| 44 | <h2 class="category_header', empty($cur_list['icon']) ? '' : ' hdicon ' . $cur_list['icon'], '">', $cur_list['title'], '</h2>'; |
||
| 45 | } |
||
| 46 | |||
| 47 | // Show any data right after the title |
||
| 48 | if (isset($cur_list['additional_rows']['after_title'])) |
||
| 49 | { |
||
| 50 | echo ' |
||
| 51 | <div class="information flow_hidden">'; |
||
| 52 | |||
| 53 | template_additional_rows('after_title', $cur_list); |
||
|
|
|||
| 54 | |||
| 55 | echo ' |
||
| 56 | </div>'; |
||
| 57 | } |
||
| 58 | |||
| 59 | // Show some data above this list |
||
| 60 | if (isset($cur_list['additional_rows']['top_of_list'])) |
||
| 61 | { |
||
| 62 | template_additional_rows('top_of_list', $cur_list); |
||
| 63 | } |
||
| 64 | |||
| 65 | $close_div = false; |
||
| 66 | if (isset($cur_list['additional_rows']['above_column_headers'])) |
||
| 67 | { |
||
| 68 | $close_div = true; |
||
| 69 | echo ' |
||
| 70 | <div class="flow_flex">', template_additional_rows('above_column_headers', $cur_list); |
||
| 71 | } |
||
| 72 | |||
| 73 | // These are the main tabs that is used all around the template. |
||
| 74 | if (isset($cur_list['list_menu']['show_on']) && ($cur_list['list_menu']['show_on'] === 'both' || $cur_list['list_menu']['show_on'] === 'top')) |
||
| 75 | { |
||
| 76 | if (!$close_div) |
||
| 77 | { |
||
| 78 | echo ' |
||
| 79 | <div class="flow_flex">'; |
||
| 80 | } |
||
| 81 | |||
| 82 | $close_div = true; |
||
| 83 | |||
| 84 | template_create_list_menu($cur_list['list_menu']); |
||
| 85 | |||
| 86 | // Menu buttons and additional buttons are on the same line, leaving no room for the index |
||
| 87 | if (isset($cur_list['additional_rows']['above_column_headers'])) |
||
| 88 | { |
||
| 89 | $page_index_new_line = true; |
||
| 90 | } |
||
| 91 | } |
||
| 92 | |||
| 93 | // Show the page index (if this list doesn't intend to show all items). |
||
| 94 | if (!empty($cur_list['items_per_page']) && !empty($cur_list['page_index'])) |
||
| 95 | { |
||
| 96 | if (!$close_div || isset($page_index_new_line)) |
||
| 97 | { |
||
| 98 | echo (isset($page_index_new_line) ? ' |
||
| 99 | </div>' : '') . ' |
||
| 100 | <div class="flow_flex">'; |
||
| 101 | } |
||
| 102 | |||
| 103 | template_pagesection(false, '', ['page_index_markup' => $cur_list['page_index']]); |
||
| 104 | $close_div = true; |
||
| 105 | } |
||
| 106 | |||
| 107 | if ($close_div) |
||
| 108 | { |
||
| 109 | echo ' |
||
| 110 | </div>'; |
||
| 111 | } |
||
| 112 | |||
| 113 | // Start of the main table |
||
| 114 | echo ' |
||
| 115 | <table id="' . $list_id . '" class="table_grid"', empty($cur_list['width']) ? '' : ' style="width: ' . $cur_list['width'] . '"', '>'; |
||
| 116 | |||
| 117 | // Show the column headers. |
||
| 118 | $header_count = count($cur_list['headers']); |
||
| 119 | if (!($header_count < 2 && empty($cur_list['headers'][0]['label']))) |
||
| 120 | { |
||
| 121 | echo ' |
||
| 122 | <thead> |
||
| 123 | <tr class="table_head">'; |
||
| 124 | |||
| 125 | // Loop through each column and add a table header. |
||
| 126 | $i = 0; |
||
| 127 | foreach ($cur_list['headers'] as $col_header) |
||
| 128 | { |
||
| 129 | $i++; |
||
| 130 | if ($i === 1) |
||
| 131 | { |
||
| 132 | $col_header['class'] = empty($col_header['class']) ? '' : $col_header['class']; |
||
| 133 | } |
||
| 134 | elseif ($i === $header_count) |
||
| 135 | { |
||
| 136 | $col_header['class'] = empty($col_header['class']) ? '' : $col_header['class']; |
||
| 137 | } |
||
| 138 | |||
| 139 | $sort_title = $col_header['sort_image'] === 'up' ? $txt['sort_desc'] : $txt['sort_asc']; |
||
| 140 | |||
| 141 | echo ' |
||
| 142 | <th scope="col" id="header_', $list_id, '_', $col_header['id'], '"', empty($col_header['class']) ? '' : ' class="' . $col_header['class'] . '"', empty($col_header['style']) ? '' : ' style="' . $col_header['style'] . '"', empty($col_header['colspan']) ? '' : ' colspan="' . $col_header['colspan'] . '"', '>', empty($col_header['href']) ? '' : '<a href="' . $col_header['href'] . '" rel="nofollow">', empty($col_header['label']) ? ' ' : $col_header['label'], empty($col_header['href']) ? '' : (empty($col_header['sort_image']) ? '</a>' : ' <i class="sort icon i-sort-amount-' . $col_header['sort_image'] . '" title="' . $sort_title . '"></i></a>'), '</th>'; |
||
| 143 | } |
||
| 144 | |||
| 145 | echo ' |
||
| 146 | </tr> |
||
| 147 | </thead>'; |
||
| 148 | } |
||
| 149 | |||
| 150 | echo ' |
||
| 151 | <tbody', empty($cur_list['sortable']) ? '' : ' id="table_grid_sortable"', '>'; |
||
| 152 | |||
| 153 | // Show a nice message informing there are no items in this list. |
||
| 154 | if (empty($cur_list['rows']) && !empty($cur_list['no_items_label'])) |
||
| 155 | { |
||
| 156 | echo ' |
||
| 157 | <tr> |
||
| 158 | <td colspan="', $cur_list['num_columns'], '"> |
||
| 159 | <div class="', empty($cur_list['no_items_align']) ? 'centertext' : $cur_list['no_items_align'], '">', $cur_list['no_items_label'], '</div> |
||
| 160 | </td> |
||
| 161 | </tr>'; |
||
| 162 | } |
||
| 163 | |||
| 164 | // Show the list rows. |
||
| 165 | elseif (!empty($cur_list['rows'])) |
||
| 166 | { |
||
| 167 | foreach ($cur_list['rows'] as $id => $row) |
||
| 168 | { |
||
| 169 | echo ' |
||
| 170 | <tr class="standard_row ', $row['class'], '" id="list_', $list_id, '_', str_replace(' ', '_', $id), '">'; |
||
| 171 | |||
| 172 | foreach ($row['data'] as $row_data) |
||
| 173 | { |
||
| 174 | echo ' |
||
| 175 | <td', empty($row_data['class']) ? '' : ' class="' . $row_data['class'] . '"', empty($row_data['style']) ? '' : ' style="' . $row_data['style'] . '"', '>', $row_data['value'], '</td>'; |
||
| 176 | } |
||
| 177 | |||
| 178 | echo ' |
||
| 179 | </tr>'; |
||
| 180 | } |
||
| 181 | } |
||
| 182 | |||
| 183 | echo ' |
||
| 184 | </tbody> |
||
| 185 | </table>'; |
||
| 186 | |||
| 187 | echo ' |
||
| 188 | <div class="flow_flex">'; |
||
| 189 | |||
| 190 | // Do we have multiple pages to show or data to show below the table |
||
| 191 | if ((!empty($cur_list['items_per_page']) && !empty($cur_list['page_index'])) || isset($cur_list['additional_rows']['below_table_data'])) |
||
| 192 | { |
||
| 193 | // Show the page index (if this list doesn't intend to show all items). |
||
| 194 | if (!empty($cur_list['items_per_page']) && !empty($cur_list['page_index'])) |
||
| 195 | { |
||
| 196 | template_pagesection(false, '', ['page_index_markup' => $cur_list['page_index']]); |
||
| 197 | } |
||
| 198 | |||
| 199 | if (isset($cur_list['additional_rows']['below_table_data'])) |
||
| 200 | { |
||
| 201 | template_additional_rows('below_table_data', $cur_list); |
||
| 202 | } |
||
| 203 | } |
||
| 204 | |||
| 205 | // Tabs at the bottom. Usually bottom aligned. |
||
| 206 | if (isset($cur_list['list_menu']['show_on']) && ($cur_list['list_menu']['show_on'] === 'both' || $cur_list['list_menu']['show_on'] === 'bottom')) |
||
| 207 | { |
||
| 208 | template_create_list_menu($cur_list['list_menu']); |
||
| 209 | } |
||
| 210 | |||
| 211 | echo ' |
||
| 212 | </div>'; |
||
| 213 | |||
| 214 | // Last chance to show more data, like buttons and links |
||
| 215 | if (isset($cur_list['additional_rows']['bottom_of_list'])) |
||
| 216 | { |
||
| 217 | template_additional_rows('bottom_of_list', $cur_list); |
||
| 218 | } |
||
| 219 | |||
| 220 | if (isset($cur_list['form'])) |
||
| 221 | { |
||
| 222 | foreach ($cur_list['form']['hidden_fields'] as $name => $value) |
||
| 223 | { |
||
| 224 | echo ' |
||
| 225 | <input type="hidden" name="', $name, '" value="', $value, '" />'; |
||
| 226 | } |
||
| 227 | |||
| 228 | echo ' |
||
| 229 | </div> |
||
| 230 | </form>'; |
||
| 231 | } |
||
| 232 | else |
||
| 233 | { |
||
| 234 | echo ' |
||
| 235 | </div>'; |
||
| 295 |