/**
  * Gets a running advertisement
  * @param int $block Id of the advertisement block (optional)
  * @return null|Advertisement
  */
 public function getRunningAdvertisement($block = null)
 {
     $time = DateTime::roundTimeToDay();
     $query = $this->createQuery(0);
     $query->addCondition('{dateStart} <= %1% AND %1% < {dateStop}', $time);
     if ($block) {
         $query->addCondition('{blocks.id} = %1%', $block);
     }
     $advertisements = $query->query();
     if (!$advertisements) {
         return null;
     }
     $advertisementKey = array_rand($advertisements);
     return $advertisements[$advertisementKey];
 }
Exemplo n.º 2
0
 /**
  * Creates a search query
  * @param string $queryString The search query
  * @param array $tokens Tokens of the search query
  * @return zibo\library\orm\query\ModelQuery
  */
 private function createSearchQuery($queryString, array $tokens)
 {
     $time = DateTime::roundTimeToDay();
     $query = $this->createQuery(0);
     $query->addCondition('{datePublication} < %1%', $time);
     $query->addCondition('{title} LIKE %1% OR {text} LIKE %1%', '%' . $queryString . '%');
     return $query;
 }
Exemplo n.º 3
0
 /**
  * Gets the time when this job should run next
  * @param int $time if not provided, the last run time will be used or now if this job hasn't run yet
  * @return int
  */
 public function getNextRunTime($time = null)
 {
     if ($time === null) {
         if ($this->lastRunTime) {
             $time = $this->lastRunTime + 1;
         } else {
             $time = time();
         }
     }
     $minute = date('i', $time);
     $hour = date('G', $time);
     $day = date('j', $time);
     $month = date('n', $time);
     $year = date('Y', $time);
     $dayOfWeek = date('w', $time);
     if ($this->minute == self::ASTERIX && $this->hour == self::ASTERIX && $this->day == self::ASTERIX && $this->month == self::ASTERIX && $this->dayOfWeek == self::ASTERIX) {
         $this->addMinute($minute, $hour, $day, $month, $year);
         return mktime($hour, $minute, 0, $month, $day, $year);
     }
     $newHour = $hour;
     $newDay = $day;
     $newMonth = $month;
     $newYear = $year;
     $changed = false;
     $newMinute = $this->getNextRunIntervalValue($this->minute, $minute, null, false);
     if ($newMinute === null) {
         $newMinute = $minute;
         $this->addMinute($newMinute, $newHour, $newDay, $newMonth, $newYear);
     }
     if ($newMinute != $minute) {
         $changed = true;
     }
     $tmpHour = $newHour;
     if ($minute < $newMinute) {
         $newHour = $this->getNextRunIntervalValue($this->hour, $newHour, $newHour, true);
     } else {
         $newHour = $this->getNextRunIntervalValue($this->hour, $newHour, null, false);
     }
     if ($newHour === null) {
         $newHour = $tmpHour;
         if ($newHour == $hour) {
             $this->addHour($newHour, $newDay, $newMonth, $newYear);
         }
     }
     if ($newHour != $hour) {
         $changed = true;
         $newMinute = $this->getFirstRunIntervalValue($this->minute, 0);
     }
     $tmpDay = $newDay;
     if ($newHour < $hour || $newHour == $hour && $newMinute <= $minute) {
         $newDay = $this->getNextRunIntervalValue($this->day, $newDay, null, false);
     } else {
         $newDay = $this->getNextRunIntervalValue($this->day, $newDay, $newDay, true);
     }
     if ($newDay === null) {
         $newDay = $tmpDay;
         if ($newDay == $day) {
             $this->addDay($newDay, $newMonth, $newYear);
         }
     }
     if ($newDay != $day) {
         $changed = true;
         $newMinute = $this->getFirstRunIntervalValue($this->minute, 0);
         $newHour = $this->getFirstRunIntervalValue($this->hour, 0);
     }
     $tmpMonth = $newMonth;
     if ($newDay < $day || $newDay == $day && ($newHour < $hour || $newHour == $hour && $newMinute <= $minute)) {
         $newMonth = $this->getNextRunIntervalValue($this->month, $newMonth, null, false);
     } else {
         $newMonth = $this->getNextRunIntervalValue($this->month, $newMonth, $newMonth, true);
     }
     if ($newMonth == null) {
         $newMonth = $tmpMonth;
         if ($newMonth == $month) {
             $this->addMonth($newMonth, $newYear);
         }
     }
     if ($newMonth != $month) {
         $newMinute = $this->getFirstRunIntervalValue($this->minute, 0);
         $newHour = $this->getFirstRunIntervalValue($this->hour, 0);
         $newDay = $this->getFirstRunIntervalValue($this->day, 1);
     }
     $nextRunTime = mktime($newHour, $newMinute, 0, $newMonth, $newDay, $newYear);
     if ($this->dayOfWeek != self::ASTERIX && !isset($this->dayOfWeek[date('w', $nextRunTime)])) {
         $nextRunTime = DateTime::roundTimeToDay($nextRunTime) + DateTime::DAY - 1;
         return $this->getNextRunTime($nextRunTime);
     }
     return $nextRunTime;
 }
Exemplo n.º 4
0
 /**
  * Check whether this node of these is published
  * @return boolean true if this node is published, false if not
  * @throws zibo\ZiboException when the NodeSettings are not set to this node
  */
 public function isPublished()
 {
     if ($this->isPublished !== null) {
         return $this->isPublished;
     }
     $this->isPublished = $this->get(NodeSettingModel::SETTING_PUBLISH, false);
     if (!$this->isPublished) {
         return $this->isPublished;
     }
     $this->isPublished = false;
     $locale = I18n::getInstance()->getLocale();
     $today = DateTime::roundTimeToDay();
     $publishStart = $this->get(NodeSettingModel::SETTING_PUBLISH_START);
     $publishStop = $this->get(NodeSettingModel::SETTING_PUBLISH_STOP);
     if ($publishStart && $publishStop) {
         $publishStart = $locale->parseDate($publishStart, NodeSettingModel::DATE_FORMAT);
         $publishStop = $locale->parseDate($publishStop, NodeSettingModel::DATE_FORMAT);
         if ($publishStart <= $today && $today < $publishStop) {
             $this->isPublished = true;
         }
     } elseif ($publishStart) {
         $publishStart = $locale->parseDate($publishStart, NodeSettingModel::DATE_FORMAT);
         if ($publishStart <= $today) {
             $this->isPublished = true;
         }
     } elseif ($publishStop) {
         $publishStop = $locale->parseDate($publishStop, NodeSettingModel::DATE_FORMAT);
         if ($today < $publishStop) {
             $this->isPublished = true;
         }
     } else {
         $this->isPublished = true;
     }
     return $this->isPublished;
 }