/** * Calculates the first day of the given period depending on the given date. * * For period Weeks: Last day of a week is always sunday * * @param class_date_period_enum $objPeriod * @param class_date $objDate * * @return class_date */ public function lastDayOfThis(class_date_period_enum $objPeriod, class_date $objDate) { $strRelativeString = ""; if ($objPeriod->equals(class_date_period_enum::YEAR())) { $strRelativeString = "last day of december"; } else { if ($objPeriod->equals(class_date_period_enum::HALFYEAR())) { $intMonth = $objDate->getIntMonth(); if ($intMonth < 7) { $strRelativeString = "last day of june"; } else { $strRelativeString = "last day of december"; } } else { if ($objPeriod->equals(class_date_period_enum::QUARTER())) { $intMonth = $objDate->getIntMonth(); if ($intMonth < 4) { $strRelativeString = "last day of march"; } elseif ($intMonth > 3 && $intMonth < 7) { $strRelativeString = "last day of june"; } elseif ($intMonth > 6 && $intMonth < 10) { $strRelativeString = "last day of september"; } elseif ($intMonth > 9) { $strRelativeString = "last day of december"; } } else { if ($objPeriod->equals(class_date_period_enum::MONTH())) { $strRelativeString = "last day of this month"; } else { if ($objPeriod->equals(class_date_period_enum::WEEK())) { if ($objDate->getIntDayOfWeek() == 0) { $strRelativeString = "now"; } else { //check if correct? $strRelativeString = "sunday this week"; } } } } } } $objNewDate = self::calcDateRelativeFormatString($objDate, $strRelativeString); $objNewDate->setIntHour($objDate->getIntHour()); $objNewDate->setIntMin($objDate->getIntMin()); $objNewDate->setIntSec($objDate->getIntSec()); return $objNewDate; }
/** * @return string * @permissions view */ protected function actionRenderCalendar() { $strReturn = ""; $strContent = ""; $arrJsHighlights = array(); $strReturn .= "<content><![CDATA["; /** @var interface_calendarsource_admin[] $arrRelevantModules */ $arrRelevantModules = array(); //fetch modules relevant for processing $arrModules = class_module_system_module::getAllModules(); foreach ($arrModules as $objSingleModule) { if ($objSingleModule->getIntRecordStatus() == 1 && $objSingleModule->getAdminInstanceOfConcreteModule() instanceof interface_calendarsource_admin) { $arrRelevantModules[] = $objSingleModule->getAdminInstanceOfConcreteModule(); } } //the header row $arrWeekdays = explode(",", $this->getLang("calendar_weekday")); foreach ($arrWeekdays as $intKey => $strValue) { $arrWeekdays[$intKey] = trim(uniStrReplace("\"", "", $strValue)); } $strContent .= $this->objToolkit->getCalendarHeaderRow($arrWeekdays); //render the single rows. calculate the first day of the row $objDate = new class_date(); $objDate->setIntDay(1); //set to interval stored in session if ($this->objSession->getSession($this->strStartMonthKey) != "") { $objDate->setIntMonth($this->objSession->getSession($this->strStartMonthKey)); } if ($this->objSession->getSession($this->strStartYearKey) != "") { $objDate->setIntYear($this->objSession->getSession($this->strStartYearKey)); } $intCurMonth = $objDate->getIntMonth(); $intCurYear = $objDate->getIntYear(); $objToday = new class_date(); //start by monday while ($objDate->getIntDayOfWeek() != 1) { $objDate->setPreviousDay(); } $strEntries = ""; $intRowEntryCount = 0; while ($objDate->getIntMonth() <= $intCurMonth && $objDate->getIntYear() <= $intCurYear || $objDate->getIntMonth() == 12 && $objDate->getIntYear() < $intCurYear || $intRowEntryCount % 7 != 0) { $intRowEntryCount++; $strDate = $objDate->getIntDay(); $arrEvents = array(); if ($objDate->getIntMonth() == $intCurMonth) { //Query modules for dates $objStartDate = clone $objDate; $objStartDate->setIntHour(0)->setIntMin(0)->setIntSec(0); $objEndDate = clone $objDate; $objEndDate->setIntHour(23)->setIntMin(59)->setIntSec(59); foreach ($arrRelevantModules as $objOneModule) { $arrEvents = array_merge($objOneModule->getArrCalendarEntries($objStartDate, $objEndDate), $arrEvents); } } while (count($arrEvents) <= 3) { $objDummy = new class_calendarentry(); $objDummy->setStrClass("spacer"); $objDummy->setStrName(" "); $arrEvents[] = $objDummy; } $strEvents = ""; /** @var class_calendarentry $objOneEvent */ foreach ($arrEvents as $objOneEvent) { $strName = $objOneEvent->getStrName(); $strSecondLine = $objOneEvent->getStrSecondLine(); if ($strSecondLine != "") { $strSecondLine = "<br />" . $strSecondLine; } //register mouse-over highlight relations if ($objOneEvent->getStrHighlightId() != "" && $objOneEvent->getStrSystemid() != "") { if (!isset($arrJsHighlights[$objOneEvent->getStrHighlightId()])) { $arrJsHighlights[$objOneEvent->getStrHighlightId()] = array(); } $arrJsHighlights[$objOneEvent->getStrHighlightId()][] = $objOneEvent->getStrSystemid(); } $strEvents .= $this->objToolkit->getCalendarEvent($strName . $strSecondLine, $objOneEvent->getStrSystemid(), $objOneEvent->getStrHighlightId(), $objOneEvent->getStrClass()); } $bitBlocked = false; if ($objDate->getIntDayOfWeek() == 0 || $objDate->getIntDayOfWeek() == 6) { $bitBlocked = true; } $strToday = ""; if ($objToday->getIntYear() == $objDate->getIntYear() && $objToday->getIntMonth() == $objDate->getIntMonth() && $objToday->getIntDay() == $objDate->getIntDay()) { $strToday = " calendarDateToday"; } if ($objDate->getIntMonth() != $intCurMonth) { $strEntries .= $this->objToolkit->getCalendarEntry($strEvents, $strDate, "calendarEntryOutOfRange" . $strToday); } else { if ($bitBlocked) { $strEntries .= $this->objToolkit->getCalendarEntry($strEvents, $strDate, "calendarEntryBlocked" . $strToday); } else { $strEntries .= $this->objToolkit->getCalendarEntry($strEvents, $strDate, "calendarEntry" . $strToday); } } if ($intRowEntryCount % 7 == 0) { $strContent .= $this->objToolkit->getCalendarRow($strEntries); $strEntries = ""; } $objDate->setNextDay(); } if ($strEntries != "") { $strContent .= $this->objToolkit->getCalendarRow($strEntries); } $strReturn .= $this->objToolkit->getCalendarWrapper($strContent); //build js-arrays $strJs = "<script type=\"text/javascript\">"; foreach ($arrJsHighlights as $strCommonId => $arrEntries) { $strJs .= " var kj_cal_" . $strCommonId . " = new Array();"; foreach ($arrEntries as $strOneIdentifier) { $strJs .= "kj_cal_" . $strCommonId . ".push('" . $strOneIdentifier . "');"; } } $strJs .= "</script>"; $strReturn .= $strJs; $strReturn .= "]]></content>"; return $strReturn; }