| Conditions | 7 |
| Paths | 4 |
| Total Lines | 97 |
| Code Lines | 72 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 declare(strict_types=1); |
||
| 40 | function b_wgevents_calendar_show($options) |
||
| 41 | { |
||
| 42 | $block = []; |
||
|
|
|||
| 43 | $typeBlock = $options[0]; |
||
| 44 | $limit = $options[1]; |
||
| 45 | \array_shift($options); |
||
| 46 | \array_shift($options); |
||
| 47 | |||
| 48 | $helper = Helper::getInstance(); |
||
| 49 | $eventHandler = $helper->getHandler('Event'); |
||
| 50 | $categoryHandler = $helper->getHandler('Category'); |
||
| 51 | |||
| 52 | \xoops_loadLanguage('main', 'wgevents'); |
||
| 53 | |||
| 54 | //default params |
||
| 55 | $year = (int)\date('Y'); |
||
| 56 | $month = (int)\date('n'); |
||
| 57 | $lastday = (int)\date('t', \strtotime($month . '/1/' . $year)); |
||
| 58 | $dayStart = \mktime(0, 0, 0, $month, 1, $year); |
||
| 59 | $dayEnd = \mktime(23, 59, 59, $month, $lastday, $year); |
||
| 60 | |||
| 61 | $filterFrom = $dayStart; |
||
| 62 | $filterTo = $dayEnd; |
||
| 63 | $filterSort = 'datefrom-ASC'; |
||
| 64 | [$sortBy, $orderBy] = \explode('-', $filterSort); |
||
| 65 | |||
| 66 | /*calendar nav bar*/ |
||
| 67 | $arrMonth = [ |
||
| 68 | 1 => \_MA_WGEVENTS_CAL_JANUARY, |
||
| 69 | 2 => \_MA_WGEVENTS_CAL_FEBRUARY, |
||
| 70 | 3 => \_MA_WGEVENTS_CAL_MARCH, |
||
| 71 | 4 => \_MA_WGEVENTS_CAL_APRIL, |
||
| 72 | 5 => \_MA_WGEVENTS_CAL_MAY, |
||
| 73 | 6 => \_MA_WGEVENTS_CAL_JUNE, |
||
| 74 | 7 => \_MA_WGEVENTS_CAL_JULY, |
||
| 75 | 8 => \_MA_WGEVENTS_CAL_AUGUST, |
||
| 76 | 9 => \_MA_WGEVENTS_CAL_SEPTEMBER, |
||
| 77 | 10 => \_MA_WGEVENTS_CAL_OCTOBER, |
||
| 78 | 11 => \_MA_WGEVENTS_CAL_NOVEMBER, |
||
| 79 | 12 => \_MA_WGEVENTS_CAL_DECEMBER |
||
| 80 | ]; |
||
| 81 | $GLOBALS['xoopsTpl']->assign('monthNav', $arrMonth[\date('n', $filterFrom)]); |
||
| 82 | $GLOBALS['xoopsTpl']->assign('yearNav', \date('Y', $filterFrom)); |
||
| 83 | |||
| 84 | $GLOBALS['xoTheme']->addStylesheet(\WGEVENTS_URL . '/class/SimpleCalendar/css/SimpleCalendarMini.css', null); |
||
| 85 | $calendar = new SimpleCalendar\SimpleCalendarMini(); |
||
| 86 | $calendar->setStartOfWeek($helper->getConfig('cal_firstday')); |
||
| 87 | $calendar->setWeekDayNames([ |
||
| 88 | \_MA_WGEVENTS_CAL_MIN_SUNDAY, |
||
| 89 | \_MA_WGEVENTS_CAL_MIN_MONDAY, |
||
| 90 | \_MA_WGEVENTS_CAL_MIN_TUESDAY, |
||
| 91 | \_MA_WGEVENTS_CAL_MIN_WEDNESDAY, |
||
| 92 | \_MA_WGEVENTS_CAL_MIN_THURSDAY, |
||
| 93 | \_MA_WGEVENTS_CAL_MIN_FRIDAY, |
||
| 94 | \_MA_WGEVENTS_CAL_MIN_SATURDAY ]); |
||
| 95 | |||
| 96 | // get categories collection |
||
| 97 | $categories = $categoryHandler->getCollection(); |
||
| 98 | // get events of period |
||
| 99 | $eventsArr = $eventHandler->getEvents(0, 0, $filterFrom, $filterTo, $sortBy, $orderBy); |
||
| 100 | |||
| 101 | $eventsCount = $eventsArr['count']; |
||
| 102 | if ($eventsCount > 0) { |
||
| 103 | $calendar->setDate($filterFrom); |
||
| 104 | $GLOBALS['xoopsTpl']->assign('eventsCount', $eventsCount); |
||
| 105 | foreach($eventsArr['eventsAll'] as $event) { |
||
| 106 | $badgeStyle = 'border:1px solid ' . $categories[$event->getVar('catid')]['bordercolor'] . '!important;'; |
||
| 107 | $badgeStyle .= 'background-color:' . $categories[$event->getVar('catid')]['bgcolor'] . '!important;'; |
||
| 108 | $badgeStyle .= 'border-radius:50% !important;'; |
||
| 109 | $eventLink = '<a href="' . \WGEVENTS_URL . '/event.php?op=show&id=' . $event->getVar('id') .'" title="' . $event->getVar('name') .'">'; |
||
| 110 | $eventLink .= '<span class="badge" style="' . $badgeStyle . '"> </span></a>'; |
||
| 111 | $calendar->addDailyHtml($eventLink, $event->getVar('datefrom'), $event->getVar('dateto')); |
||
| 112 | } |
||
| 113 | } |
||
| 114 | $GLOBALS['xoopsTpl']->assign('events_calendar', $calendar->render()); |
||
| 115 | $GLOBALS['xoopsTpl']->assign('events_calendar_header', ''); |
||
| 116 | |||
| 117 | if($limit > 0 && $eventsCount > 0) { |
||
| 118 | $counter = 0; |
||
| 119 | $eventsList = []; |
||
| 120 | // Get All Event |
||
| 121 | foreach($eventsArr['eventsAll'] as $event) { |
||
| 122 | if ($counter < $limit) { |
||
| 123 | $eventsList[$counter] = $event->getValuesEvents(); |
||
| 124 | } |
||
| 125 | $counter++; |
||
| 126 | } |
||
| 127 | $GLOBALS['xoopsTpl']->assign('events_list', $eventsList); |
||
| 128 | unset($eventsList); |
||
| 129 | } |
||
| 130 | |||
| 131 | $GLOBALS['xoopsTpl']->assign('wgevents_upload_catlogos_url', \WGEVENTS_UPLOAD_CATLOGOS_URL); |
||
| 132 | $GLOBALS['xoopsTpl']->assign('wgevents_upload_eventlogos_url', \WGEVENTS_UPLOAD_EVENTLOGOS_URL); |
||
| 133 | $GLOBALS['xoopsTpl']->assign('wgevents_url', \WGEVENTS_URL . '/'); |
||
| 134 | |||
| 135 | //create dummy return in order to show block |
||
| 136 | return ['dummy']; |
||
| 137 | } |
||
| 179 |