public function executeDays($request) { $inputDate = $request->getParameter('date'); // Check the input value and convert it to time if ($inputDate == '' || is_null($inputDate)) { $inputTime = time(); } else { $inputTime = strtotime($inputDate); if ($inputTime == '') { $inputTime = time(); } } $matrix = array(); $dayNames = array(); $matrixTotal = 1; $firstDayOfMonth = Datepicker::getFirstDayOfMonth($inputTime); if ($firstDayOfMonth == -1) { $firstDayOfMonth = 6; } for ($i = Datepicker::getPrevMonthMaxDays($inputTime) - $firstDayOfMonth; $i <= Datepicker::getPrevMonthMaxDays($inputTime); $i++) { $matrix[strtotime($i . '.' . Datepicker::getPrevMonth($inputTime) . '.' . Datepicker::getYearPrevMonth($inputTime))] = $i; $matrixTotal++; } for ($i = 1; $i <= date('t', $inputTime); $i++) { $matrix[strtotime($i . '.' . date('m', $inputTime) . '.' . date('Y', $inputTime))] = $i; $matrixTotal++; } if ($matrixTotal != 42) { for ($i = 1; $i <= 43 - $matrixTotal; $i++) { $matrix[strtotime($i . '.' . Datepicker::getNextMonth($inputTime) . '.' . Datepicker::getYearNextMonth($inputTime))] = $i; } } foreach (sfDateTimeFormatInfo::getInstance($this->getUser()->getCulture())->getDayNames() as $days) { $dayNames[] = ucfirst(substr($days, 0, 2)); } $this->month_matrix = $matrix; $this->time = $inputTime; $this->dayNames = $dayNames; }
<table class="title-container" cellpadding="0" cellspacing="0" align="center"> <tr> <td class="arrow-left" valign="middle" onclick="dp_prevMonth('<?php echo date('d.m.Y', strtotime(date('d', $time) . '.' . Datepicker::getPrevMonth($time) . '.' . Datepicker::getYearPrevMonth($time))); ?> ')"></td> <td class="title" valign="middle"> <?php echo ucfirst(format_date($time, 'MMMM, yyyy', $sf_user->getCulture())); ?> </td> <td class="arrow-right" valign="middle" onclick="dp_nextMonth('<?php echo date('d.m.Y', strtotime(date('d', $time) . '.' . Datepicker::getNextMonth($time) . '.' . Datepicker::getYearNextMonth($time))); ?> ')"></td> </tr> </table> <table class="weekdays-container" cellpadding="0" cellspacing="0" align="center"> <tr> <td><?php echo $dayNames[1]; ?> </td> <td><?php echo $dayNames[2]; ?> </td> <td><?php echo $dayNames[3]; ?> </td>
/** * Get the previous year if the month is january * * @param mixed $date The date or a time * @return integer the previous year or the current year */ public static function getYearPrevMonth($date) { $currentMonth = date('n', Datepicker::getTime($date)); if ($currentMonth == 1) { $lastYear = date('Y', Datepicker::getTime($date)) - 1; } else { $lastYear = date('Y', Datepicker::getTime($date)); } return $lastYear; }