| Conditions | 14 |
| Paths | 289 |
| Total Lines | 209 |
| Code Lines | 116 |
| 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 |
||
| 35 | function bExtcalMinicalShow($options) |
||
| 36 | { |
||
| 37 | global $xoopsUser; |
||
| 38 | |||
| 39 | extcal_getDefautminicalOption($options); |
||
| 40 | |||
| 41 | // // require_once dirname(__DIR__) . '/class/Config.php'; |
||
| 42 | |||
| 43 | require_once _EXTCAL_PEAR_CALENDAR_ROOT . '/Util/Textual.php'; |
||
| 44 | require_once _EXTCAL_PEAR_CALENDAR_ROOT . '/Month/Weeks.php'; |
||
| 45 | require_once _EXTCAL_PEAR_CALENDAR_ROOT . '/Day.php'; |
||
| 46 | // require_once CALENDAR_ROOT . 'Month/Weeks.php'; |
||
| 47 | // require_once CALENDAR_ROOT . 'Day.php'; |
||
| 48 | |||
| 49 | /** @var Helper $helper */ |
||
| 50 | if (!class_exists(Helper::class)) { |
||
| 51 | return false; |
||
| 52 | } |
||
| 53 | |||
| 54 | $helper = Helper::getInstance(); |
||
| 55 | $helper->loadLanguage('main'); |
||
| 56 | |||
| 57 | // Retriving Image for block if enabled |
||
| 58 | if (isset($options[0]) && 1 == $options[0]) { |
||
| 59 | $imageHandler = xoops_getHandler('image'); |
||
| 60 | $criteria = new \Criteria('imgcat_id', $options[1]); |
||
| 61 | $criteria->setSort('RAND()'); |
||
| 62 | $criteria->setLimit($options[6]); |
||
| 63 | $images = $imageHandler->getObjects($criteria); |
||
|
|
|||
| 64 | $slideShowParam = [ |
||
| 65 | 'images' => $images, |
||
| 66 | 'frameHeight' => $options[3], |
||
| 67 | 'frameWidth' => $options[2], |
||
| 68 | 'transTime' => $options[4], |
||
| 69 | 'pauseTime' => $options[5], |
||
| 70 | ]; |
||
| 71 | if (count($images) > 0) { |
||
| 72 | _makeXMLSlideshowConf($slideShowParam); |
||
| 73 | $imageParam = ['displayImage' => true]; |
||
| 74 | } else { |
||
| 75 | $imageParam = ['displayImage' => false]; |
||
| 76 | } |
||
| 77 | } else { |
||
| 78 | $imageParam = ['displayImage' => false]; |
||
| 79 | } |
||
| 80 | $imageParam['frameHeight'] = $options[3]; |
||
| 81 | $imageParam['frameWidth'] = $options[2]; |
||
| 82 | |||
| 83 | $categoryHandler = $helper->getHandler(_EXTCAL_CLN_CAT); |
||
| 84 | |||
| 85 | $cats = $categoryHandler->getAllCatById($xoopsUser); |
||
| 86 | // $t = print_r($cats,true); |
||
| 87 | // echo "zzz<pre>{$t}</pre>"; |
||
| 88 | |||
| 89 | $eventHandler = $helper->getHandler(_EXTCAL_CLN_EVENT); |
||
| 90 | $timeHandler = Time::getHandler(); |
||
| 91 | |||
| 92 | // Retriving month and year value according to block options |
||
| 93 | //modif JJD |
||
| 94 | $offset = $helper->getConfig('offsetMinical'); |
||
| 95 | $monthToShow = mktime(0, 0, 0, date('m') + $offset, date('d'), date('Y')); |
||
| 96 | $month = date('n', $monthToShow); |
||
| 97 | $year = date('Y', $monthToShow); |
||
| 98 | |||
| 99 | //---------------------------------------------------- |
||
| 100 | $month += $options[7]; //ajout ou retrait du nombre de mois de décalage |
||
| 101 | if ($month < 1) { |
||
| 102 | $month = 12; |
||
| 103 | --$year; |
||
| 104 | } elseif ($month > 12) { |
||
| 105 | $month = 1; |
||
| 106 | ++$year; |
||
| 107 | } |
||
| 108 | //---------------------------------------------------- |
||
| 109 | |||
| 110 | // Saving display link preference |
||
| 111 | $displayLink = $options[8]; |
||
| 112 | |||
| 113 | // Delete options to keep only categorie data |
||
| 114 | $tCatSelected = explode(',', $options[9]); |
||
| 115 | |||
| 116 | /***************************************************************/ // Retriving events and formatting them |
||
| 117 | //$events = $eventHandler->objectToArray($eventHandler->getEventCalendarMonth($month, $year, $tCatSelected)); |
||
| 118 | if (true) { |
||
| 119 | $criteres = [ |
||
| 120 | 'periode' => _EXTCAL_EVENTS_MONTH, |
||
| 121 | 'month' => $month, |
||
| 122 | 'year' => $year, |
||
| 123 | 'category' => $tCatSelected, |
||
| 124 | 'externalKeys' => 'cat_id', |
||
| 125 | ]; |
||
| 126 | $events = $eventHandler->getEventsOnPeriode($criteres); |
||
| 127 | } else { |
||
| 128 | $events = []; |
||
| 129 | } |
||
| 130 | //Utility::echoArray($events, 'minical'); |
||
| 131 | /***************************************************************/ //$eventHandler->formatEventDate($events, "l dS \of F Y h:i A"); |
||
| 132 | |||
| 133 | // Calculating timestamp for the begin and the end of the month |
||
| 134 | $startMonth = mktime(0, 0, 0, $month, 1, $year); |
||
| 135 | $endMonth = mktime(23, 59, 59, $month + 1, 0, $year); |
||
| 136 | |||
| 137 | /* |
||
| 138 | * Adding all event occuring during this month to an array indexed by day number |
||
| 139 | */ |
||
| 140 | $eventsArray = []; |
||
| 141 | foreach ($events as $event) { |
||
| 142 | //echo "id->{$event['event_id']}<br>"; |
||
| 143 | bExtcalMinicalAddEventToArray($event, $eventsArray, $timeHandler, $startMonth, $endMonth, $cats); |
||
| 144 | // if (!$event['event_isrecur']) { |
||
| 145 | // bExtcalMinicalAddEventToArray($event, $eventsArray, $timeHandler, $startMonth, $endMonth, $cats); |
||
| 146 | // } else { |
||
| 147 | // |
||
| 148 | // $recurEvents = $eventHandler->getRecurEventToDisplay($event, $startMonth, $endMonth); |
||
| 149 | // foreach ($recurEvents as $recurEvent) |
||
| 150 | // { |
||
| 151 | // bExtcalMinicalAddEventToArray($recurEvent, $eventsArray, $timeHandler, $startMonth, $endMonth, $cats); |
||
| 152 | // } |
||
| 153 | // } |
||
| 154 | } |
||
| 155 | //Utility::echoArray($eventsArray); |
||
| 156 | |||
| 157 | /* |
||
| 158 | * Making an array to create tabbed output on the template |
||
| 159 | */ |
||
| 160 | // Flag current day |
||
| 161 | $selectedDays = [ |
||
| 162 | new Calendar_Day( |
||
| 163 | date('Y', xoops_getUserTimestamp(time(), $timeHandler->getUserTimeZone($GLOBALS['xoopsUser']))), |
||
| 164 | date('n', xoops_getUserTimestamp(time(), $timeHandler->getUserTimeZone($GLOBALS['xoopsUser']))), |
||
| 165 | date('j', xoops_getUserTimestamp(time(), $timeHandler->getUserTimeZone($GLOBALS['xoopsUser']))) |
||
| 166 | ), |
||
| 167 | ]; |
||
| 168 | |||
| 169 | // Build calendar object |
||
| 170 | $monthCalObj = new Calendar_Month_Weeks($year, $month, $helper->getConfig('week_start_day')); |
||
| 171 | $monthCalObj->build(); |
||
| 172 | |||
| 173 | $tableRows = []; |
||
| 174 | $rowId = 0; |
||
| 175 | $cellId = 0; |
||
| 176 | while (false !== ($weekCalObj = $monthCalObj->fetch())) { |
||
| 177 | $weekCalObj->build($selectedDays); |
||
| 178 | $tableRows[$rowId]['weekInfo'] = [ |
||
| 179 | 'week' => $weekCalObj->thisWeek('n_in_year'), |
||
| 180 | 'day' => $weekCalObj->thisDay(), |
||
| 181 | 'month' => $monthCalObj->thisMonth(), |
||
| 182 | 'year' => $monthCalObj->thisYear(), |
||
| 183 | ]; |
||
| 184 | while (false !== ($dayCalObj = $weekCalObj->fetch())) { |
||
| 185 | $tableRows[$rowId]['week'][$cellId] = [ |
||
| 186 | 'isEmpty' => $dayCalObj->isEmpty(), |
||
| 187 | 'number' => $dayCalObj->thisDay(), |
||
| 188 | 'isSelected' => $dayCalObj->isSelected(), |
||
| 189 | ]; |
||
| 190 | $day = $dayCalObj->thisDay(); |
||
| 191 | if (isset($eventsArray[$day]) && !$dayCalObj->isEmpty()) { |
||
| 192 | $tableRows[$rowId]['week'][$cellId]['haveEvents'] = true; |
||
| 193 | $tableRows[$rowId]['week'][$cellId]['color'] = $eventsArray[$day]['color']; |
||
| 194 | } else { |
||
| 195 | $tableRows[$rowId]['week'][$cellId]['haveEvents'] = false; |
||
| 196 | } |
||
| 197 | ++$cellId; |
||
| 198 | } |
||
| 199 | $cellId = 0; |
||
| 200 | ++$rowId; |
||
| 201 | } |
||
| 202 | |||
| 203 | // Retriving weekdayNames |
||
| 204 | //$loc_de = setlocale (LC_ALL, 'Fr'); |
||
| 205 | |||
| 206 | $weekdayNames = Calendar_Util_Textual::weekdayNames('one'); |
||
| 207 | //$weekdayNames=array('D','L','M','M','J','V','S'); |
||
| 208 | |||
| 209 | // echo "<hr>L'identifiant de l'allemand sur ce système est '$loc_de'"; |
||
| 210 | // echoArray($weekdayNames,true); |
||
| 211 | |||
| 212 | for ($i = 0; $i < $helper->getConfig('week_start_day'); ++$i) { |
||
| 213 | $weekdayName = array_shift($weekdayNames); |
||
| 214 | $weekdayNames[] = $weekdayName; |
||
| 215 | } |
||
| 216 | |||
| 217 | // Making navig data |
||
| 218 | $navig = [ |
||
| 219 | 'page' => $helper->getConfig('start_page'), |
||
| 220 | 'uri' => 'year=' . $monthCalObj->thisYear() . '&month=' . $monthCalObj->thisMonth(), |
||
| 221 | 'name' => $timeHandler->getFormatedDate($helper->getConfig('nav_date_month'), $monthCalObj->getTimestamp()), |
||
| 222 | ]; |
||
| 223 | |||
| 224 | $horloge = []; |
||
| 225 | $horloge['display'] = ('' != trim($options[10])); |
||
| 226 | $horloge['fullName'] = XOOPS_URL . _EXTCAL_PATH_HORLOGES . $options[11]; |
||
| 227 | $horloge['width'] = $options[12] . 'px'; |
||
| 228 | $horloge['height'] = $options[13] . 'px'; |
||
| 229 | |||
| 230 | $ret = [ |
||
| 231 | 'imageParam' => $imageParam, |
||
| 232 | 'displayLink' => $displayLink, |
||
| 233 | 'submitText' => _MB_EXTCAL_SUBMIT_LINK_TEXT, |
||
| 234 | 'tableRows' => $tableRows, |
||
| 235 | 'weekdayNames' => $weekdayNames, |
||
| 236 | 'navig' => $navig, |
||
| 237 | 'horloge' => $horloge, |
||
| 238 | 'bgColor' => $options[10], |
||
| 239 | ]; |
||
| 240 | |||
| 241 | // $t = print_r($horloge,true); |
||
| 242 | // echo "<pre>{$t}</pre>"; |
||
| 243 | return $ret; |
||
| 244 | } |
||
| 593 |