/** * If period isn't archived, then it assign var state, var archiveSubPeriod, * and each subperiod values in subPeriodValues array * If period is already archived, true * * @return bool */ function isArchived() { $r = query("SELECT idarchives \n\t\t\t\t\tFROM " . T_ARCHIVES . "\n\t\t\t \t\tWHERE idsite = " . $this->site->getId() . "\n\t\t\t\t\tAND date1 = '" . $this->date->get() . "'\n\t\t\t\t\tAND date2 = '" . $this->date2->get() . "'\n\t\t\t\t\tAND period = " . $this->periodType . "\n\t\t\t\t\tAND done <> " . DB_ARCHIVES_FAIL); // not archived if (mysql_num_rows($r) == 0) { // if YEAR, we use Months for processing if ($this->periodType === DB_ARCHIVES_PERIOD_YEAR) { $this->archiveSubPeriod = new ArchiveMonth($this->site); $a_subPeriod = getDayOfMonthBetween($this->date->get(), $this->date2->get()); } else { $this->archiveSubPeriod = new ArchiveDay($this->site); $a_subPeriod = getDaysBetween($this->date->get(), $this->date2->get()); printDebug("Not archive... launch computation for "); printDebug($a_subPeriod); } foreach ($a_subPeriod as $subPeriod) { // printDebug("<br>avant set date : ".$this->archiveSubPeriod->date->get()); $this->archiveSubPeriod->setDate($subPeriod); //printDebug("<br>apres set date : devrait etre $subPeriod et est ".$this->archiveSubPeriod->date->get()); // if any of the days in period is temp, then the whole period is set to temp if ($this->archiveSubPeriod->state === DB_ARCHIVES_TEMP) { $this->state = DB_ARCHIVES_TEMP; } // store in ->subPeriodValues[] days to compute and select * for each day $l = $this->archiveSubPeriod->getArchived(); // if subperiod is the day, stocke KEY = DATE // else if period, stock KEY = IDARCHIVES // needed for computing nb_uniq_vis if ($this->periodType === DB_ARCHIVES_PERIOD_YEAR) { $key = $l['idarchives']; } else { $key = $subPeriod; } $this->subPeriodValues[$key] = $l; } //printDebug("OK we have all datas<br>"); //printDebug($this->subPeriodValues); return false; } else { printDebug("<u>Period known ! Don't archive</u><br>"); $l = mysql_fetch_assoc($r); $this->idArchives = $l['idarchives']; return true; } }
/** * end QF rules */ function getTemplateArrayMonth($o_minDay, $o_request) { $dateAsked = new Date($o_request->getDate()); $todayDate = getDateFromTimestamp(time()); if ($o_request->getPeriod() == DB_ARCHIVES_PERIOD_YEAR) { $minYear = $o_minDay->getYear(); while ($minYear <= date("Y")) { $return[$minYear . "-07-14"] = $minYear++; // french 14 juillet ! :) } $selected = $dateAsked->getYear() . "-07-14"; } else { $a_months = getDayOfMonthBetween($o_minDay->get(), $todayDate); $selected = $todayDate; foreach ($a_months as $date) { $o_date = new Date($date); if ($o_date->getMonth() == $dateAsked->getMonth() && $o_date->getYear() == $dateAsked->getYear()) { $selected = $date; } $return[$date] = getDateDisplay(5, $o_date); } } return array($return, $selected); }
function getLastArchives($n, $boolOnlyGetPeriodNMinus = 0, $dateTextType = DATE_NORMAL, $o_site = false) { //var_dump($this->archive->date->get()); $date = new Date($this->archive->date->get()); //var_dump($date->get()); if ($o_site) { $o_siteToUse = $o_site; } else { $o_siteToUse = $this->archive->site; } $toArchive = array(); switch ($this->archive->periodType) { case DB_ARCHIVES_PERIOD_DAY: $ts = $date->getTimestamp() + 86400; while (sizeof($toArchive) < $n) { $toArchive[] = getDateFromTimestamp($ts -= 86400); } $typeDateDisplay = 2; $typeDateDisplayGraph = 8; $typeDateDisplayGraphLongAxis = 13; // only take N - x, only for page views comparisons if ($boolOnlyGetPeriodNMinus === 1) { $date0 = $toArchive[0]; $date1 = $toArchive[7]; $date2 = $toArchive[14]; unset($toArchive); $toArchive[] = $date0; $toArchive[] = $date1; $toArchive[] = $date2; $typeDateDisplay = 7; //print("date1 $date1 date2 $date2 "); } break; case DB_ARCHIVES_PERIOD_WEEK: $ts = $date->getTimestamp(); $ts += 86400 * 7; while (sizeof($toArchive) < $n) { $toArchive[] = getDateFromTimestamp($ts -= 86400 * 7); } $typeDateDisplay = 6; $typeDateDisplayGraph = 6; $typeDateDisplayGraphLongAxis = 13; break; case DB_ARCHIVES_PERIOD_MONTH: $s_date1 = getDateFromTimestamp(mktime(23, 59, 59, $date->getMonth() - $n % 12, 15, $date->getYear() - floor($n / 12))); $s_date2 = $date->get(); $toArchive = array_reverse(getDayOfMonthBetween($s_date1, $s_date2)); $typeDateDisplay = 5; $typeDateDisplayGraph = 10; $typeDateDisplayGraphLongAxis = 10; break; case DB_ARCHIVES_PERIOD_YEAR: for ($i = 0; $i < $n; $i++) { $a = $date->getYear() - $i; $toArchive[] = $a . "-01-01"; } $typeDateDisplay = 11; $typeDateDisplayGraph = 12; break; } //var_dump($this->archive->date->get()); $return = array(); foreach ($toArchive as $dateToArchive) { //print("boucle :"); // if day, and IF current date asked is today, then take current archive if ($dateToArchive == $this->archive->date->get() && $this->archive->periodType === DB_ARCHIVES_PERIOD_DAY && $o_siteToUse->getId() === $this->archive->site->getId()) { $a = $this->archive; // erreur possible ici ? } else { $a = $this->getArchive($o_siteToUse, $dateToArchive, $this->archive->periodType); } if ($dateTextType == DATE_GRAPH) { $dateToDisplay = getDateDisplay($typeDateDisplayGraph, new Date($dateToArchive)); $dateComputed = getDateDisplay($typeDateDisplayGraph, $a->date); } else { if ($dateTextType == DATE_NORMAL) { $dateToDisplay = getDateDisplay($typeDateDisplay, new Date($dateToArchive)); $dateComputed = getDateDisplay($typeDateDisplay, $a->date); } else { if ($dateTextType == DATE_GRAPH_LONG_AXIS) { $dateToDisplay = getDateDisplay($typeDateDisplayGraphLongAxis, new Date($dateToArchive)); $dateComputed = getDateDisplay($typeDateDisplayGraphLongAxis, $a->date); } } } if ($this->archive->periodType === DB_ARCHIVES_PERIOD_WEEK) { $firstDayOfWeek = new Date(getFirstDayOfWeek(new Date($dateToArchive))); $minDay = $o_siteToUse->getMinDay(); if ($firstDayOfWeek->getTimestamp() >= $minDay->getTimestamp()) { $dateToDisplay = getDateDisplay($typeDateDisplay, $firstDayOfWeek); } } if ($dateComputed == $dateToDisplay) { // print("$dateToDisplay is correctly computed ($dateComputed)<br>"); $return[$dateComputed] = $a; } else { // print("$dateToDisplay is not correctly computed ($dateComputed) ==> empty archive<br>"); $return[$dateToDisplay] = $this->getEmptyArchive($o_siteToUse, $dateToArchive, $this->archive->periodType); } } //print("\n\n");exit; return $return; }