/** * Calculates the date of easter-sunday for the passed year. * In best cases, this may be done by easter_date, but since this requires a special extension, * we calc the date on our own just to be sure. * * @param $intYear * * @return class_date * @see http://php.net/manual/de/function.easter-date.php#68874 */ private function calcEasterSunday($intYear) { $intMarch21DayOffset = date('z', mktime(0, 0, 0, 3, 21, $intYear)); $intDaysAfterMarch = ((15 + $intYear / 100 - $intYear / 400 - (8 * $intYear / 100 + 13) / 25) % 30 + 19 * ($intYear % 19)) % 30; if ($intDaysAfterMarch == 29) { $intTargetDay = 28; } elseif ($intDaysAfterMarch == 28 && $intYear % 17 >= 11) { $intTargetDay = 27; } else { $intTargetDay = $intDaysAfterMarch; } $intOffset = (2 * ($intYear % 4) + 4 * ($intYear % 7) + 6 * $intTargetDay + (6 + $intYear / 100 - $intYear / 400 - 2) % 7) % 7; $intEasterSundayYearOffset = $intOffset + $intTargetDay + 1 + $intMarch21DayOffset; if ($this->isLeapYear($intYear)) { $intEasterSundayYearOffset -= 1; } //offset per year, so calc back to the current year $objDateTime = DateTime::createFromFormat('z Y', strval($intEasterSundayYearOffset) . ' ' . strval($intYear)); $objDate = new class_date($objDateTime->getTimestamp()); return $objDate->setIntHour(0)->setIntMin(0)->setIntSec(0); }
/** * Loads the list of elements on a single page. * Returns an array of plain data, not the corresponding objects. * In most cases getElementsOnPage is the right way to go. * * * @param string $strPageId * @param bool $bitJustActive * @param string $strLanguage * * @see class_module_pages_pageelement::getElementsOnPage() * @return array */ public static function getPlainElementsOnPage($strPageId, $bitJustActive = false, $strLanguage = "") { //Calculate the current day as a time-stamp. This improves database-caches e.g. the kajona or mysql-query-cache. $objDate = new class_date(); $objDate->setIntMin(0, true); $objDate->setIntSec(0, true); $objDate->setIntHour(0, true); $longToday = $objDate->getLongTimestamp(); $arrParams = array($strPageId, $strLanguage); $objORM = new class_orm_objectlist(); $strAnd = ""; if ($bitJustActive) { $strAnd = "AND system_status = 1\n AND ( system_date_start IS null OR (system_date_start = 0 OR system_date_start <= ?))\n AND ( system_date_end IS null OR (system_date_end = 0 OR system_date_end >= ?)) "; $arrParams[] = $longToday; $arrParams[] = $longToday; } $strQuery = "SELECT *\n FROM " . _dbprefix_ . "page_element,\n " . _dbprefix_ . "element,\n " . _dbprefix_ . "system_right,\n " . _dbprefix_ . "system as system\n LEFT JOIN " . _dbprefix_ . "system_date\n ON (system_id = system_date_id)\n WHERE system_prev_id= ?\n AND page_element_ph_element = element_name\n AND system_id = page_element_id\n AND system_id = right_id\n AND page_element_ph_language = ?\n " . $strAnd . "\n " . $objORM->getDeletedWhereRestriction() . "\n ORDER BY page_element_ph_placeholder ASC,\n page_element_ph_language ASC,\n system_sort ASC"; $arrReturn = class_carrier::getInstance()->getObjDB()->getPArray($strQuery, $arrParams); foreach ($arrReturn as $arrOneRow) { class_orm_rowcache::addSingleInitRow($arrOneRow); } return $arrReturn; }
public function testChangelogIntervalChanges() { $strSystemid = generateSystemid(); $objStartDate = new class_date(); $objEndDate = new class_date(); $objMiddleDate = new class_date(); $objStartDate->setIntYear(2012)->setIntMonth(10)->setIntDay(1)->setIntHour(10)->setIntMin(0)->setIntSec(0); $objMiddleDate->setIntYear(2012)->setIntMonth(11)->setIntDay(1)->setIntHour(10)->setIntMin(0)->setIntSec(0); $objEndDate->setIntYear(2012)->setIntMonth(12)->setIntDay(1)->setIntHour(10)->setIntMin(0)->setIntSec(0); $objChanges = new class_module_system_changelog(); $objChanges->createLogEntry(new dummyObject($strSystemid), 1); $objChanges->processCachedInserts(); $strQuery = "INSERT INTO " . _dbprefix_ . "changelog\n (change_id,\n change_date,\n change_systemid,\n change_system_previd,\n change_user,\n change_class,\n change_action,\n change_property,\n change_oldvalue,\n change_newvalue) VALUES\n (?,?,?,?,?,?,?,?,?,?)"; class_carrier::getInstance()->getObjDB()->_pQuery($strQuery, array(generateSystemid(), $objStartDate->getLongTimestamp(), $strSystemid, "", "", "dummyObject", "edit", "test2", "", "1")); class_carrier::getInstance()->getObjDB()->_pQuery($strQuery, array(generateSystemid(), $objMiddleDate->getLongTimestamp(), $strSystemid, "", "", "dummyObject", "edit", "test2", "1", "2")); class_carrier::getInstance()->getObjDB()->_pQuery($strQuery, array(generateSystemid(), $objEndDate->getLongTimestamp(), $strSystemid, "", "", "dummyObject", "edit", "test2", "2", "3")); //start middle end // 1 2 3 $objStartDate->setIntDay(2); $objEndDate->setIntHour(9); class_module_system_changelog::changeValueForInterval($strSystemid, "edit", "test2", "", "dummyObject", "", "a", $objStartDate, $objEndDate); $objStartDate->setIntDay(1); $this->assertEquals("1", $objChanges->getValueForDate($strSystemid, "test2", $objStartDate)); $objStartDate->setIntDay(2); $this->assertEquals("a", $objChanges->getValueForDate($strSystemid, "test2", $objStartDate)); $this->assertEquals("a", $objChanges->getValueForDate($strSystemid, "test2", $objMiddleDate)); $objEndDate->setIntHour(8); $this->assertEquals("a", $objChanges->getValueForDate($strSystemid, "test2", $objEndDate)); $objEndDate->setIntHour(9); $this->assertEquals("2", $objChanges->getValueForDate($strSystemid, "test2", $objEndDate)); $objEndDate->setIntHour(11); $this->assertEquals("3", $objChanges->getValueForDate($strSystemid, "test2", $objEndDate)); }
/** * This method is called, when the widget should generate it's content. * Return the complete content using the methods provided by the base class. * Do NOT use the toolkit right here! * * @return string */ public function getWidgetOutput() { $strReturn = ""; if (!class_module_system_module::getModuleByName("stats")->rightView()) { return $this->getLang("commons_error_permissions"); } $objStatsCommon = new class_stats_report_common(class_carrier::getInstance()->getObjDB(), class_carrier::getInstance()->getObjToolkit("admin"), class_carrier::getInstance()->getObjLang()); //check wich infos to produce if ($this->getFieldValue("current") == "checked") { $strReturn .= $this->getLang("stats_online") . $objStatsCommon->getNumberOfCurrentUsers(); $strReturn .= $this->widgetSeparator(); } if ($this->getFieldValue("chart") == "checked") { //load the last view days $objDate = new class_date(); $objDate->setIntHour(0); $objDate->setIntMin(0); $objDate->setIntSec(0); $arrHits = array(); $arrLabels = array(); for ($intI = 0; $intI < 7; $intI++) { $objEndDate = clone $objDate; $objEndDate->setNextDay(); $objStatsCommon->setStartDate($objDate->getTimeInOldStyle()); $objStatsCommon->setEndDate($objEndDate->getTimeInOldStyle()); $arrHits[] = $objStatsCommon->getHits(); $arrLabels[] = $objDate->getIntDay(); $objDate->setPreviousDay(); } $arrHits = array_reverse($arrHits); $arrLabels = array_reverse($arrLabels); $strReturn .= $this->widgetText($this->getLang("stats_hits")); $objChart = class_graph_factory::getGraphInstance(); $objChart->setArrXAxisTickLabels($arrLabels); $objChart->addLinePlot($arrHits, ""); $objChart->setBitRenderLegend(false); $objChart->setIntHeight(220); $objChart->setIntWidth(300); $objChart->setStrXAxisTitle(""); $objChart->setStrYAxisTitle(""); $strReturn .= $objChart->renderGraph(); } if ($this->getFieldValue("day") == "checked") { //current day: //pass date to commons-object $objDate = new class_date(); $objDate->setIntHour(0); $objDate->setIntMin(0); $objDate->setIntSec(0); $strReturn .= $this->widgetText(dateToString($objDate, false)); $objStatsCommon->setStartDate($objDate->getTimeInOldStyle()); $objDate->setNextDay(); $objStatsCommon->setEndDate($objDate->getTimeInOldStyle()); $strReturn .= $this->widgetText($this->getLang("stats_hits") . " " . $objStatsCommon->getHits()); $strReturn .= $this->widgetText($this->getLang("stats_visitors") . " " . $objStatsCommon->getVisitors()); $strReturn .= $this->widgetSeparator(); } if ($this->getFieldValue("last") == "checked") { $strReturn .= $this->widgetText($this->getLang("stats_ip") . " " . $this->getLang("stats_page")); $intMaxRecords = $this->getFieldValue("nrLast"); if (!is_numeric($intMaxRecords) || $intMaxRecords > 15) { $intMaxRecords = 15; } $arrRecordsets = class_carrier::getInstance()->getObjDB()->getPArray("SELECT * FROM " . _dbprefix_ . "stats_data ORDER BY stats_date DESC ", array(), 0, $intMaxRecords - 1); foreach ($arrRecordsets as $arrOneRecord) { $strReturn .= $this->widgetText($arrOneRecord["stats_ip"] . " " . $arrOneRecord["stats_page"]); } } return $strReturn; }