コード例 #1
0
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param      PropelPDO $con
  * @return     int The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws     PropelException
  * @see        save()
  */
 protected function doSave(PropelPDO $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aCcShowInstances !== null) {
             if ($this->aCcShowInstances->isModified() || $this->aCcShowInstances->isNew()) {
                 $affectedRows += $this->aCcShowInstances->save($con);
             }
             $this->setCcShowInstances($this->aCcShowInstances);
         }
         if ($this->isNew()) {
             $this->modifiedColumns[] = CcShowSchedulePeer::ID;
         }
         // If this object has been modified, then save it to the database.
         if ($this->isModified()) {
             if ($this->isNew()) {
                 $criteria = $this->buildCriteria();
                 if ($criteria->keyContainsValue(CcShowSchedulePeer::ID)) {
                     throw new PropelException('Cannot insert a value for auto-increment primary key (' . CcShowSchedulePeer::ID . ')');
                 }
                 $pk = BasePeer::doInsert($criteria, $con);
                 $affectedRows += 1;
                 $this->setDbId($pk);
                 //[IMV] update autoincrement primary key
                 $this->setNew(false);
             } else {
                 $affectedRows += CcShowSchedulePeer::doUpdate($this, $con);
             }
             $this->resetModified();
             // [HL] After being saved an object is no longer 'modified'
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
コード例 #2
0
ファイル: Shows.php プロジェクト: romansavrulin/Airtime
 private static function populateRepeatingShow($show_id, $next_pop_date, $first_show, $last_show, $start_time, $duration, $day, $record, $end_timestamp, $interval)
 {
     global $CC_DBC;
     if (isset($next_pop_date)) {
         $next_date = $next_pop_date . " " . $start_time;
     } else {
         $next_date = $first_show . " " . $start_time;
     }
     $sql = "SELECT * FROM cc_show_rebroadcast WHERE show_id={$show_id}";
     $rebroadcasts = $CC_DBC->GetAll($sql);
     $show = new Show($show_id);
     $date = new DateHelper();
     $currentTimestamp = $date->getTimestamp();
     while (strtotime($next_date) <= strtotime($end_timestamp) && (strtotime($last_show) > strtotime($next_date) || is_null($last_show))) {
         $start = $next_date;
         $sql = "SELECT timestamp '{$start}' + interval '{$duration}'";
         $end = $CC_DBC->GetOne($sql);
         if ($show->hasInstanceOnDate($start)) {
             $ccShowInstance = $show->getInstanceOnDate($start);
             $newInstance = false;
         } else {
             $ccShowInstance = new CcShowInstances();
             $newInstance = true;
         }
         /* When editing the start/end time of a repeating show, we don't want to
          * change shows that started in the past. So check the start time.
          */
         if ($newInstance || $ccShowInstance->getDbStarts() > $currentTimestamp) {
             $ccShowInstance->setDbShowId($show_id);
             $ccShowInstance->setDbStarts($start);
             $ccShowInstance->setDbEnds($end);
             $ccShowInstance->setDbRecord($record);
             $ccShowInstance->save();
         }
         $show_instance_id = $ccShowInstance->getDbId();
         $showInstance = new ShowInstance($show_instance_id);
         if (!$newInstance) {
             $showInstance->correctScheduleStartTimes();
         }
         foreach ($rebroadcasts as $rebroadcast) {
             $timeinfo = explode(" ", $next_date);
             $sql = "SELECT timestamp '{$timeinfo[0]}' + interval '{$rebroadcast["day_offset"]}' + interval '{$rebroadcast["start_time"]}'";
             $rebroadcast_start_time = $CC_DBC->GetOne($sql);
             $sql = "SELECT timestamp '{$rebroadcast_start_time}' + interval '{$duration}'";
             $rebroadcast_end_time = $CC_DBC->GetOne($sql);
             if ($rebroadcast_start_time > $currentTimestamp) {
                 $newRebroadcastInstance = new CcShowInstances();
                 $newRebroadcastInstance->setDbShowId($show_id);
                 $newRebroadcastInstance->setDbStarts($rebroadcast_start_time);
                 $newRebroadcastInstance->setDbEnds($rebroadcast_end_time);
                 $newRebroadcastInstance->setDbRecord(0);
                 $newRebroadcastInstance->setDbRebroadcast(1);
                 $newRebroadcastInstance->setDbOriginalShow($show_instance_id);
                 $newRebroadcastInstance->save();
             }
         }
         $sql = "SELECT timestamp '{$start}' + interval '{$interval}'";
         $next_date = $CC_DBC->GetOne($sql);
     }
     Show::setNextPop($next_date, $show_id, $day);
     RabbitMq::PushSchedule();
 }
コード例 #3
0
ファイル: Show.php プロジェクト: nidzix/Airtime
 private static function createRebroadcastInstances($p_rebroadcasts, $p_currentUtcTimestamp, $p_showId, $p_showInstanceId, $p_startTime, $p_duration, $p_timezone = null)
 {
     //Y-m-d
     //use only the date part of the show start time stamp for the offsets to work properly.
     $date = explode(" ", $p_startTime);
     $start_date = $date[0];
     foreach ($p_rebroadcasts as $rebroadcast) {
         $days = explode(" ", $rebroadcast["day_offset"]);
         $time = explode(":", $rebroadcast["start_time"]);
         $offset = array("days" => $days[0], "hours" => $time[0], "mins" => $time[1]);
         list($utcStartDateTime, $utcEndDateTime) = Application_Model_Show::createUTCStartEndDateTime($start_date, $p_duration, $p_timezone, $offset);
         if ($utcStartDateTime->format("Y-m-d H:i:s") > $p_currentUtcTimestamp) {
             $newRebroadcastInstance = new CcShowInstances();
             $newRebroadcastInstance->setDbShowId($p_showId);
             $newRebroadcastInstance->setDbStarts($utcStartDateTime);
             $newRebroadcastInstance->setDbEnds($utcEndDateTime);
             $newRebroadcastInstance->setDbRecord(0);
             $newRebroadcastInstance->setDbRebroadcast(1);
             $newRebroadcastInstance->setDbOriginalShow($p_showInstanceId);
             $newRebroadcastInstance->save();
         }
     }
 }
コード例 #4
0
 private function createMonthlyRepeatInstances($showDay, $populateUntil)
 {
     $show_id = $showDay->getDbShowId();
     $first_show = $showDay->getDbFirstShow();
     //non-UTC
     $last_show = $showDay->getDbLastShow();
     //non-UTC
     $duration = $showDay->getDbDuration();
     $day = $showDay->getDbDay();
     $record = $showDay->getDbRecord();
     $timezone = $showDay->getDbTimezone();
     //DateTime local
     $start = $this->getNextRepeatingPopulateStartDateTime($showDay);
     if (isset($last_show)) {
         $end = new DateTime($last_show, new DateTimeZone($timezone));
     } else {
         $end = $populateUntil;
     }
     // We will only need this if the repeat type is MONTHLY_WEEKLY
     list($weekNumberOfMonth, $dayOfWeek) = $this->getMonthlyWeeklyRepeatInterval(new DateTime($first_show, new DateTimeZone($timezone)));
     $this->repeatType = $showDay->getDbRepeatType();
     if ($last_show) {
         $utcLastShowDateTime = new DateTime($last_show, new DateTimeZone($timezone));
         $utcLastShowDateTime->setTimezone(new DateTimeZone("UTC"));
     } else {
         $utcLastShowDateTime = null;
     }
     while ($start->getTimestamp() < $end->getTimestamp()) {
         list($utcStartDateTime, $utcEndDateTime) = $this->createUTCStartEndDateTime($start, $duration);
         /*
          * Make sure start date is less than populate until date AND
          * last show date is null OR start date is less than last show date
          */
         if ($utcStartDateTime->getTimestamp() <= $populateUntil->getTimestamp() && (is_null($utcLastShowDateTime) || $utcStartDateTime->getTimestamp() < $utcLastShowDateTime->getTimestamp())) {
             $lastCreatedShow = clone $utcStartDateTime;
             /* There may not always be an instance when editing a show
              * This will be the case when we are adding a new show day to
              * a repeating show
              */
             if ($this->isUpdate && $this->hasInstance($utcStartDateTime)) {
                 $ccShowInstance = $this->getInstance($utcStartDateTime);
                 $newInstance = false;
                 $updateScheduleStatus = true;
             } else {
                 $newInstance = true;
                 $ccShowInstance = new CcShowInstances();
                 $updateScheduleStatus = false;
             }
             /* When editing the start/end time of a repeating show, we don't want to
              * change shows that started in the past. So check the start time.
              */
             if ($newInstance || $ccShowInstance->getDbStarts() > gmdate("Y-m-d H:i:s")) {
                 $ccShowInstance->setDbShowId($show_id);
                 $ccShowInstance->setDbStarts($utcStartDateTime);
                 $ccShowInstance->setDbEnds($utcEndDateTime);
                 $ccShowInstance->setDbRecord($record);
                 $ccShowInstance->save();
             }
             if ($this->isRebroadcast) {
                 $this->createRebroadcastInstances($showDay, $start, $ccShowInstance->getDbId());
             }
         }
         if ($this->repeatType == REPEAT_MONTHLY_WEEKLY) {
             $monthlyWeeklyStart = new DateTime($utcStartDateTime->format("Y-m"), new DateTimeZone("UTC"));
             $monthlyWeeklyStart->add(new DateInterval("P1M"));
             $start = $this->getNextMonthlyWeeklyRepeatDate($monthlyWeeklyStart, $timezone, $showDay->getDbStartTime(), $weekNumberOfMonth, $dayOfWeek);
         } else {
             $start = $this->getNextMonthlyMonthlyRepeatDate($start, $timezone, $showDay->getDbStartTime());
         }
     }
     $this->setNextRepeatingShowDate($start->format("Y-m-d"), $day, $show_id);
 }