/** * Compares two dates of type class_date. * * @param class_date $objDateLeft * @param class_date $objDateRight * * @return int * 0, if the dates are equal * 1, if $objDateLeft is greater than $objDateRight * -1, if $objDateLeft is less than $objDateRight * null, if $objDateLeft or $objDateRight are null (then no comparison is possible) */ public static function compareDates(class_date $objDateLeft = null, class_date $objDateRight = null) { if ($objDateLeft != null && $objDateRight != null) { if ($objDateLeft->getLongTimestamp() < $objDateRight->getLongTimestamp()) { return -1; //less; } if ($objDateLeft->getLongTimestamp() > $objDateRight->getLongTimestamp()) { return 1; //greater } else { return 0; //equals } } return null; }
protected function updateValue() { $arrParams = class_carrier::getAllParams(); if (isset($arrParams[$this->getStrEntryName() . "_day"]) && $arrParams[$this->getStrEntryName() . "_day"] != "" || isset($arrParams[$this->getStrEntryName()])) { if (isset($arrParams[$this->getStrEntryName()]) && $arrParams[$this->getStrEntryName()] == "") { $this->setStrValue(null); } else { $objDate = new class_date(); $objDate->generateDateFromParams($this->getStrEntryName(), $arrParams); $this->setStrValue($objDate->getLongTimestamp()); } } else { $this->setStrValue($this->getValueFromObject()); } }
/** * Calculates the number of working days between the given dates. * The start and enddate are included in the count. * * @param class_date $objDateFrom * @param class_date $objDateTo * @return int */ public function calcNumberOfWorkingDaysBetween(class_date $objDateFrom, class_date $objDateTo) { $intNumberOfWorkingDays = 0; if ($objDateFrom->getLongTimestamp() > $objDateTo->getLongTimestamp()) { return $intNumberOfWorkingDays; } if ($objDateFrom->isSameDay($objDateTo)) { return $intNumberOfWorkingDays; } $objDateCompare = clone $objDateFrom; if ($this->isValidTarget2Day($objDateCompare)) { $intNumberOfWorkingDays++; } while ($objDateCompare = $this->calcNextWorkingDay($objDateCompare)) { if ($objDateCompare->getLongTimestamp() > $objDateTo->getLongTimestamp()) { break; } $intNumberOfWorkingDays++; if ($objDateCompare->isSameDay($objDateTo)) { break; } } return $intNumberOfWorkingDays; }
/** * Returns the latest new_value in the date range per systemid * * @param $strClass * @param $strProperty * @param class_date $objDateFrom * @param class_date $objDateTo * @param array $arrAllowedSystemIds * @return array */ public static function getNewValuesForDateRange($strClass, $strProperty, class_date $objDateFrom = null, class_date $objDateTo = null, array $arrAllowedSystemIds) { $arrParams = array($strClass, $strProperty); //system id filter $objRestriction = new class_orm_objectlist_in_restriction("log.change_systemid", $arrAllowedSystemIds); $strQueryCondition = $objRestriction->getStrWhere(); $arrParams = array_merge($arrParams, $objRestriction->getArrParams()); //filter by create date from if ($objDateFrom != null) { $objRestriction = new class_orm_objectlist_restriction("AND ( log.change_date >= ? )", array($objDateFrom->getLongTimestamp())); $strQueryCondition .= $objRestriction->getStrWhere() . " "; $arrParams[] = $objDateFrom->getLongTimestamp(); } //filter by create end to if ($objDateTo != null) { $objRestriction = new class_orm_objectlist_restriction("AND ( log.change_date <= ? )", array($objDateTo->getLongTimestamp())); $strQueryCondition .= $objRestriction->getStrWhere() . " "; $arrParams[] = $objDateTo->getLongTimestamp(); } $strQuery = " SELECT change_systemid,\n change_newvalue\n FROM " . _dbprefix_ . self::getTableForClass($strClass) . " log\n WHERE log.change_class = ?\n AND log.change_property = ?\n {$strQueryCondition}\n ORDER BY log.change_systemid ASC, log.change_date DESC"; $arrResult = class_carrier::getInstance()->getObjDB()->getPArray($strQuery, $arrParams); $arrData = array(); $strLastId = ""; foreach ($arrResult as $arrRow) { if ($strLastId != $arrRow["change_systemid"]) { $arrData[] = array("change_systemid" => $arrRow["change_systemid"], "change_newvalue" => $arrRow["change_newvalue"]); } $strLastId = $arrRow["change_systemid"]; } return $arrData; }
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)); }
/** * Creates a form to edit a users data * * @return string */ private function editUserData() { $arrErrors = array(); $bitForm = true; //what to do? if ($this->getParam("submitUserForm") != "") { if ($this->getParam("password") != "") { if ($this->getParam("password") != $this->getParam("password2")) { $arrErrors[] = $this->getLang("passwordsUnequal"); } } $objValidator = new class_email_validator(); if (!$objValidator->validate($this->getParam("email"))) { $arrErrors[] = $this->getLang("invalidEmailadress"); } if (count($arrErrors) == 0) { $bitForm = false; } } if ($bitForm) { if ($this->arrElementData["portallogin_editmode"] == 1) { $strTemplateID = $this->objTemplate->readTemplate("/element_portallogin/" . $this->arrElementData["portallogin_template"], "portallogin_userdataform_complete"); } else { $strTemplateID = $this->objTemplate->readTemplate("/element_portallogin/" . $this->arrElementData["portallogin_template"], "portallogin_userdataform_minimal"); } $arrTemplate = array(); $objUser = new class_module_user_user($this->objSession->getUserID()); if ($objUser->getObjSourceUser()->isEditable() && $objUser->getStrSubsystem() == "kajona" && $objUser->getObjSourceUser() instanceof class_usersources_user_kajona) { $arrTemplate["username"] = $objUser->getStrUsername(); $arrTemplate["email"] = $objUser->getObjSourceUser()->getStrEmail(); $arrTemplate["forename"] = $objUser->getObjSourceUser()->getStrForename(); $arrTemplate["name"] = $objUser->getObjSourceUser()->getStrName(); $arrTemplate["street"] = $objUser->getObjSourceUser()->getStrStreet(); $arrTemplate["postal"] = $objUser->getObjSourceUser()->getStrPostal(); $arrTemplate["city"] = $objUser->getObjSourceUser()->getStrCity(); $arrTemplate["phone"] = $objUser->getObjSourceUser()->getStrTel(); $arrTemplate["mobile"] = $objUser->getObjSourceUser()->getStrMobile(); $arrTemplate["portallogin_elsystemid"] = $this->arrElementData["content_id"]; $objDate = new class_date($objUser->getObjSourceUser()->getLongDate()); $arrTemplate["date_day"] = $objDate->getIntDay(); $arrTemplate["date_month"] = $objDate->getIntMonth(); $arrTemplate["date_year"] = $objDate->getIntYear(); $arrTemplate["formaction"] = class_link::getLinkPortalHref($this->getPagename(), "", "portalEditProfile"); $arrTemplate["formErrors"] = ""; if (count($arrErrors) > 0) { foreach ($arrErrors as $strOneError) { $strErrTemplate = $this->objTemplate->readTemplate("/element_portallogin/" . $this->arrElementData["portallogin_template"], "errorRow"); $arrTemplate["formErrors"] .= "" . $this->fillTemplate(array("error" => $strOneError), $strErrTemplate); } } return $this->fillTemplate($arrTemplate, $strTemplateID); } else { return "Login provider not supported."; } } else { $objUser = new class_module_user_user($this->objSession->getUserID()); if ($objUser->getObjSourceUser() instanceof class_usersources_user_kajona) { $objUser->getObjSourceUser()->setStrEmail($this->getParam("email")); $objUser->getObjSourceUser()->setStrForename($this->getParam("forename")); $objUser->getObjSourceUser()->setStrName($this->getParam("name")); $objUser->getObjSourceUser()->setStrPass($this->getParam("password")); if ($this->arrElementData["portallogin_editmode"] == 1) { $objUser->getObjSourceUser()->setStrStreet($this->getParam("street")); $objUser->getObjSourceUser()->setStrPostal($this->getParam("postal")); $objUser->getObjSourceUser()->setStrCity($this->getParam("city")); $objUser->getObjSourceUser()->setStrTel($this->getParam("phone")); $objUser->getObjSourceUser()->setStrMobile($this->getParam("mobile")); $objDate = new class_date(); $objDate->setIntDay($this->getParam("date_day")); $objDate->setIntMonth($this->getParam("date_month")); $objDate->setIntYear($this->getParam("date_year")); $objUser->getObjSourceUser()->setLongDate($objDate->getLongTimestamp()); } $objUser->getObjSourceUser()->updateObjectToDb(); } $this->portalReload(class_link::getLinkPortalHref($this->getPagename())); } return ""; }
/** * Returns a list of events available * * @param bool|int $intStart * @param bool|int $intEnd * @param class_date $objStartDate * @param class_Date $objEndDate * @param bool $bitOnlyActive * @param int $intOrder * @param null $intStatusFilter * * @return class_module_eventmanager_event[] */ public static function getAllEvents($intStart = false, $intEnd = false, class_date $objStartDate = null, class_date $objEndDate = null, $bitOnlyActive = false, $intOrder = 0, $intStatusFilter = null) { $objORM = new class_orm_objectlist(); if ($objStartDate != null && $objEndDate != null) { $objORM->addWhereRestriction(new class_orm_objectlist_restriction("AND (system_date_start > ? AND system_date_start <= ?", array($objStartDate->getLongTimestamp(), $objEndDate->getLongTimestamp()))); } if ($intStatusFilter != null) { $objORM->addWhereRestriction(new class_orm_objectlist_restriction("AND em_ev_eventstatus = ?", array($intStatusFilter))); } if ($bitOnlyActive) { $objORM->addWhereRestriction(new class_orm_objectlist_systemstatus_restriction(class_orm_comparator_enum::Equal(), 1)); } $objORM->addOrderBy(new class_orm_objectlist_orderby("system_date_start " . ($intOrder == "1" ? " ASC " : " DESC "))); $objORM->addOrderBy(new class_orm_objectlist_orderby("em_ev_title ASC ")); return $objORM->getObjectList(get_called_class(), "", $intStart, $intEnd); }
/** * 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 testSetBeginningOfDay() { $objDate = new class_date(20150901133737); $objDate->setBeginningOfDay(); $this->assertEquals($objDate->getLongTimestamp(), 20150901000000); }
/** * @return array */ public function getTotalUniqueHostsInInterval() { $objStart = new class_date($this->intDateStart); $objEnd = new class_date($this->intDateEnd); $strQuery = "SELECT log_hostname, COUNT(*) as anzahl\n\t\t\t\t\t\tFROM " . _dbprefix_ . "packageserver_log\n\t\t\t\t\t\tWHERE log_date > ?\n\t\t\t\t\t\t AND log_date <= ?\n\t\t\t\t GROUP BY log_hostname\n\t\t\t\t ORDER BY anzahl DESC"; $arrRow = $this->objDB->getPArray($strQuery, array($objStart->getLongTimestamp(), $objEnd->getLongTimestamp())); return $arrRow; }
/** * Updates a record in the date table. Make sure to use a proper system-id! * Up from Kajona V3.3, the signature changed. Pass instances of class_date instead of * int-values. * * @param string $strSystemid * @param class_date $objStartDate * @param class_date $objEndDate * @param class_date $objSpecialDate * @deprecated use the internal date-objects to have all dates handled automatically * @return bool */ public function updateDateRecord($strSystemid, class_date $objStartDate = null, class_date $objEndDate = null, class_date $objSpecialDate = null) { $intStart = 0; $intEnd = 0; $intSpecial = 0; if ($objStartDate != null && $objStartDate instanceof class_date) { $intStart = $objStartDate->getLongTimestamp(); } if ($objEndDate != null && $objEndDate instanceof class_date) { $intEnd = $objEndDate->getLongTimestamp(); } if ($objSpecialDate != null && $objSpecialDate instanceof class_date) { $intSpecial = $objSpecialDate->getLongTimestamp(); } $strQuery = "UPDATE " . _dbprefix_ . "system_date\n SET system_date_start = ?,\n system_date_end = ?,\n system_date_special = ?\n WHERE system_date_id = ?"; return $this->objDB->_pQuery($strQuery, array($intStart, $intEnd, $intSpecial, $strSystemid)); }
echo str_pad("PServer-Unique", 20); echo "\n"; for ($intYear = 2012; $intYear <= 2014; $intYear++) { for ($intMonth = 1; $intMonth <= 12; $intMonth++) { $objStartDate->setIntDay(1)->setIntMonth($intMonth)->setIntYear($intYear)->setIntHour(0)->setIntMin(0)->setIntSec(1); $objEndDate = clone $objStartDate; $objEndDate->setNextDay(); while ($objEndDate->getIntDay() != 1) { $objEndDate->setNextDay(); } $objEndDate->setPreviousDay()->setIntHour(23)->setIntMin(59)->setIntSec(59); echo str_pad($objStartDate->getIntMonth() . "/" . $objStartDate->getIntYear(), 10); echo str_pad(getHits($objStartDate->getTimeInOldStyle(), $objEndDate->getTimeInOldStyle()), 15, " ", STR_PAD_LEFT); echo str_pad(getVisitors($objStartDate->getTimeInOldStyle(), $objEndDate->getTimeInOldStyle()), 15, " ", STR_PAD_LEFT); echo str_pad(getDownloads($objStartDate->getTimeInOldStyle(), $objEndDate->getTimeInOldStyle()), 15, " ", STR_PAD_LEFT); echo str_pad(getPackageserverRequests($objStartDate->getLongTimestamp(), $objEndDate->getLongTimestamp()), 20, " ", STR_PAD_LEFT); echo str_pad(getUniquePackageserverSystems($objStartDate->getLongTimestamp(), $objEndDate->getLongTimestamp()), 20, " ", STR_PAD_LEFT); echo "\n"; flush(); ob_flush(); } } echo "Total unique installations: \n"; getTotalUniquePackagesererSystems(); function getTotalUniquePackagesererSystems() { $strQuery = "SELECT log_hostname, count(*) AS ANZ\n FROM " . _dbprefix_ . "packageserver_log\n GROUP BY log_hostname\n ORDER BY ANZ DESC "; $intI = 0; foreach (class_carrier::getInstance()->getObjDB()->getPArray($strQuery, array()) as $arrOneRow) { if (uniStrpos($arrOneRow["log_hostname"], "localhost/") === false && uniStrpos($arrOneRow["log_hostname"], "kajona.de") === false && uniStrpos($arrOneRow["log_hostname"], "kajonabase") === false && uniStrpos($arrOneRow["log_hostname"], "aquarium") === false && uniStrpos($arrOneRow["log_hostname"], "stb400s") === false && $arrOneRow["log_hostname"] != "") { echo sprintf("%4d", $arrOneRow["ANZ"]) . " => " . $arrOneRow["log_hostname"] . "<br />";
/** * Generates a long-timestamp of the current time * * @return int */ public static function getCurrentTimestamp() { $objDate = new class_date(); return $objDate->getLongTimestamp(); }
/** * Loads all news from the database * if passed, the filter is used to load the news of the given category * If a start and end value is given, just a section of the list is being loaded * * @param string $strFilter * @param int $intStart * @param int $intEnd * @param class_date $objStartDate * @param class_date $objEndDate * * @return class_module_news_news[] * @static */ public static function getObjectList($strFilter = "", $intStart = null, $intEnd = null, class_date $objStartDate = null, class_date $objEndDate = null) { $arrParams = array(); $strWhere = ""; if ($objStartDate != null && $objEndDate != null) { $strWhere = "AND (system_date_start >= ? and system_date_start < ?) "; $arrParams[] = $objStartDate->getLongTimestamp(); $arrParams[] = $objEndDate->getLongTimestamp(); } $objOrm = new class_orm_objectlist(); $strWhere .= $objOrm->getDeletedWhereRestriction(); if ($strFilter != "") { $strQuery = "SELECT *\n\t\t\t\t\t\t\tFROM " . _dbprefix_ . "news,\n\t\t\t\t\t\t\t " . _dbprefix_ . "system_right,\n\t\t\t\t\t\t\t " . _dbprefix_ . "news_member,\n\t\t\t\t\t\t\t " . _dbprefix_ . "system\n\t\t\t\t\t\tLEFT JOIN " . _dbprefix_ . "system_date\n\t\t\t\t\t\t ON system_id = system_date_id\n\t\t\t\t\t\t\tWHERE system_id = news_id\n\t\t\t\t\t\t\t AND news_id = newsmem_news\n\t\t\t\t\t\t\t AND system_id = right_id\n\t\t\t\t\t\t\t " . $strWhere . "\n\t\t\t\t\t\t\t AND newsmem_category = ?\n\t\t\t\t\t\t\tORDER BY system_date_start DESC"; $arrParams[] = $strFilter; } else { $strQuery = "SELECT *\n\t\t\t\t\t\t\tFROM " . _dbprefix_ . "news,\n\t\t\t\t\t\t\t " . _dbprefix_ . "system_right,\n\t\t\t\t\t\t\t " . _dbprefix_ . "system\n\t\t\t\t\t LEFT JOIN " . _dbprefix_ . "system_date\n\t\t\t\t\t\t ON system_id = system_date_id\n\t\t\t\t\t\t\tWHERE system_id = news_id\n\t\t\t\t\t\t\t AND system_id = right_id\n\t\t\t\t\t\t\t " . $strWhere . "\n\t\t\t\t\t\t\tORDER BY system_date_start DESC"; } $arrIds = class_carrier::getInstance()->getObjDB()->getPArray($strQuery, $arrParams, $intStart, $intEnd); class_orm_rowcache::addArrayOfInitRows($arrIds); $arrReturn = array(); foreach ($arrIds as $arrOneId) { $arrReturn[] = class_objectfactory::getInstance()->getObject($arrOneId["system_id"]); } return $arrReturn; }