Conditions | 22 |
Paths | > 20000 |
Total Lines | 153 |
Code Lines | 104 |
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 |
||
164 | function displayBox($selectedDate, $month, $year) |
||
165 | { |
||
166 | global $langs, $conf; |
||
167 | |||
168 | //print "$selectedDate,$month,$year"; |
||
169 | $thedate = dol_mktime(12, 0, 0, $month, 1, $year); |
||
170 | //print "thedate=$thedate"; |
||
171 | $today = dol_now(); |
||
172 | $todayArray = dol_getdate($today); |
||
173 | if ($selectedDate != "00000000") { |
||
174 | $selDate = xyzToUnixTimestamp($selectedDate); |
||
175 | $xyz = dol_print_date($selDate, "%Y%m%d"); |
||
176 | } else { |
||
177 | $selDate = 0; |
||
178 | $xyz = 0; |
||
179 | } ?> |
||
180 | <table class="dp"> |
||
181 | <tr> |
||
182 | <td colspan="6" class="dpHead"><?php |
||
183 | $selectMonth = dol_print_date($thedate, '%m'); |
||
184 | $selectYear = dol_print_date($thedate, '%Y'); |
||
185 | echo $langs->trans("Month" . $selectMonth) . ", " . $selectYear; ?></td> |
||
186 | <td class="dpHead"> |
||
187 | <button type="button" class="dpInvisibleButtons" id="DPCancel" |
||
188 | onClick="closeDPBox();">X |
||
189 | </button> |
||
190 | </td> |
||
191 | </tr> |
||
192 | <tr> |
||
193 | <td class="dpButtons" |
||
194 | onClick="loadMonth('<?php echo constant('BASE_URL') . '/core/' ?>','<?php echo $month ?>','<?php echo $year - 1 ?>','<?php echo $xyz ?>','<?php echo $langs->defaultlang ?>')"> |
||
195 | << |
||
196 | </td> |
||
197 | <td class="dpButtons" |
||
198 | onClick="loadMonth('<?php echo constant('BASE_URL') . '/core/' ?>','<?php if ($month == 1) { |
||
199 | echo "12"; |
||
200 | } else { |
||
201 | echo $month - 1; |
||
202 | } ?>','<?php if ($month == 1) { |
||
203 | echo $year - 1; |
||
204 | } else { |
||
205 | echo $year; |
||
206 | } ?>','<?php echo $xyz ?>','<?php echo $langs->defaultlang ?>')">< |
||
207 | </td> |
||
208 | <td colspan="3" class="dpButtons" |
||
209 | onClick="loadMonth('<?php echo constant('BASE_URL') . '/core/' ?>','<?php echo (int)dol_print_date($today, '%m') ?>','<?php echo $todayArray["year"] ?>','<?php echo $xyz ?>','<?php echo $langs->defaultlang ?>')"><?php echo '-' ?></td> |
||
210 | <td class="dpButtons" |
||
211 | onClick="loadMonth('<?php echo constant('BASE_URL') . '/core/' ?>','<?php if ($month == 12) { |
||
212 | echo "1"; |
||
213 | } else { |
||
214 | echo $month + 1; |
||
215 | } ?>','<?php if ($month == 12) { |
||
216 | echo $year + 1; |
||
217 | } else { |
||
218 | echo $year; |
||
219 | } ?>','<?php echo $xyz ?>','<?php echo $langs->defaultlang ?>')">> |
||
220 | </td> |
||
221 | <td class="dpButtons" |
||
222 | onClick="loadMonth('<?php echo constant('BASE_URL') . '/core/' ?>','<?php echo $month ?>','<?php echo $year + 1 ?>','<?php echo $xyz ?>','<?php echo $langs->defaultlang ?>')"> |
||
223 | >> |
||
224 | </td> |
||
225 | </tr> |
||
226 | <tr class="dpDayNames"> |
||
227 | <?php |
||
228 | $startday = isset($conf->global->MAIN_START_WEEK) ? $conf->global->MAIN_START_WEEK : 1; |
||
229 | $day_names = array('ShortSunday', 'ShortMonday', 'ShortTuesday', 'ShortWednesday', 'ShortThursday', 'ShortFriday', 'ShortSaturday'); |
||
230 | for ($i = 0; $i < 7; $i++) { |
||
231 | echo '<td width="', (int)(($i + 1) * 100 / 7) - (int)($i * 100 / 7), '%">', $langs->trans($day_names[($i + $startday) % 7]), '</td>', "\n"; |
||
232 | } |
||
233 | print '</tr>'; |
||
234 | //print "x ".$thedate." y"; // $thedate = first day of month |
||
235 | $firstdate = dol_getdate($thedate); |
||
236 | //var_dump($firstdateofweek); |
||
237 | $mydate = dol_get_first_day_week(1, $month, $year, true); // mydate = cursor date |
||
238 | |||
239 | // Loop on each day of month |
||
240 | $stoploop = 0; |
||
241 | $day = 1; |
||
242 | $cols = 0; |
||
243 | while (!$stoploop) { |
||
244 | //print_r($mydate); |
||
245 | if ($mydate < $firstdate) { // At first run |
||
246 | echo "<tr class=\"dpWeek\">"; |
||
247 | //echo $conf->global->MAIN_START_WEEK.' '.$firstdate["wday"].' '.$startday; |
||
248 | $cols = 0; |
||
249 | for ($i = 0; $i < 7; $i++) { |
||
250 | $w = ($i + $startday) % 7; |
||
251 | if ($w == $firstdate["wday"]) { |
||
252 | $mydate = $firstdate; |
||
253 | break; |
||
254 | } |
||
255 | echo "<td> </td>"; |
||
256 | $cols++; |
||
257 | } |
||
258 | } else { |
||
259 | if ($mydate["wday"] == $startday) { |
||
260 | echo "<tr class=\"dpWeek\">"; |
||
261 | $cols = 0; |
||
262 | } |
||
263 | } |
||
264 | |||
265 | $dayclass = "dpReg"; |
||
266 | if ($thedate == $selDate) { |
||
267 | $dayclass = "dpSelected"; |
||
268 | } elseif ($thedate == $today) { |
||
269 | $dayclass = "dpToday"; |
||
270 | } |
||
271 | |||
272 | if ($langs->trans("FormatDateShortJavaInput") == "FormatDateShortJavaInput") { |
||
273 | print "ERROR FormatDateShortJavaInput not defined for language " . $langs->defaultlang; |
||
274 | exit; |
||
275 | } |
||
276 | |||
277 | // Sur click dans calendrier, appelle fonction dpClickDay |
||
278 | echo "<td class=\"" . $dayclass . "\""; |
||
279 | echo " onMouseOver=\"dpHighlightDay(" . $mydate["year"] . ",parseInt('" . dol_print_date($thedate, "%m") . "',10)," . $mydate["mday"] . ",tradMonths)\""; |
||
280 | echo " onClick=\"dpClickDay(" . $mydate["year"] . ",parseInt('" . dol_print_date($thedate, "%m") . "',10)," . $mydate["mday"] . ",'" . $langs->trans("FormatDateShortJavaInput") . "')\""; |
||
281 | echo ">" . sprintf("%02d", $mydate["mday"]) . "</td>"; |
||
282 | $cols++; |
||
283 | |||
284 | if (($mydate["wday"] + 1) % 7 == $startday) { |
||
285 | echo "</TR>\n"; |
||
286 | } |
||
287 | |||
288 | //$thedate=strtotime("tomorrow",$thedate); |
||
289 | $day++; |
||
290 | $thedate = dol_mktime(12, 0, 0, $month, $day, $year); |
||
291 | if ($thedate == '') { |
||
292 | $stoploop = 1; |
||
293 | } else { |
||
294 | $mydate = dol_getdate($thedate); |
||
295 | if ($firstdate["month"] != $mydate["month"]) { |
||
296 | $stoploop = 1; |
||
297 | } |
||
298 | } |
||
299 | } |
||
300 | |||
301 | if ($cols < 7) { |
||
302 | for ($i = 6; $i >= $cols; $i--) { |
||
303 | echo "<td> </td>"; |
||
304 | } |
||
305 | echo "</tr>\n"; |
||
306 | } ?> |
||
307 | <tr> |
||
308 | <td id="dpExp" class="dpExplanation" colspan="7"><?php |
||
309 | if ($selDate) { |
||
310 | $tempDate = dol_getdate($selDate); |
||
311 | print $langs->trans("Month" . $selectMonth) . " "; |
||
312 | print sprintf("%02d", $tempDate["mday"]); |
||
313 | print ", " . $selectYear; |
||
314 | } else { |
||
315 | print "Click a Date"; |
||
316 | } ?></td> |
||
317 | </tr> |
||
321 |