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