Beispiel #1
0
 /**
  * Generate the module
  */
 protected function compile()
 {
     // Respond to month
     if (\Input::get('month')) {
         $this->Date = new \Date(\Input::get('month'), 'Ym');
     } elseif (\Input::get('day')) {
         $this->Date = new \Date(\Input::get('day'), 'Ymd');
     } else {
         $this->Date = new \Date();
     }
     // Find the boundaries
     $objMinMax = \CalendarEventsModel::findBoundaries($this->cal_calendar);
     $intLeftBoundary = date('Ym', $objMinMax->dateFrom);
     $intRightBoundary = date('Ym', max($objMinMax->dateTo, $objMinMax->repeatUntil));
     // Instantiate the template
     $objTemplate = new \FrontendTemplate($this->cal_ctemplate ? $this->cal_ctemplate : 'cal_default');
     // Store year and month
     $intYear = date('Y', $this->Date->tstamp);
     $intMonth = date('m', $this->Date->tstamp);
     $objTemplate->intYear = $intYear;
     $objTemplate->intMonth = $intMonth;
     // Previous month
     $prevMonth = $intMonth == 1 ? 12 : $intMonth - 1;
     $prevYear = $intMonth == 1 ? $intYear - 1 : $intYear;
     $lblPrevious = $GLOBALS['TL_LANG']['MONTHS'][$prevMonth - 1] . ' ' . $prevYear;
     $intPrevYm = intval($prevYear . str_pad($prevMonth, 2, 0, STR_PAD_LEFT));
     // Only generate a link if there are events (see #4160)
     if ($intPrevYm >= $intLeftBoundary) {
         $objTemplate->prevHref = $this->strUrl . ($GLOBALS['TL_CONFIG']['disableAlias'] ? '?id=' . \Input::get('id') . '&' : '?') . 'month=' . $intPrevYm;
         $objTemplate->prevTitle = specialchars($lblPrevious);
         $objTemplate->prevLink = $GLOBALS['TL_LANG']['MSC']['cal_previous'] . ' ' . $lblPrevious;
         $objTemplate->prevLabel = $GLOBALS['TL_LANG']['MSC']['cal_previous'];
     }
     // Current month
     $objTemplate->current = $GLOBALS['TL_LANG']['MONTHS'][date('m', $this->Date->tstamp) - 1] . ' ' . date('Y', $this->Date->tstamp);
     // Next month
     $nextMonth = $intMonth == 12 ? 1 : $intMonth + 1;
     $nextYear = $intMonth == 12 ? $intYear + 1 : $intYear;
     $lblNext = $GLOBALS['TL_LANG']['MONTHS'][$nextMonth - 1] . ' ' . $nextYear;
     $intNextYm = $nextYear . str_pad($nextMonth, 2, 0, STR_PAD_LEFT);
     // Only generate a link if there are events (see #4160)
     if ($intNextYm <= $intRightBoundary) {
         $objTemplate->nextHref = $this->strUrl . ($GLOBALS['TL_CONFIG']['disableAlias'] ? '?id=' . \Input::get('id') . '&amp;' : '?') . 'month=' . $intNextYm;
         $objTemplate->nextTitle = specialchars($lblNext);
         $objTemplate->nextLink = $lblNext . ' ' . $GLOBALS['TL_LANG']['MSC']['cal_next'];
         $objTemplate->nextLabel = $GLOBALS['TL_LANG']['MSC']['cal_next'];
     }
     // Set the week start day
     if (!$this->cal_startDay) {
         $this->cal_startDay = 0;
     }
     $objTemplate->days = $this->compileDays();
     $objTemplate->weeks = $this->compileWeeks();
     $objTemplate->substr = $GLOBALS['TL_LANG']['MSC']['dayShortLength'];
     $this->Template->calendar = $objTemplate->parse();
 }
 /**
  * Generate module
  */
 protected function compile()
 {
     // Respond to month
     if (\Input::get('month')) {
         $this->Date = new \Date(\Input::get('month') . '01', 'Ymd');
     } elseif (\Input::get('week')) {
         $selYear = (int) substr(\Input::get('week'), 0, 4);
         $selWeek = (int) substr(\Input::get('week'), -2);
         $selDay = $selWeek == 1 ? 4 : 1;
         $dt = new \DateTime();
         $dt->setISODate($selYear, $selWeek, $selDay);
         $this->Date = new \Date($dt->format('Ymd'), 'Ymd');
         unset($dt);
     } elseif (\Input::get('day')) {
         $this->Date = new \Date(\Input::get('day'), 'Ymd');
     } else {
         $this->Date = new \Date();
     }
     // Get the Year and the week of the given date
     $intYear = (int) date('Y', $this->Date->tstamp);
     $intWeek = (int) date('W', $this->Date->tstamp);
     $dt = new \DateTime();
     // Set date to the first day of the given week
     $dt->setISODate($intYear, $intWeek, 1);
     $newDate = new Date($dt->format('Ymd'), 'Ymd');
     $newYear = date('Y', $newDate->tstamp);
     $newMonth = date('m', $newDate->tstamp);
     $newDay = (int) date('d', $newDate->tstamp);
     $this->weekBegin = mktime(0, 0, 0, $newMonth, $newDay, $newYear);
     // Set date to the last day of the given week
     $dt->setISODate($intYear, $intWeek, 7);
     $newDate = new Date($dt->format('Ymd'), 'Ymd');
     $newYear = date('Y', $newDate->tstamp);
     $newMonth = date('m', $newDate->tstamp);
     $newDay = (int) date('d', $newDate->tstamp);
     $this->weekEnd = mktime(23, 59, 59, $newMonth, $newDay, $newYear);
     unset($dt);
     // Get total count of weeks of the year
     if (($weeksTotal = date('W', mktime(0, 0, 0, 12, 31, $intYear))) == 1) {
         $weeksTotal = date('W', mktime(0, 0, 0, 12, 24, $intYear));
     }
     // Find the boundaries
     $objMinMax = \CalendarEventsModel::findBoundaries($this->cal_calendar);
     $intLeftBoundary = date('YW', $objMinMax->dateFrom);
     $intRightBoundary = date('YW', max($objMinMax->dateTo, $objMinMax->repeatUntil));
     $objTemplate = new \FrontendTemplate($this->calext_ctemplate ? $this->calext_ctemplate : 'calext_timetable');
     $objTemplate->intYear = $intYear;
     $objTemplate->intWeek = $intWeek;
     $objTemplate->weekBegin = $this->weekBegin;
     $objTemplate->weekEnd = $this->weekEnd;
     $objTemplate->cal_times = $this->cal_times;
     $objTemplate->use_navigation = $this->use_navigation;
     $objTemplate->linkCurrent = $this->linkCurrent;
     // display the navigation if selected
     if ($this->use_navigation) {
         // Get the current year and the week
         if ($this->linkCurrent) {
             $currYear = date('Y');
             $currWeek = (int) date('W');
             $lblCurrent = $GLOBALS['TL_LANG']['MSC']['curr_week'];
             $objTemplate->currHref = $this->strUrl . ($GLOBALS['TL_CONFIG']['disableAlias'] ? '?id=' . $this->Input->get('id') . '&amp;' : '?') . 'week=' . $currYear . str_pad($currWeek, 2, 0, STR_PAD_LEFT);
             $objTemplate->currTitle = specialchars($lblCurrent);
             $objTemplate->currLink = $lblCurrent;
             $objTemplate->currLabel = $GLOBALS['TL_LANG']['MSC']['cal_previous'];
         }
         // Previous week
         $prevWeek = $intWeek == 1 ? $weeksTotal : $intWeek - 1;
         $prevYear = $intWeek == 1 ? $intYear - 1 : $intYear;
         $lblPrevious = $GLOBALS['TL_LANG']['MSC']['calendar_week'] . ' ' . $prevWeek . ' ' . $prevYear;
         $intPrevYm = intval($prevYear . str_pad($prevWeek, 2, 0, STR_PAD_LEFT));
         if ($intPrevYm >= $intLeftBoundary) {
             $objTemplate->prevHref = $this->strUrl . ($GLOBALS['TL_CONFIG']['disableAlias'] ? '?id=' . $this->Input->get('id') . '&amp;' : '?') . 'week=' . $prevYear . str_pad($prevWeek, 2, 0, STR_PAD_LEFT);
             $objTemplate->prevTitle = specialchars($lblPrevious);
             $objTemplate->prevLink = $GLOBALS['TL_LANG']['MSC']['cal_previous'] . ' ' . $lblPrevious;
             $objTemplate->prevLabel = $GLOBALS['TL_LANG']['MSC']['cal_previous'];
         }
         // Current week
         $dateInfo = $this->parseDate($GLOBALS['TL_CONFIG']['dateFormat'], $this->weekBegin) . ' - ' . $this->parseDate($GLOBALS['TL_CONFIG']['dateFormat'], $this->weekEnd);
         $objTemplate->current = $GLOBALS['TL_LANG']['MSC']['calendar_week'] . ' ' . $intWeek . ' ' . $intYear;
         // Next month
         $nextWeek = $intWeek == $weeksTotal ? 1 : $intWeek + 1;
         $nextYear = $intWeek == $weeksTotal ? $intYear + 1 : $intYear;
         $lblNext = $GLOBALS['TL_LANG']['MSC']['calendar_week'] . ' ' . $nextWeek . ' ' . $nextYear;
         $intNextYm = $nextYear . str_pad($nextWeek, 2, 0, STR_PAD_LEFT);
         // Only generate a link if there are events (see #4160)
         if ($intNextYm <= $intRightBoundary) {
             $objTemplate->nextHref = $this->strUrl . ($GLOBALS['TL_CONFIG']['disableAlias'] ? '?id=' . $this->Input->get('id') . '&amp;' : '?') . 'week=' . $nextYear . str_pad($nextWeek, 2, 0, STR_PAD_LEFT);
             $objTemplate->nextTitle = specialchars($lblNext);
             $objTemplate->nextLink = $lblNext . ' ' . $GLOBALS['TL_LANG']['MSC']['cal_next'];
             $objTemplate->nextLabel = $GLOBALS['TL_LANG']['MSC']['cal_next'];
         }
     }
     // Set week start day
     if (!$this->cal_startDay) {
         $this->cal_startDay = 0;
     }
     list($objTemplate->weekday, $objTemplate->times) = $this->compileDays();
     $this->Template->calendar = $objTemplate->parse();
 }
 /**
  * Generate module
  */
 protected function compile()
 {
     if (\Input::get('year')) {
         $intYear = \Input::get('year');
         $this->yearBegin = mktime(0, 0, 0, 1, 1, $intYear);
         $this->Date = new \Date($this->yearBegin);
     } else {
         $this->Date = new \Date();
     }
     // Get the Year and the week of the given date
     $intYear = date('Y', $this->Date->tstamp);
     $this->yearBegin = mktime(0, 0, 0, 1, 1, $intYear);
     $this->yearEnd = mktime(23, 59, 59, 12, 31, $intYear);
     // Get total count of weeks of the year
     if (($weeksTotal = date('W', mktime(0, 0, 0, 12, 31, $intYear))) == 1) {
         $weeksTotal = date('W', mktime(0, 0, 0, 12, 24, $intYear));
     }
     // Find the boundaries
     $objMinMax = \CalendarEventsModel::findBoundaries($this->cal_calendar);
     $intLeftBoundary = date('Y', $objMinMax->dateFrom);
     $intRightBoundary = date('Y', max($objMinMax->dateTo, $objMinMax->repeatUntil));
     $objTemplate = new \FrontendTemplate($this->calext_ctemplate ? $this->calext_ctemplate : 'calext_yearview');
     $objTemplate->intYear = $intYear;
     $objTemplate->use_navigation = $this->use_navigation;
     $objTemplate->linkCurrent = $this->linkCurrent;
     // display the navigation if selected
     if ($this->use_navigation) {
         // Get the current year and the week
         if ($this->linkCurrent) {
             $currYear = date('Y', time());
             $lblCurrent = $GLOBALS['TL_LANG']['MSC']['curr_year'];
             $objTemplate->currHref = $this->strUrl . ($GLOBALS['TL_CONFIG']['disableAlias'] ? '?id=' . $this->Input->get('id') . '&amp;' : '?') . 'year=' . $currYear;
             $objTemplate->currTitle = $currYear;
             $objTemplate->currLink = $lblCurrent;
             $objTemplate->currLabel = $GLOBALS['TL_LANG']['MSC']['cal_previous'];
         }
         // Previous week
         $prevYear = $intYear - 1;
         $lblPrevious = $GLOBALS['TL_LANG']['MSC']['calendar_year'] . ' ' . $prevYear;
         // Only generate a link if there are events (see #4160)
         if ($prevYear >= $intLeftBoundary) {
             $objTemplate->prevHref = $this->strUrl . ($GLOBALS['TL_CONFIG']['disableAlias'] ? '?id=' . $this->Input->get('id') . '&amp;' : '?') . 'year=' . $prevYear;
             $objTemplate->prevTitle = $prevYear;
             $objTemplate->prevLink = $GLOBALS['TL_LANG']['MSC']['cal_previous'] . ' ' . $lblPrevious;
             $objTemplate->prevLabel = $GLOBALS['TL_LANG']['MSC']['cal_previous'];
         }
         // Current week
         $objTemplate->current = $GLOBALS['TL_LANG']['MSC']['calendar_year'] . ' ' . $intYear;
         // Next month
         $nextYear = $intYear + 1;
         $lblNext = $GLOBALS['TL_LANG']['MSC']['calendar_year'] . ' ' . $nextYear;
         // Only generate a link if there are events (see #4160)
         if ($nextYear <= $intRightBoundary) {
             $objTemplate->nextHref = $this->strUrl . ($GLOBALS['TL_CONFIG']['disableAlias'] ? '?id=' . $this->Input->get('id') . '&amp;' : '?') . 'year=' . $nextYear;
             $objTemplate->nextTitle = $nextYear;
             $objTemplate->nextLink = $lblNext . ' ' . $GLOBALS['TL_LANG']['MSC']['cal_next'];
             $objTemplate->nextLabel = $GLOBALS['TL_LANG']['MSC']['cal_next'];
         }
     }
     // Set week start day
     if (!$this->cal_startDay) {
         $this->cal_startDay = 0;
     }
     $objTemplate->months = $this->compileMonths();
     $objTemplate->yeardays = $this->compileDays($intYear);
     $this->Template->calendar = $objTemplate->parse();
 }