Conditions | 37 |
Paths | 4456 |
Total Lines | 214 |
Code Lines | 84 |
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 |
||
218 | function template_show_month_grid($grid_name) |
||
219 | { |
||
220 | global $context, $txt, $modSettings; |
||
221 | |||
222 | if (!isset($context['calendar_grid_' . $grid_name])) |
||
223 | { |
||
224 | return false; |
||
225 | } |
||
226 | |||
227 | $calendar_data = &$context['calendar_grid_' . $grid_name]; |
||
228 | |||
229 | if (empty($calendar_data['disable_title'])) |
||
230 | { |
||
231 | echo ' |
||
232 | <h2 class="category_header">'; |
||
233 | |||
234 | if (empty($calendar_data['previous_calendar']['disabled']) && $calendar_data['show_next_prev']) |
||
235 | { |
||
236 | echo ' |
||
237 | <a href="', $calendar_data['previous_calendar']['href'], '" class="previous_month"> |
||
238 | <i class="icon icon-lg i-chevron-circle-left"></i> |
||
239 | </a>'; |
||
240 | } |
||
241 | |||
242 | if (empty($calendar_data['next_calendar']['disabled']) && $calendar_data['show_next_prev']) |
||
243 | { |
||
244 | echo ' |
||
245 | <a href="', $calendar_data['next_calendar']['href'], '" class="next_month"> |
||
246 | <i class="icon icon-lg i-chevron-circle-right"></i> |
||
247 | </a>'; |
||
248 | } |
||
249 | |||
250 | if ($calendar_data['show_next_prev']) |
||
251 | { |
||
252 | echo ' |
||
253 | ', $txt['months_titles'][$calendar_data['current_month']], ' ', $calendar_data['current_year']; |
||
254 | } |
||
255 | else |
||
256 | { |
||
257 | echo ' |
||
258 | <a href="', getUrl('action', ['action' => 'calendar', 'year' => $calendar_data['current_year'], 'month' => $calendar_data['current_month']]), '"> |
||
259 | <i class="icon icon-small i-calendar"></i> ', $txt['months_titles'][$calendar_data['current_month']], ' ', $calendar_data['current_year'], ' |
||
260 | </a>'; |
||
261 | } |
||
262 | |||
263 | echo ' |
||
264 | </h2>'; |
||
265 | } |
||
266 | |||
267 | // Show the sidebar months |
||
268 | echo ' |
||
269 | <table class="calendar_table">'; |
||
270 | |||
271 | // Show each day of the week. |
||
272 | if (empty($calendar_data['disable_day_titles'])) |
||
273 | { |
||
274 | echo ' |
||
275 | <tr class="table_head">'; |
||
276 | |||
277 | if (!empty($calendar_data['show_week_links'])) |
||
278 | { |
||
279 | echo ' |
||
280 | <th> </th>'; |
||
281 | } |
||
282 | |||
283 | foreach ($calendar_data['week_days'] as $day) |
||
284 | { |
||
285 | echo ' |
||
286 | <th scope="col" class="days">', empty($calendar_data['short_day_titles']) ? ($txt['days'][$day]) : Util::substr($txt['days'][$day], 0, 1), '</th>'; |
||
287 | } |
||
288 | |||
289 | echo ' |
||
290 | </tr>'; |
||
291 | } |
||
292 | |||
293 | // Each week in weeks contains the following: |
||
294 | // days (a list of days), number (week # in the year.) |
||
295 | foreach ($calendar_data['weeks'] as $week) |
||
296 | { |
||
297 | echo ' |
||
298 | <tr>'; |
||
299 | |||
300 | if (!empty($calendar_data['show_week_links'])) |
||
301 | { |
||
302 | echo ' |
||
303 | <td class="weeks"> |
||
304 | <a href="', getUrl('action', ['action' => 'calendar', 'year' => $calendar_data['current_year'], 'month' => $calendar_data['current_month'], 'day' => $week['days'][0]['day'], 'viewweek']), '"> |
||
305 | <i class="icon i-eye-plus"></i> |
||
306 | </a> |
||
307 | </td>'; |
||
308 | } |
||
309 | |||
310 | // Every day has the following: |
||
311 | // day (# in month), is_today (is this day *today*?), is_first_day (first day of the week?), |
||
312 | // holidays, events, birthdays. (last three are lists.) |
||
313 | foreach ($week['days'] as $day) |
||
314 | { |
||
315 | // If this is today, make it a different color and show a border. |
||
316 | echo ' |
||
317 | <td class="', $day['is_today'] ? 'calendar_today' : '', ' days">'; |
||
318 | |||
319 | // Skip it if it should be blank - it's not a day if it has no number. |
||
320 | if (!empty($day['day'])) |
||
321 | { |
||
322 | // Should the day number be a link? |
||
323 | if (!empty($modSettings['cal_daysaslink']) && $context['can_post']) |
||
324 | { |
||
325 | echo ' |
||
326 | <a href="', getUrl('action', ['action' => 'calendar', 'sa' => 'post', 'year' => $calendar_data['current_year'], 'month' => $calendar_data['current_month'], 'day' => $day['day'], '{session_data}']), '">', $day['day'], '</a>'; |
||
327 | } |
||
328 | else |
||
329 | { |
||
330 | echo ' |
||
331 | ', $day['day']; |
||
332 | } |
||
333 | |||
334 | // Is this the first day of the week? (and are we showing week numbers?) |
||
335 | if ($day['is_first_day'] && $calendar_data['size'] != 'small') |
||
336 | { |
||
337 | echo ' - <a href="', getUrl('action', ['action' => 'calendar', 'year' => $calendar_data['current_year'], 'month' => $calendar_data['current_month'], 'day' => $day['day'], 'viewweek']), '">', $txt['calendar_week'], ' ', $week['number'], '</a>'; |
||
338 | } |
||
339 | |||
340 | // Are there any holidays? |
||
341 | if (!empty($day['holidays'])) |
||
342 | { |
||
343 | echo ' |
||
344 | <div class="holiday">', $txt['calendar_prompt'], ' ', implode(', ', $day['holidays']), '</div>'; |
||
345 | } |
||
346 | |||
347 | // Show any birthdays... |
||
348 | if (!empty($day['birthdays'])) |
||
349 | { |
||
350 | echo ' |
||
351 | <div> |
||
352 | <span class="birthday">', $txt['birthdays'], '</span>'; |
||
353 | |||
354 | // Each of the birthdays has: |
||
355 | // id, name (person), age (if they have one set?), and is_last. (last in list?) |
||
356 | $use_js_hide = empty($context['show_all_birthdays']) && count($day['birthdays']) > 10; |
||
357 | $count = 0; |
||
358 | foreach ($day['birthdays'] as $member) |
||
359 | { |
||
360 | echo ' |
||
361 | <a href="', getUrl('profile', ['action' => 'profile', 'u' => $member['id'], 'name' => $member['name']]), '">', $member['name'], isset($member['age']) ? ' (' . $member['age'] . ')' : '', '</a>', $member['is_last'] || ($count == 10 && $use_js_hide) ? '' : ', '; |
||
362 | |||
363 | // Stop at ten? |
||
364 | if ($count === 10 && $use_js_hide) |
||
365 | { |
||
366 | echo ' |
||
367 | <span class="hidelink" id="bdhidelink_', $day['day'], '">...<br /> |
||
368 | <a href="', getUrl('action', ['action' => 'calendar', 'year' => $calendar_data['current_year'], 'month' => $calendar_data['current_month'], 'showbd']), '" onclick="document.getElementById(\'bdhide_', $day['day'], "').style.display = 'block'; document.getElementById('bdhidelink_", $day['day'], '\').style.display = \'none\'; return false;">(', sprintf($txt['calendar_click_all'], count($day['birthdays'])), ')</a> |
||
369 | </span> |
||
370 | <span id="bdhide_', $day['day'], '" class="hide">, '; |
||
371 | } |
||
372 | |||
373 | $count++; |
||
374 | } |
||
375 | |||
376 | if ($use_js_hide) |
||
377 | { |
||
378 | echo ' |
||
379 | </span>'; |
||
380 | } |
||
381 | |||
382 | echo ' |
||
383 | </div>'; |
||
384 | } |
||
385 | |||
386 | // Any special posted events? |
||
387 | if (!empty($day['events'])) |
||
388 | { |
||
389 | echo ' |
||
390 | <div class="lefttext"> |
||
391 | <span class="event">', $txt['events'], '</span><br />'; |
||
392 | |||
393 | // The events are made up of: |
||
394 | // title, href, is_last, can_edit (are they allowed to?), and modify_href. |
||
395 | foreach ($day['events'] as $event) |
||
396 | { |
||
397 | // If they can edit the event, show an icon they can click on.... |
||
398 | if ($event['can_edit']) |
||
399 | { |
||
400 | echo ' |
||
401 | <a class="modify_event" href="', $event['modify_href'], '"> |
||
402 | <i class="icon i-modify" title="' . $txt['modify'] . '"></i> |
||
403 | </a>'; |
||
404 | } |
||
405 | |||
406 | if ($event['can_export']) |
||
407 | { |
||
408 | echo ' |
||
409 | <a class="modify_event" href="', $event['export_href'], '"> |
||
410 | <i class="icon i-download" title="' . $txt['save'] . '"></i> |
||
411 | </a>'; |
||
412 | } |
||
413 | |||
414 | echo ' |
||
415 | ', $event['link'], $event['is_last'] ? '' : '<br />'; |
||
416 | } |
||
417 | |||
418 | echo ' |
||
419 | </div>'; |
||
420 | } |
||
421 | } |
||
422 | |||
423 | echo ' |
||
424 | </td>'; |
||
425 | } |
||
426 | |||
427 | echo ' |
||
428 | </tr>'; |
||
429 | } |
||
430 | |||
431 | echo ' |
||
432 | </table>'; |
||
572 |