function evaluateRange(&$date, $range, $rangeValue) { if (!is_numeric($range)) { if ($range == 'last') { $range = -1; } else { if ($range == 'next') { $range = 1; } } } if (is_numeric($rangeValue)) { $date->addSeconds($rangeValue * $range); } else { if (is_array($rangeValue)) { foreach ($rangeValue as $key => $value) { if ($key == 'weekday' && $range > 0) { for ($i = 0; $i < $range; $i++) { $formatedDate = Calc::nextDayOfWeek($value, $date->getDay(), $date->getMonth(), $date->getYear()); $date = new \TYPO3\CMS\Cal\Model\CalDate($formatedDate); $date->setTZbyId('UTC'); } } else { if ($key == 'weekday' && $range < 0) { for ($i = 0; $i > $range; $i--) { $formatedDate = Calc::prevDayOfWeek($value, $date->getDay(), $date->getMonth(), $date->getYear()); $date = new \TYPO3\CMS\Cal\Model\CalDate($formatedDate); $date->setTZbyId('UTC'); } } else { if ($value == 'week' && $range > 0) { $date->addSeconds($range * 604800); } else { if ($value == 'week' && $range < 0) { $date->subtractSeconds($range * 604800); } } } } } } else { if ($range > 0) { if ($rangeValue == 'month') { for ($i = 0; $i < $range; $i++) { $days = Calc::daysInMonth($date->getMonth(), $date->getYear()); $endOfNextMonth = new \TYPO3\CMS\Cal\Model\CalDate(Calc::endOfNextMonth($date->getDay(), $date->getMonth(), $date->getYear())); $date->addSeconds(60 * 60 * 24 * $days); if ($date->after($endOfNextMonth)) { $date->setDay($endOfNextMonth->getDay()); $date->setMonth($endOfNextMonth->getMonth()); $date->setYear($endOfNextMonth->getYear()); } } } else { if ($rangeValue == 'year') { $date->setYear($date->getYear() + $range); } else { if ($rangeValue == 'hour') { $date->addSeconds($range * 3600); } else { if ($rangeValue == 'minute') { $date->addSeconds($range * 60); } else { $date->addSeconds($range * 86400); } } } } } else { if ($range < 0) { if ($rangeValue == 'month') { for ($i = 0; $i > $range; $i--) { $endOfPrevMonth = new \TYPO3\CMS\Cal\Model\CalDate(Calc::endOfPrevMonth($date->getDay(), $date->getMonth(), $date->getYear())); $days = Calc::daysInMonth($endOfPrevMonth->getMonth(), $endOfPrevMonth->getYear()); $date->subtractSeconds(60 * 60 * 24 * $days); } } else { if ($rangeValue == 'year') { $date->setYear($date->getYear() - abs($range)); } else { if ($rangeValue == 'hour') { $date->subtractSeconds(abs($range) * 3600); } else { if ($rangeValue == 'minute') { $date->subtractSeconds(abs($range) * 60); } else { $date->subtractSeconds(abs($range) * 86400); } } } } } } } } $date->subtractSeconds(1); }
/** * Draws the month view * @param $page string The page template * @param $offset integer The month offset. Default = +0 * @param $type integer The date of the event * @return string The HTML output. */ function _draw_month($page, $offset = '+0', $type) { $viewTarget = $this->conf['view.']['monthLinkTarget']; $monthTemplate = $this->cObj->getSubpart($page, '###MONTH_TEMPLATE###'); if ($monthTemplate != '') { $loop_wd = $this->cObj->getSubpart($monthTemplate, '###LOOPWEEKDAY###'); $t_month = $this->cObj->getSubpart($monthTemplate, '###SWITCHMONTHDAY###'); $startweek = $this->cObj->getSubpart($monthTemplate, '###LOOPMONTHWEEKS_DAYS###'); $endweek = $this->cObj->getSubpart($monthTemplate, '###LOOPMONTHDAYS_WEEKS###'); $weeknum = $this->cObj->getSubpart($monthTemplate, '###LOOPWEEK_NUMS###'); $corner = $this->cObj->getSubpart($monthTemplate, '###CORNER###'); /* 11.12.2008 Franz: * why is there a limitation that only MEDIUM calendar sheets can have absolute offsets and vice versa? * I'm commenting this out and make it more flexible. */ #if ($type != 'medium') { // old one if (preg_match('![+|-][0-9]{1,2}!is', $offset)) { // new one $fake_getdate_time = new \TYPO3\CMS\Cal\Model\CalDate(); $fake_getdate_time->copy($this->controller->getDateTimeObject); $fake_getdate_time->setDay(15); if (intval($offset) < 0) { $fake_getdate_time->subtractSeconds(abs(intval($offset)) * 2592000); } else { $fake_getdate_time->addSeconds(intval($offset) * 2592000); } } else { $fake_getdate_time = new \TYPO3\CMS\Cal\Model\CalDate(); $fake_getdate_time->copy($this->controller->getDateTimeObject); $fake_getdate_time->setDay(15); $fake_getdate_time->setMonth($offset); } $minical_month = $fake_getdate_time->getMonth(); $minical_year = $fake_getdate_time->getYear(); $today = new \TYPO3\CMS\Cal\Model\CalDate(); $month_title = $fake_getdate_time->format($this->conf['view.'][$viewTarget . '.']['dateFormatMonth']); $this->initLocalCObject(); $this->local_cObj->setCurrentVal($month_title); $this->local_cObj->data['view'] = $viewTarget; $this->controller->getParametersForTyposcriptLink($this->local_cObj->data, array('getdate' => $fake_getdate_time->format('%Y%m%d'), 'view' => $viewTarget, $this->pointerName => NULL), $this->conf['cache'], $this->conf['clear_anyway'], $this->conf['view.'][$viewTarget . '.'][$viewTarget . 'ViewPid']); $month_title = $this->local_cObj->cObjGetSingle($this->conf['view.'][$viewTarget . '.'][$viewTarget . 'ViewLink'], $this->conf['view.'][$viewTarget . '.'][$viewTarget . 'ViewLink.']); $month_date = $fake_getdate_time->format('%Y%m%d'); $view_array = array(); if (!$this->viewarray) { $this->eventArray = array(); if (!empty($this->master_array)) { // use array keys for the loop in order to be able to use referenced events instead of copies and save some memory $masterArrayKeys = array_keys($this->master_array); foreach ($masterArrayKeys as $dateKey) { $dateArray =& $this->master_array[$dateKey]; $dateArrayKeys = array_keys($dateArray); foreach ($dateArrayKeys as $timeKey) { $arrayOfEvents =& $dateArray[$timeKey]; $eventKeys = array_keys($arrayOfEvents); foreach ($eventKeys as $eventKey) { $event =& $arrayOfEvents[$eventKey]; $eventReferenceKey = $dateKey . '_' . $event->getType() . '_' . $event->getUid() . '_' . $event->getStart()->format('%Y%m%d%H%M%S'); $this->eventArray[$eventReferenceKey] =& $event; $starttime = new \TYPO3\CMS\Cal\Model\CalDate(); $starttime->copy($event->getStart()); $endtime = new \TYPO3\CMS\Cal\Model\CalDate(); $endtime->copy($event->getEnd()); if ($timeKey == '-1') { $endtime->addSeconds(1); // needed to let allday events show up } $j = new \TYPO3\CMS\Cal\Model\CalDate(); $j->copy($starttime); $j->setHour(0); $j->setMinute(0); $j->setSecond(0); for (; $j->before($endtime); $j->addSeconds(60 * 60 * 24)) { $view_array[$j->format('%Y%m%d')]['000000'][count($view_array[$j->format('%Y%m%d')]['000000'])] = $eventReferenceKey; } } } } } $this->viewarray =& $view_array; } $monthTemplate = str_replace('###MONTH_TITLE###', $month_title, $monthTemplate); $langtype = $this->conf['view.']['month.']['weekdayFormat' . ucwords($type) . 'Month']; $typeSize = intval($this->conf['view.']['month.']['weekdayLength' . ucwords($type) . 'Month']); $dateOfWeek = Calc::beginOfWeek(15, $fake_getdate_time->getMonth(), $fake_getdate_time->getYear()); $start_day = new \TYPO3\CMS\Cal\Model\CalDate($dateOfWeek . '000000'); // backwardscompatibility with old templates if (!empty($corner)) { $weekday_loop .= str_replace('###ADDITIONAL_CLASSES###', $this->conf['view.']['month.']['monthCornerStyle'], $corner); } else { $weekday_loop .= sprintf($weeknum, $this->conf['view.']['month.']['monthCornerStyle'], ''); } for ($i = 0; $i < 7; $i++) { $weekday = $start_day->format($langtype); $weekdayLong = $start_day->format('%A'); if ($typeSize) { $weekday = $this->cs_convert->substr(\TYPO3\CMS\Cal\Utility\Functions::getCharset(), $weekday, 0, $typeSize); } $start_day->addSeconds(86400); $additionalClasses = trim(sprintf($this->conf['view.']['month.']['monthDayOfWeekStyle'], $start_day->format('%w'))); $markerArray = array('###WEEKDAY###' => $weekday, '###WEEKDAY_LONG###' => $weekdayLong, '###ADDITIONAL_CLASSES###' => ' ' . $additionalClasses, '###CLASSES###' => !empty($additionalClasses) ? ' class="' . $additionalClasses . '" ' : ''); $weekday_loop .= strtr($loop_wd, $markerArray); } $weekday_loop .= $endweek; $dateOfWeek = Calc::beginOfWeek(1, $fake_getdate_time->getMonth(), $fake_getdate_time->getYear()); $endOfMonth = $this->controller->getListViewTime('monthend', $start_day); $start_day = new \TYPO3\CMS\Cal\Model\CalDate($dateOfWeek . '000000'); $start_day->setTZbyID('UTC'); $i = 0; $whole_month = TRUE; $isAllowedToCreateEvent = $this->rightsObj->isAllowedToCreateEvent(); $createOffset = intval($this->conf['rights.']['create.']['event.']['timeOffset']) * 60; $getdate = new \TYPO3\CMS\Cal\Model\CalDate($this->conf['getdate']); $getdate->setTZbyID('UTC'); $startWeekTime = \TYPO3\CMS\Cal\Controller\Calendar::calculateStartWeekTime($getdate); $endWeekTime = \TYPO3\CMS\Cal\Controller\Calendar::calculateEndWeekTime($getdate); $formattedWeekStartTime = $startWeekTime->format('%Y%m%d'); $formattedWeekEndTime = $endWeekTime->format('%Y%m%d'); do { $daylink = new \TYPO3\CMS\Cal\Model\CalDate(); $daylink->copy($start_day); $formatedGetdate = $daylink->format('%Y%m%d'); $formatedDayDate = $daylink->format($this->conf['view.']['month.']['dateFormatDay']); $isCurrentWeek = false; $isSelectedWeek = false; if ($formatedGetdate >= $formattedWeekStartTime && $formatedGetdate <= $formattedWeekEndTime) { $isSelectedWeek = true; } if ($start_day->format('%Y%U') == $today->format('%Y%U')) { $isCurrentWeek = true; } if ($i == 0 && !empty($weeknum)) { $start_day->addSeconds(86400); $num = $numPlain = $start_day->getWeekOfYear(); $hasEvent = false; $start_day->subtractSeconds(86400); for ($j = 0; $j < 7; $j++) { if (is_array($this->viewarray[$start_day->format('%Y%m%d')]) || $isAllowedToCreateEvent) { $hasEvent = true; break; } $start_day->addSeconds(86400); } $start_day->copy($daylink); $weekLinkViewTarget = $this->conf['view.']['weekLinkTarget']; if (($this->rightsObj->isViewEnabled($weekLinkViewTarget) || $this->conf['view.'][$weekLinkViewTarget . '.'][$weekLinkViewTarget . 'ViewPid']) && $hasEvent) { $this->initLocalCObject(); $this->local_cObj->setCurrentVal($num); $this->local_cObj->data['view'] = $weekLinkViewTarget; $this->controller->getParametersForTyposcriptLink($this->local_cObj->data, array('getdate' => $formatedGetdate, 'view' => $weekLinkViewTarget, $this->pointerName => NULL), $this->conf['cache'], $this->conf['clear_anyway'], $this->conf['view.'][$weekLinkViewTarget . '.'][$weekLinkViewTarget . 'ViewPid']); $num = $this->local_cObj->cObjGetSingle($this->conf['view.'][$weekLinkViewTarget . '.'][$weekLinkViewTarget . 'ViewLink'], $this->conf['view.'][$weekLinkViewTarget . '.'][$weekLinkViewTarget . 'ViewLink.']); } $className = array(); if ($isSelectedWeek && !empty($this->conf['view.']['month.']['monthSelectedWeekStyle'])) { $className[] = $this->conf['view.']['month.']['monthSelectedWeekStyle']; } if ($isCurrentWeek && !empty($this->conf['view.']['month.']['monthCurrentWeekStyle'])) { $className[] = $this->conf['view.']['month.']['monthCurrentWeekStyle']; } if ($hasEvent && !empty($this->conf['view.']['month.']['monthWeekWithEventStyle'])) { $className[] = $this->conf['view.']['month.']['monthWeekWithEventStyle']; } $weekClasses = trim(implode(' ', $className)); $markerArray = array('###ADDITIONAL_CLASSES###' => $weekClasses ? ' ' . $weekClasses : '', '###CLASSES###' => $weekClasses ? ' class="' . $weekClasses . '" ' : '', '###WEEKNUM###' => $num, '###WEEKNUM_PLAIN###' => $numPlain); $middle .= strtr($startweek, $markerArray); // we do this sprintf all only for backwards compatibility with old templates $middle .= strtr(sprintf($weeknum, $markerArray['###ADDITIONAL_CLASSES###'], $num), $markerArray); } $i++; $switch = array('###ALLDAY###' => ''); $check_month = $start_day->getMonth(); $switch['###LINK###'] = $this->getCreateEventLink('month', '', $start_day, $createOffset, $isAllowedToCreateEvent, '', '', $this->conf['view.']['day.']['dayStart']); $style = array(); $dayLinkViewTarget = $this->conf['view.']['dayLinkTarget']; if (($this->rightsObj->isViewEnabled($dayLinkViewTarget) || $this->conf['view.'][$dayLinkViewTarget . '.'][$dayLinkViewTarget . 'ViewPid']) && ($this->viewarray[$formatedGetdate] || $isAllowedToCreateEvent)) { $this->initLocalCObject(); $this->local_cObj->setCurrentVal($formatedDayDate); $this->local_cObj->data['view'] = $dayLinkViewTarget; $this->controller->getParametersForTyposcriptLink($this->local_cObj->data, array('getdate' => $formatedGetdate, 'view' => $dayLinkViewTarget, $this->pointerName => NULL), $this->conf['cache'], $this->conf['clear_anyway'], $this->conf['view.'][$dayLinkViewTarget . '.'][$dayLinkViewTarget . 'ViewPid']); $switch['###LINK###'] .= $this->local_cObj->cObjGetSingle($this->conf['view.'][$dayLinkViewTarget . '.'][$dayLinkViewTarget . 'ViewLink'], $this->conf['view.'][$dayLinkViewTarget . '.'][$dayLinkViewTarget . 'ViewLink.']); if ($switch['###LINK###'] === '') { $switch['###LINK###'] .= $formatedDayDate; } $switch['###LINK###'] = $this->cObj->stdWrap($switch['###LINK###'], $this->conf['view.']['month.'][$type . 'Link_stdWrap.']); } else { $switch['###LINK###'] .= $formatedDayDate; } // add a css class if the current day has a event - regardless if linked or not if ($this->viewarray[$formatedGetdate]) { $style[] = $this->conf['view.']['month.']['eventDayStyle']; } $style[] = $this->conf['view.']['month.']['month' . ucfirst($type) . 'Style']; if ($check_month != $minical_month) { $style[] = $this->conf['view.']['month.']['monthOffStyle']; } if ($start_day->format('%w') == 0 || $start_day->format('%w') == 6) { $style[] = $this->conf['view.']['month.']['monthDayWeekendStyle']; } if ($isSelectedWeek) { $style[] = $this->conf['view.']['month.']['monthDaySelectedWeekStyle']; } if ($formatedGetdate == $this->conf['getdate']) { $style[] = $this->conf['view.']['month.']['monthSelectedStyle']; } if ($isCurrentWeek) { $style[] = $this->conf['view.']['month.']['monthDayCurrentWeekStyle']; } if ($formatedGetdate == $today->format('%Y%m%d')) { $style[] = $this->conf['view.']['month.']['monthTodayStyle']; } if ($this->conf['view.']['month.']['monthDayOfWeekStyle']) { $style[] = sprintf($this->conf['view.']['month.']['monthDayOfWeekStyle'], $start_day->format('%w')); } //clean up empty styles (code beautify) foreach ($style as $key => $classname) { if ($classname == '') { unset($style[$key]); } } // Adds hook for processing of extra month day style markers if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['tx_cal_controller']['extraMonthDayStyleMarkerHook'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['tx_cal_controller']['extraMonthDayStyleMarkerHook'] as $_classRef) { $_procObj =& GeneralUtility::getUserObj($_classRef); if (is_object($_procObj) && method_exists($_procObj, 'extraMonthDayStyleMarkerProcessor')) { $_procObj->extraMonthDayStyleMarkerProcessor($this, $daylink, $switch, $type, $style); } } } $classesDay = implode(' ', $style); $markerArray = array('###STYLE###' => $classesDay, '###ADDITIONAL_CLASSES###' => $classesDay ? ' ' . $classesDay : '', '###CLASSES###' => $classesDay ? ' class="' . $classesDay . '" ' : '', '###DAY_ID###' => $formatedGetdate); $temp = strtr($t_month, $markerArray); $wraped = array(); if ($this->viewarray[$formatedGetdate] && preg_match('!\\###EVENT\\###!is', $t_month)) { foreach ($this->viewarray[$formatedGetdate] as $cal_time => $event_times) { foreach ($event_times as $uid => $eventId) { if ($type == 'large') { $switch['###EVENT###'] .= $this->eventArray[$eventId]->renderEventForMonth(); } else { if ($type == 'medium') { $switch['###EVENT###'] .= $this->eventArray[$eventId]->renderEventForYear(); } else { if ($type == 'small') { $switch['###EVENT###'] .= $this->eventArray[$eventId]->renderEventForMiniMonth(); } } } } } } if (!isset($switch['###EVENT###'])) { $this->initLocalCObject(); $switch['###EVENT###'] = $this->local_cObj->cObjGetSingle($this->conf['view.'][$viewTarget . '.']['event.']['noEventFound'], $this->conf['view.'][$viewTarget . '.']['event.']['noEventFound.']); } if (!isset($switch['###ALLDAY###'])) { $this->initLocalCObject(); $switch['###ALLDAY###'] = $this->local_cObj->cObjGetSingle($this->conf['view.'][$viewTarget . '.']['event.']['noEventFound'], $this->conf['view.'][$viewTarget . '.']['event.']['noEventFound.']); } // Adds hook for processing of extra month day markers if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['tx_cal_controller']['extraMonthDayMarkerHook'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['tx_cal_controller']['extraMonthDayMarkerHook'] as $_classRef) { $_procObj =& GeneralUtility::getUserObj($_classRef); if (is_object($_procObj) && method_exists($_procObj, 'extraMonthDayMarkerProcessor')) { $switch = $_procObj->extraMonthDayMarkerProcessor($this, $daylink, $switch, $type); } } } $middle .= \TYPO3\CMS\Cal\Utility\Functions::substituteMarkerArrayNotCached($temp, $switch, array(), $wraped); $start_day->addSeconds(86400); // 60 * 60 *24 -> strtotime('+1 day', $start_day); if ($i == 7) { $i = 0; $middle .= $endweek; $checkagain = $start_day->getMonth(); if ($checkagain != $minical_month) { $whole_month = FALSE; } } } while ($whole_month == TRUE); $rems['###LOOPWEEKDAY###'] = $weekday_loop; $rems['###LOOPMONTHWEEKS###'] = $middle; $rems['###LOOPMONTHWEEKS_DAYS###'] = ''; $rems['###LOOPWEEK_NUMS###'] = ''; $rems['###CORNER###'] = ''; $monthTemplate = \TYPO3\CMS\Cal\Utility\Functions::substituteMarkerArrayNotCached($monthTemplate, array(), $rems, array()); $monthTemplate .= $ajaxEvents; $page = \TYPO3\CMS\Cal\Utility\Functions::substituteMarkerArrayNotCached($page, array(), array('###MONTH_TEMPLATE###' => $monthTemplate), array()); } $listTemplate = $this->cObj->getSubpart($page, '###LIST###'); if ($listTemplate != '') { $tx_cal_listview =& GeneralUtility::makeInstanceService('cal_view', 'list', 'list'); $starttime = gmmktime(0, 0, 0, $this_month, 1, $this_year); $endtime = gmmktime(0, 0, 0, $this_month + 1, 1, $this_year); $rems['###LIST###'] = $tx_cal_listview->drawList($this->master_array, $listTemplate, $starttime, $endtime); } $return = \TYPO3\CMS\Cal\Utility\Functions::substituteMarkerArrayNotCached($page, array(), $rems, array()); if ($this->rightsObj->isViewEnabled($viewTarget) || $this->conf['view.'][$viewTarget . '.'][$viewTarget . 'ViewPid']) { $this->initLocalCObject(); $this->local_cObj->setCurrentVal($month_title); $this->local_cObj->data['view'] = $viewTarget; $this->controller->getParametersForTyposcriptLink($this->local_cObj->data, array('getdate' => $month_date, 'view' => $viewTarget, $this->pointerName => NULL), $this->conf['cache'], $this->conf['clear_anyway'], $this->conf['view.'][$viewTarget . '.'][$viewTarget . 'ViewPid']); $month_link = $this->local_cObj->cObjGetSingle($this->conf['view.'][$viewTarget . '.'][$viewTarget . 'ViewLink'], $this->conf['view.'][$viewTarget . '.'][$viewTarget . 'ViewLink.']); } else { $month_link = $month_title; } $return = str_replace('###MONTH_LINK###', $month_link, $return); return $return; }
function processObject(&$event, &$cal_time, &$firstEventDate) { $eventStart = $event->getStart(); $eventEnd = $event->getEnd(); if ($eventEnd->before($this->starttime) || $eventStart->after($this->endtime)) { return; } /* If we haven't saved an event date already, save this one */ if (!$firstEventDate) { $firstEventDate = new \TYPO3\CMS\Cal\Model\CalDate(); if ($this->reverse) { $firstEventDate->copy($eventEnd); } else { $firstEventDate->copy($eventStart); } } /* Always save the current event date as the last one and let it fall through */ if ($this->reverse) { $lastEventDate = $eventStart; } else { $lastEventDate = $eventEnd; } $year = $eventStart->getYear(); $month = $eventStart->getMonth(); $day = $eventStart->getDay(); $week = $eventStart->getWeekOfYear(); $this->eventCounter['byDate'][$year][$month][$day]['total']++; $this->eventCounter['byWeek'][$week]['total']++; $this->eventCounter['byYear'][$year]['total']++; $this->eventCounter['byMonth'][$month]['total']++; $this->eventCounter['byDay'][$day]['total']++; $this->eventCounter['byYearMonth'][$year][$month]['total']++; $this->eventCounter['byYearDay'][$year][$day]['total']++; // Pagebrowser if ($this->conf['view.']['list.']['pageBrowser.']['usePageBrowser']) { if ($this->count < $this->recordsPerPage * $this->offset) { $this->eventCounter['byDate'][$year][$month][$day]['previousPages']++; $this->eventCounter['byWeek'][$week]['previousPages']++; $this->eventCounter['byYear'][$year]['previousPages']++; $this->eventCounter['byMonth'][$month]['previousPages']++; $this->eventCounter['byYearMonth'][$year][$month]['previousPages']++; $this->eventCounter['byDay'][$day]['previousPages']++; $this->eventCounter['byYearDay'][$year][$day]['previousPages']++; } else { if ($this->count > $this->recordsPerPage * $this->offset + $this->recordsPerPage - 1) { $this->eventCounter['byDate'][$year][$month][$day]['nextPages']++; $this->eventCounter['byWeek'][$week]['nextPages']++; $this->eventCounter['byYear'][$year]['nextPages']++; $this->eventCounter['byMonth'][$month]['nextPages']++; $this->eventCounter['byYearMonth'][$year][$month]['nextPages']++; $this->eventCounter['byDay'][$day]['nextPages']++; $this->eventCounter['byYearDay'][$year][$day]['nextPages']++; } else { $this->eventCounter['byDate'][$year][$month][$day]['currentPage']++; $this->eventCounter['byWeek'][$week]['currentPage']++; $this->eventCounter['byYear'][$year]['currentPage']++; $this->eventCounter['byMonth'][$month]['currentPage']++; $this->eventCounter['byYearMonth'][$year][$month]['currentPage']++; $this->eventCounter['byDay'][$day]['currentPage']++; $this->eventCounter['byYearDay'][$year][$day]['currentPage']++; } } if ($this->count < $this->recordsPerPage * $this->offset || $this->count > $this->recordsPerPage * $this->offset + $this->recordsPerPage - 1) { $this->count++; if ($this->count == intval($this->conf['view.']['list.']['maxEvents'])) { $finished = true; } return $finished; } } $GLOBALS['TSFE']->register['cal_list_lastevent'] = $event->getStart()->getTime(); // reference the event in the rendering array $hookObjectsArr = \TYPO3\CMS\Cal\Utility\Functions::getHookObjectsArray('tx_cal_listview', 'sorting', 'view'); if (count($hookObjectsArr)) { foreach ($hookObjectsArr as $hookObj) { if (method_exists($hookObj, 'sorting')) { $hookObj->sorting($this, $cal_time, $event); } } } else { $this->objectsInList[$cal_time][] =& $event; } if ($this->conf['view.']['list.']['showLongEventsInEachWrapper']) { if ($this->conf['view.']['list.']['enableDayWrapper'] && $eventStart->format('%Y%m%d') != $eventEnd->format('%Y%m%d')) { $tempEventStart = new \TYPO3\CMS\Cal\Model\CalDate(); $tempEventStart->copy($eventStart); while ($tempEventStart->format('%Y%m%d') != $eventEnd->format('%Y%m%d')) { $tempEventStart->addSeconds(60 * 60 * 24); $this->objectsInList[$tempEventStart->format('%Y%m%d')][] =& $event; } } if ($this->conf['view.']['list.']['enableWeekWrapper'] && $eventStart->format('%Y%U') != $eventEnd->format('%Y%U')) { $tempEventStart = new \TYPO3\CMS\Cal\Model\CalDate(); $tempEventStart->copy($eventStart); while ($tempEventStart->format('%Y%U') != $eventEnd->format('%Y%U')) { $tempEventStart->addSeconds(60 * 60 * 24 * 7); $this->objectsInList[$tempEventStart->format('%Y%m%d')][] =& $event; } } if ($this->conf['view.']['list.']['enableMonthWrapper'] && $eventStart->format('%Y%m') != $eventEnd->format('%Y%m')) { $tempEventStart = new \TYPO3\CMS\Cal\Model\CalDate(); $tempEventStart->copy($eventStart); while ($tempEventStart->format('%Y%m') != $eventEnd->format('%Y%m')) { $tempEventStart->setMonth($tempEventStart->getMonth() + 1); $this->objectsInList[$tempEventStart->format('%Y%m01')][] =& $event; } } if ($this->conf['view.']['list.']['enableYearWrapper'] && $eventStart->format('%Y') != $eventEnd->format('%Y')) { $tempEventStart = new \TYPO3\CMS\Cal\Model\CalDate(); $tempEventStart->copy($eventStart); while ($tempEventStart->format('%Y') != $eventEnd->format('%Y')) { $tempEventStart->setYear($tempEventStart->getYear() + 1); $this->objectsInList[$tempEventStart->format('%Y0101')][] =& $event; } } } $this->count++; if ($this->count == intval($this->conf['view.']['list.']['maxEvents'])) { $finished = true; } return $finished; }
/** * This function looks, if the event is a recurring event * and creates the recurrings events for a given time. * The starting and ending dates are calculated from the conf * array ('gedate' and 'view'). * * @param $event object * this class (tx_cal_model) */ function recurringEvent($event) { $deviations = array(); $select = '*'; $table = 'tx_cal_event_deviation'; $where = 'parentid = ' . $event->getUid() . $this->cObj->enableFields('tx_cal_event_deviation'); $deviationResult = $GLOBALS['TYPO3_DB']->exec_SELECTquery($select, $table, $where); if ($deviationResult) { while ($deviationRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($deviationResult)) { $origStartDate = new \TYPO3\CMS\Cal\Model\CalDate($deviationRow['orig_start_date']); $origStartDate->addSeconds($deviationRow['orig_start_time']); $deviations[$origStartDate->format('%Y%m%d%H%M%S')] = $deviationRow; } $GLOBALS['TYPO3_DB']->sql_free_result($deviationResult); } $event->setDeviationDates($deviations); $eventStart = $event->getStart(); $eventEnd = $event->getEnd(); $this->filterFalseCombinations($event); $this->checkRecurringSettings($event); $master_array = array(); $until = new \TYPO3\CMS\Cal\Model\CalDate(); $until->copy($event->getUntil()); $until->addSeconds(86399); $rrule_array = $event->getRecurringRule(); $count = intval($event->getCount()); if ($this->endtime->before($until)) { $until->copy($this->endtime); } $byyear = array(); $eventStart = new \TYPO3\CMS\Cal\Model\CalDate(); $eventStart->copy($event->getStart()); $i = $eventStart->getYear(); if ($event->getFreq() == 'year') { $i = intval($this->starttime->getYear()) - ($this->starttime->getYear() - $eventStart->getYear()) % $event->getInterval(); } for (; $i < intval($until->getYear()) + 1; $i++) { $byyear[] = $i; } /* If starttime is before or at the same time as the event date, add the event */ if ($this->starttime->compare($this->starttime, $eventStart) != 1 || $event->getFreq() == 'none') { if ($event->isAllday()) { $master_array[$eventStart->format('%Y%m%d')]['-1'][$event->getUid()] = $event; } else { $master_array[$eventStart->format('%Y%m%d')][$eventStart->format('%H%M')][$event->getUid()] = $event; } } // new feature for limiting f.e. the listed recurring events in listView $maxRecurringEvents = array(); if (TYPO3_MODE != 'BE') { $maxRecurringEvents = (int) $this->conf['view.'][$this->conf['view'] . '.']['maxRecurringEvents']; } $maxRecurringEvents = !empty($maxRecurringEvents) ? $maxRecurringEvents : $count; $counter = 1; $total = 1; // if the 'parent' event is still in future, set $added to 1 (true), because we already have one instance of this event $added = (int) $eventStart->isFuture(); $nextOccuranceTime = new \TYPO3\CMS\Cal\Model\CalDate(); $nextOccuranceTime->copy($event->getStart()); $nextOccuranceTime->addSeconds(86400); if ($event->getRdateType() && $event->getRdateType() != 'none') { $this->getRecurringDate($master_array, $event, $added); } switch ($event->getFreq()) { case 'day': $this->findDailyWithin($master_array, $event, $nextOccuranceTime, $until, $event->getByDay(), $count, $counter, $total, $added, $maxRecurringEvents); break; case 'week': case 'month': case 'year': $bymonth = $event->getByMonth(); $byday = $event->getByDay(); $hour = $eventStart->format('%H'); $minute = $eventStart->format('%M'); // 2007, 2008... foreach ($byyear as $year) { if ($counter < $count && $until->after($nextOccuranceTime) && $added < $maxRecurringEvents) { // 1,2,3,4,5,6,7,8,9,10,11,12 foreach ($bymonth as $month) { if ($counter < $count && $until->after($nextOccuranceTime) && intval(str_pad($year, 2, '0', STR_PAD_LEFT) . str_pad($month, 2, '0', STR_PAD_LEFT)) >= intval($nextOccuranceTime->format('%Y') . $nextOccuranceTime->format('%m')) && $added < $maxRecurringEvents) { $bymonthday = $this->getMonthDaysAccordingly($event, $month, $year); // 1,2,3,4....31 foreach ($bymonthday as $day) { $nextOccuranceTime->setHour($hour); $nextOccuranceTime->setMinute($minute); $nextOccuranceTime->setSecond(0); $nextOccuranceTime->setDay($day); $nextOccuranceTime->setMonth($month); $nextOccuranceTime->setYear($year); if ($counter < $count && ($until->after($nextOccuranceTime) || $until->equals($nextOccuranceTime)) && $added < $maxRecurringEvents) { $currentUntil = new \TYPO3\CMS\Cal\Model\CalDate(); $currentUntil->copy($nextOccuranceTime); $currentUntil->addSeconds(86399); if (intval($nextOccuranceTime->getMonth()) == $month && $eventStart->before($nextOccuranceTime) || $eventStart->equals($nextOccuranceTime)) { $this->findDailyWithin($master_array, $event, $nextOccuranceTime, $currentUntil, $byday, $count, $counter, $total, $added, $maxRecurringEvents); } else { continue; } } else { return $master_array; } } } } } else { return $master_array; } } break; // switch-case break } return $master_array; }
/** * Returns a array with fields/parameters that can be used for link rendering in typoscript. * It's based on the link functions from \TYPO3\CMS\Frontend\Plugin\AbstractPlugin. * * @param * array Referenced array in which the parameters get merged into * @param * array Array with parameter=>value pairs of piVars that should override present piVars * @param * boolean Flag that indicates if the linktarget is allowed to be cached (takes care of cacheHash and no_cache parameter) * @param * boolean Flag that's clearing all present piVars, thus only piVars defined in $overrulePIvars are kept * @param * integer Alternative ID of a page that should be used as link target. If empty or 0, current page is used * @return nothing * */ public function getParametersForTyposcriptLink(&$parameterArray, $overrulePIvars = array(), $cache = false, $clearAnyway = false, $altPageId = 0) { // copied from function 'pi_linkTP_keepPIvars' if (is_array($this->piVars) && is_array($overrulePIvars) && !$clearAnyway) { $piVars = $this->piVars; unset($piVars['DATA']); if (\TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version) < '6002000') { $piVars = GeneralUtility::array_merge_recursive_overrule($piVars, $overrulePIvars); } else { \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($piVars, $overrulePIvars); } $overrulePIvars = $piVars; if ($this->pi_autoCacheEn) { $cache = $this->pi_autoCache($overrulePIvars); } } $piVars = array($this->prefixId => $overrulePIvars); /* TEST */ if ($piVars[$this->prefixId]['getdate']) { $date = new \TYPO3\CMS\Cal\Model\CalDate($piVars[$this->prefixId]['getdate']); $sessionVars = array(); switch ($piVars[$this->prefixId]['view']) { case 'week': $piVars[$this->prefixId]['year'] = $date->getYear(); $piVars[$this->prefixId]['week'] = $date->getWeekOfYear(); $piVars[$this->prefixId]['weekday'] = $date->getDayOfWeek(); $sessionVars['month'] = substr($piVars[$this->prefixId]['getdate'], 4, 2); $sessionVars['day'] = substr($piVars[$this->prefixId]['getdate'], 6, 2); if ($date->getMonth() == 12 && $piVars[$this->prefixId]['week'] == 1) { $piVars[$this->prefixId]['year']++; } unset($piVars[$this->prefixId]['view']); unset($piVars[$this->prefixId]['getdate']); break; case 'event': case 'todo': $piVars[$this->prefixId]['year'] = substr($piVars[$this->prefixId]['getdate'], 0, 4); $piVars[$this->prefixId]['month'] = substr($piVars[$this->prefixId]['getdate'], 4, 2); $piVars[$this->prefixId]['day'] = substr($piVars[$this->prefixId]['getdate'], 6, 2); unset($piVars[$this->prefixId]['getdate']); break; case 'day': $piVars[$this->prefixId]['year'] = substr($piVars[$this->prefixId]['getdate'], 0, 4); $piVars[$this->prefixId]['month'] = substr($piVars[$this->prefixId]['getdate'], 4, 2); $piVars[$this->prefixId]['day'] = substr($piVars[$this->prefixId]['getdate'], 6, 2); case 'month': $piVars[$this->prefixId]['year'] = substr($piVars[$this->prefixId]['getdate'], 0, 4); $piVars[$this->prefixId]['month'] = substr($piVars[$this->prefixId]['getdate'], 4, 2); $sessionVars['day'] = substr($piVars[$this->prefixId]['getdate'], 6, 2); case 'year': $piVars[$this->prefixId]['year'] = substr($piVars[$this->prefixId]['getdate'], 0, 4); $sessionVars['month'] = substr($piVars[$this->prefixId]['getdate'], 4, 2); $sessionVars['day'] = substr($piVars[$this->prefixId]['getdate'], 6, 2); unset($piVars[$this->prefixId]['view']); unset($piVars[$this->prefixId]['getdate']); } foreach ($sessionVars as $key => $value) { //$_SESSION[$this->prefixId][$key] = $value; } } /* TEST */ // use internal method for cleaning up piVars $this->cleanupUrlParameter($piVars); // copied and modified logic of function 'pi_linkTP' # once useCacheHash property in typolinks has stdWrap, we can use this flag - until then it's unfortunately useless :( #$parameterArray['link_useCacheHash'] = $this->pi_USER_INT_obj ? 0 : $cache; $parameterArray['link_no_cache'] = $this->pi_USER_INT_obj ? 0 : !$cache; $parameterArray['link_parameter'] = $altPageId ? $altPageId : ($this->pi_tmpPageId ? $this->pi_tmpPageId : $GLOBALS['TSFE']->id); $parameterArray['link_additionalParams'] = $this->conf['parent.']['addParams'] . GeneralUtility::implodeArrayForUrl('', $piVars, '', true) . $this->pi_moreParams; $parameterArray['link_ATagParams'] = 'class="url"'; # add time/date related parameters to all link objects, so that they can use them e.g. to display the monthname etc. $parameterArray['getdate'] = $this->conf['getdate']; if ($overrulePIvars['getdate'] && is_object($date)) { $parameterArray['link_timestamp'] = $date->getTime(); $parameterArray['link_getdate'] = $overrulePIvars['getdate']; } }
/** * * @param string $dateObject * @return \TYPO3\CMS\Cal\Model\CalDate */ public static function calculateEndMonthTime($dateObject = '') { $timeObj = Calendar::calculateStartDayTime($dateObject); $timeObj = new \TYPO3\CMS\Cal\Model\CalDate(Calc::endOfNextMonth($timeObj->getDay(), $timeObj->getMonth(), $timeObj->getYear())); $timeObj->setDay(1); $timeObj->subtractSeconds(1); $timeObj->setTZbyId('UTC'); return $timeObj; }