Esempio n. 1
0
 private function makeHeaderRow($p_item)
 {
     $row = $this->defaultRowArray;
     //$this->isAllowed($p_item, $row);
     $this->getRowTimestamp($p_item, $row);
     $this->getItemColor($p_item, $row);
     $showStartDT = new DateTime($p_item["si_starts"], new DateTimeZone("UTC"));
     $showStartDT->setTimezone(new DateTimeZone($this->timezone));
     $startsEpoch = floatval($showStartDT->format("U.u"));
     $showEndDT = new DateTime($p_item["si_ends"], new DateTimeZone("UTC"));
     $showEndDT->setTimezone(new DateTimeZone($this->timezone));
     $endsEpoch = floatval($showEndDT->format("U.u"));
     //is a rebroadcast show
     if (intval($p_item["si_rebroadcast"]) === 1) {
         $row["rebroadcast"] = true;
         $parentInstance = CcShowInstancesQuery::create()->findPk($p_item["parent_show"]);
         $name = $parentInstance->getCcShow()->getDbName();
         $dt = $parentInstance->getDbStarts(null);
         $dt->setTimezone(new DateTimeZone($this->timezone));
         $time = $dt->format("Y-m-d H:i");
         $row["rebroadcast_title"] = sprintf(_("Rebroadcast of %s from %s"), $name, $time);
     } elseif (intval($p_item["si_record"]) === 1) {
         $row["record"] = true;
         // at the time of creating on show, the recorded file is not in the DB yet.
         // therefore, 'si_file_id' is null. So we need to check it.
         if (Application_Model_Preference::GetUploadToSoundcloudOption() && isset($p_item['si_file_id'])) {
             $file = Application_Model_StoredFile::RecallById($p_item['si_file_id']);
             if (isset($file)) {
                 $sid = $file->getSoundCloudId();
                 $row['soundcloud_id'] = $sid;
             }
         }
     }
     if ($startsEpoch < $this->epoch_now && $endsEpoch > $this->epoch_now) {
         $row["currentShow"] = true;
         $this->currentShow = true;
     } else {
         $this->currentShow = false;
     }
     $this->isAllowed($p_item, $row);
     $row["header"] = true;
     $row["starts"] = $showStartDT->format("Y-m-d H:i");
     $row["startDate"] = $showStartDT->format("Y-m-d");
     $row["startTime"] = $showStartDT->format("H:i");
     $row["refresh"] = floatval($showStartDT->format("U.u")) - $this->epoch_now;
     $row["ends"] = $showEndDT->format("Y-m-d H:i");
     $row["endDate"] = $showEndDT->format("Y-m-d");
     $row["endTime"] = $showEndDT->format("H:i");
     $row["duration"] = floatval($showEndDT->format("U.u")) - floatval($showStartDT->format("U.u"));
     $row["title"] = htmlspecialchars($p_item["show_name"]);
     $row["instance"] = intval($p_item["si_id"]);
     $row["image"] = '';
     $this->getScheduledStatus($startsEpoch, $endsEpoch, $row);
     $this->contentDT = $showStartDT;
     return $row;
 }
Esempio n. 2
0
 public function editShowAction()
 {
     //1) Get add_show_start_date since it might not have been sent
     $js = $this->_getParam('data');
     $data = array();
     //need to convert from serialized jQuery array.
     foreach ($js as $j) {
         $data[$j["name"]] = $j["value"];
     }
     $data['add_show_hosts'] = $this->_getParam('hosts');
     $data['add_show_day_check'] = $this->_getParam('days');
     if ($data['add_show_day_check'] == "") {
         $data['add_show_day_check'] = null;
     }
     $show = new Application_Model_Show($data['add_show_id']);
     $validateStartDate = true;
     $validateStartTime = true;
     if (!array_key_exists('add_show_start_date', $data)) {
         //Changing the start date was disabled, since the
         //array key does not exist. We need to repopulate this entry from the db.
         //The start date will be returned in UTC time, so lets convert it to local time.
         $dt = Application_Common_DateHelper::ConvertToLocalDateTime($show->getStartDateAndTime());
         $data['add_show_start_date'] = $dt->format("Y-m-d");
         if (!array_key_exists('add_show_start_time', $data)) {
             $data['add_show_start_time'] = $dt->format("H:i");
             $validateStartTime = false;
         }
         $validateStartDate = false;
     }
     $data['add_show_record'] = $show->isRecorded();
     $origianlShowStartDateTime = Application_Common_DateHelper::ConvertToLocalDateTime($show->getStartDateAndTime());
     $success = Application_Model_Schedule::addUpdateShow($data, $this, $validateStartDate, $origianlShowStartDateTime, true, $data['add_show_instance_id']);
     if ($success) {
         $scheduler = new Application_Model_Scheduler();
         $showInstances = CcShowInstancesQuery::create()->filterByDbShowId($data['add_show_id'])->find();
         foreach ($showInstances as $si) {
             $scheduler->removeGaps($si->getDbId());
         }
         $this->view->addNewShow = true;
         $this->view->newForm = $this->view->render('schedule/add-show-form.phtml');
     } else {
         if (!$validateStartDate) {
             $this->view->when->getElement('add_show_start_date')->setOptions(array('disabled' => true));
         }
         if (!$validateStartTime) {
             $this->view->when->getElement('add_show_start_time')->setOptions(array('disabled' => true));
         }
         $this->view->rr->getElement('add_show_record')->setOptions(array('disabled' => true));
         $this->view->addNewShow = false;
         $this->view->action = "edit-show";
         $this->view->form = $this->view->render('schedule/add-show-form.phtml');
     }
 }
Esempio n. 3
0
 public function builderDialogAction()
 {
     $request = $this->getRequest();
     $id = $request->getParam("id");
     $instance = CcShowInstancesQuery::create()->findPK($id);
     if (is_null($instance)) {
         $this->view->error = "show does not exist";
         return;
     }
     $start = $instance->getDbStarts(null);
     $start->setTimezone(new DateTimeZone(date_default_timezone_get()));
     $end = $instance->getDbEnds(null);
     $end->setTimezone(new DateTimeZone(date_default_timezone_get()));
     $show_name = $instance->getCcShow()->getDbName();
     $start_time = $start->format("Y-m-d H:i:s");
     $end_time = $end->format("Y-m-d H:i:s");
     $this->view->title = "{$show_name}:    {$start_time} - {$end_time}";
     $this->view->start = $instance->getDbStarts("U");
     $this->view->end = $instance->getDbEnds("U");
     $this->view->dialog = $this->view->render('showbuilder/builderDialog.phtml');
 }
Esempio n. 4
0
 public function getOtherInstances($instanceId)
 {
     return CcShowInstancesQuery::create()->filterByCcShow($this)->filterByDbId($instanceId, Criteria::NOT_EQUAL)->find();
 }
 private function validateHistoryItem($instanceId, $form)
 {
     /*
     $userService = new Application_Service_UserService();
     $currentUser = $userService->getCurrentUser();
     
     if (!$currentUser->isAdminOrPM()) {
         if (empty($instance_id) ) {
     
         }
     }
     */
     $valid = true;
     $recordStartsEl = $form->getElement("his_item_starts");
     $recordStarts = $recordStartsEl->getValue();
     $recordEndsEl = $form->getElement("his_item_starts");
     $recordEnds = $recordEndsEl->getValue();
     $timezoneLocal = new DateTimeZone($this->timezone);
     $startDT = new DateTime($recordStarts, $timezoneLocal);
     $endDT = new DateTime($recordEnds, $timezoneLocal);
     if ($recordStarts > $recordEnds) {
         $valid = false;
         $recordEndsEl->addErrorMessage("End time must be after start time");
     }
     if (isset($instanceId)) {
         $instance = CcShowInstancesQuery::create()->findPk($instanceId, $this->con);
         $inStartsDT = $instance->getDbStarts(null);
         $inEndsDT = $instance->getDbEnds(null);
         if ($startDT < $inStartsDT) {
             $valid = false;
             $form->addErrorMessage("History item begins before show.");
         } else {
             if ($startDT > $inEndsDT) {
                 $valid = false;
                 $form->addErrorMessage("History item begins after show.");
             }
         }
     }
     return $valid;
 }
Esempio n. 6
0
 /**
  * Get the associated CcShowInstances object
  *
  * @param      PropelPDO Optional Connection object.
  * @return     CcShowInstances The associated CcShowInstances object.
  * @throws     PropelException
  */
 public function getCcShowInstances(PropelPDO $con = null)
 {
     if ($this->aCcShowInstances === null && $this->instance_id !== null) {
         $this->aCcShowInstances = CcShowInstancesQuery::create()->findPk($this->instance_id, $con);
         /* The following can be used additionally to
         		   guarantee the related object contains a reference
         		   to this object.  This level of coupling may, however, be
         		   undesirable since it could result in an only partially populated collection
         		   in the referenced object.
         		   $this->aCcShowInstances->addCcSchedules($this);
         		 */
     }
     return $this->aCcShowInstances;
 }
 /**
  * 
  * Returns 2 DateTime objects, in the user's local time,
  * of the next future repeat show instance start and end time
  */
 public function getNextFutureRepeatShowTime()
 {
     $ccShowInstance = CcShowInstancesQuery::create()->filterByDbShowId($this->ccShow->getDbId())->filterByDbModifiedInstance(false)->filterByDbEnds(gmdate("Y-m-d H:i:s"), Criteria::GREATER_THAN)->orderByDbStarts()->limit(1)->findOne();
     $starts = new DateTime($ccShowInstance->getDbStarts(), new DateTimeZone("UTC"));
     $ends = new DateTime($ccShowInstance->getDbEnds(), new DateTimeZone("UTC"));
     $showTimezone = $this->ccShow->getFirstCcShowDay()->getDbTimezone();
     $starts->setTimezone(new DateTimeZone($showTimezone));
     $ends->setTimezone(new DateTimeZone($showTimezone));
     return array($starts, $ends);
 }
 private function validateShowMove($deltaDay, $deltaMin)
 {
     if (!$this->currentUser->isAdminOrPM()) {
         throw new Exception(_("Permission denied"));
     }
     if ($this->ccShow->isRepeating()) {
         throw new Exception(_("Can't drag and drop repeating shows"));
     }
     $today_timestamp = time();
     $startsDateTime = $this->ccShowInstance->getDbStarts(null);
     $endsDateTime = $this->ccShowInstance->getDbEnds(null);
     if ($today_timestamp > $startsDateTime->getTimestamp()) {
         throw new Exception(_("Can't move a past show"));
     }
     //the user is moving the show on the calendar from the perspective of local time.
     //incase a show is moved across a time change border offsets should be added to the localtime
     //stamp and then converted back to UTC to avoid show time changes!
     $showTimezone = $this->ccShow->getFirstCcShowDay()->getDbTimezone();
     $startsDateTime->setTimezone(new DateTimeZone($showTimezone));
     $endsDateTime->setTimezone(new DateTimeZone($showTimezone));
     $duration = $startsDateTime->diff($endsDateTime);
     $newStartsDateTime = self::addDeltas($startsDateTime, $deltaDay, $deltaMin);
     /* WARNING: Do not separately add a time delta to the start and end times because
                    that does not preserve the duration across a DST time change.
                    For example, 5am - 3 hours = 3am when DST occurs at 2am.
                             BUT, 6am - 3 hours = 3am also!
                              So when a DST change occurs, adding the deltas like this
                              separately does not conserve the duration of a show.
                    Since that's what we want (otherwise we'll get a zero length show), 
                    we calculate the show duration FIRST, then we just add that on
                    to the start time to calculate the end time. 
                    This is a safer approach.
                    The key lesson here is that in general: duration != end - start
                    ... so be careful!
        */
     //$newEndsDateTime = self::addDeltas($endsDateTime, $deltaDay, $deltaMin); <--- Wrong, don't do it.
     $newEndsDateTime = clone $newStartsDateTime;
     $newEndsDateTime = $newEndsDateTime->add($duration);
     //convert our new starts/ends to UTC.
     $newStartsDateTime->setTimezone(new DateTimeZone("UTC"));
     $newEndsDateTime->setTimezone(new DateTimeZone("UTC"));
     if ($today_timestamp > $newStartsDateTime->getTimestamp()) {
         throw new Exception(_("Can't move show into past"));
     }
     //check if show is overlapping
     $overlapping = Application_Model_Schedule::checkOverlappingShows($newStartsDateTime, $newEndsDateTime, true, $this->ccShowInstance->getDbId());
     if ($overlapping) {
         throw new Exception(_("Cannot schedule overlapping shows"));
     }
     if ($this->ccShow->isRecorded()) {
         //rebroadcasts should start at max 1 hour after a recorded show has ended.
         $minRebroadcastStart = self::addDeltas($newEndsDateTime, 0, 60);
         //check if we are moving a recorded show less than 1 hour before any of its own rebroadcasts.
         $rebroadcasts = CcShowInstancesQuery::create()->filterByDbOriginalShow($this->ccShow->getDbId())->filterByDbStarts($minRebroadcastStart->format('Y-m-d H:i:s'), Criteria::LESS_THAN)->find();
         if (count($rebroadcasts) > 0) {
             throw new Exception(_("Can't move a recorded show less than 1 hour before its rebroadcasts."));
         }
     }
     if ($this->ccShow->isRebroadcast()) {
         $recordedShow = CcShowInstancesQuery::create()->filterByCcShow($this->ccShowInstance->getDbOriginalShow())->findOne();
         if (is_null($recordedShow)) {
             $this->ccShowInstance->delete();
             throw new Exception(_("Show was deleted because recorded show does not exist!"));
         }
         $recordEndDateTime = new DateTime($recordedShow->getDbEnds(), new DateTimeZone("UTC"));
         $newRecordEndDateTime = self::addDeltas($recordEndDateTime, 0, 60);
         if ($newStartsDateTime->getTimestamp() < $newRecordEndDateTime->getTimestamp()) {
             throw new Exception(_("Must wait 1 hour to rebroadcast."));
         }
     }
     return array($newStartsDateTime, $newEndsDateTime);
 }
Esempio n. 9
0
 public function setRecordedFile($file_id)
 {
     $showInstance = CcShowInstancesQuery::create()->findPK($this->_instanceId);
     $showInstance->setDbRecordedFile($file_id)->save();
     $rebroadcasts = CcShowInstancesQuery::create()->filterByDbOriginalShow($this->_instanceId)->find();
     foreach ($rebroadcasts as $rebroadcast) {
         $rebroad = new ShowInstance($rebroadcast->getDbId());
         $rebroad->addFileToShow($file_id);
     }
 }
 public function emptyShowContent($instanceId)
 {
     try {
         $ccShowInstance = CcShowInstancesQuery::create()->findPk($instanceId);
         $instances = array();
         $instanceIds = array();
         if ($ccShowInstance->getCcShow()->isLinked()) {
             foreach ($ccShowInstance->getCcShow()->getCcShowInstancess() as $instance) {
                 $instanceIds[] = $instance->getDbId();
                 $instances[] = $instance;
             }
         } else {
             $instanceIds[] = $ccShowInstance->getDbId();
             $instances[] = $ccShowInstance;
         }
         /* Get the file ids of the tracks we are about to delete
          * from cc_schedule. We need these so we can update the
          * is_scheduled flag in cc_files
          */
         $ccSchedules = CcScheduleQuery::create()->filterByDbInstanceId($instanceIds, Criteria::IN)->setDistinct(CcSchedulePeer::FILE_ID)->find();
         $fileIds = array();
         foreach ($ccSchedules as $ccSchedule) {
             $fileIds[] = $ccSchedule->getDbFileId();
         }
         /* Clear out the schedule */
         CcScheduleQuery::create()->filterByDbInstanceId($instanceIds, Criteria::IN)->delete();
         /* Now that the schedule has been cleared we need to make
          * sure we do not update the is_scheduled flag for tracks
          * that are scheduled in other shows
          */
         $futureScheduledFiles = Application_Model_Schedule::getAllFutureScheduledFiles();
         foreach ($fileIds as $k => $v) {
             if (in_array($v, $futureScheduledFiles)) {
                 unset($fileIds[$k]);
             }
         }
         $selectCriteria = new Criteria();
         $selectCriteria->add(CcFilesPeer::ID, $fileIds, Criteria::IN);
         $updateCriteria = new Criteria();
         $updateCriteria->add(CcFilesPeer::IS_SCHEDULED, false);
         BasePeer::doUpdate($selectCriteria, $updateCriteria, Propel::getConnection());
         Application_Model_RabbitMq::PushSchedule();
         $con = Propel::getConnection(CcShowInstancesPeer::DATABASE_NAME);
         foreach ($instances as $instance) {
             $instance->updateDbTimeFilled($con);
         }
         return true;
     } catch (Exception $e) {
         Logging::info($e->getMessage());
         return false;
     }
 }
Esempio n. 11
0
    /**
     * Create a show.
     *
     * Note: end dates are non inclusive.
     *
     * @param  array $data
     * @return int
     *     Show ID
     */
    public static function create($data)
    {
        $startDateTime = new DateTime($data['add_show_start_date'] . " " . $data['add_show_start_time']);
        $utcStartDateTime = clone $startDateTime;
        $utcStartDateTime->setTimezone(new DateTimeZone('UTC'));
        if ($data['add_show_no_end']) {
            $endDate = NULL;
        } elseif ($data['add_show_repeats']) {
            $endDateTime = new DateTime($data['add_show_end_date']);
            //$endDateTime->setTimezone(new DateTimeZone('UTC'));
            $endDateTime->add(new DateInterval("P1D"));
            $endDate = $endDateTime->format("Y-m-d");
        } else {
            $endDateTime = new DateTime($data['add_show_start_date']);
            //$endDateTime->setTimezone(new DateTimeZone('UTC'));
            $endDateTime->add(new DateInterval("P1D"));
            $endDate = $endDateTime->format("Y-m-d");
        }
        //What we are doing here is checking if the show repeats or if
        //any repeating days have been checked. If not, then by default
        //the "selected" DOW is the initial day.
        //DOW in local time.
        $startDow = date("w", $startDateTime->getTimestamp());
        if (!$data['add_show_repeats']) {
            $data['add_show_day_check'] = array($startDow);
        } elseif ($data['add_show_repeats'] && $data['add_show_day_check'] == "") {
            $data['add_show_day_check'] = array($startDow);
        }
        //find repeat type or set to a non repeating show.
        $repeatType = $data['add_show_repeats'] ? $data['add_show_repeat_type'] : -1;
        if ($data['add_show_id'] == -1) {
            $ccShow = new CcShow();
        } else {
            $ccShow = CcShowQuery::create()->findPK($data['add_show_id']);
        }
        $ccShow->setDbName($data['add_show_name']);
        $ccShow->setDbDescription($data['add_show_description']);
        $ccShow->setDbUrl($data['add_show_url']);
        $ccShow->setDbGenre($data['add_show_genre']);
        $ccShow->setDbColor($data['add_show_color']);
        $ccShow->setDbBackgroundColor($data['add_show_background_color']);
        $ccShow->setDbLiveStreamUsingAirtimeAuth($data['cb_airtime_auth'] == 1);
        $ccShow->setDbLiveStreamUsingCustomAuth($data['cb_custom_auth'] == 1);
        $ccShow->setDbLiveStreamUser($data['custom_username']);
        $ccShow->setDbLiveStreamPass($data['custom_password']);
        $ccShow->save();
        $showId = $ccShow->getDbId();
        $isRecorded = isset($data['add_show_record']) && $data['add_show_record'] ? 1 : 0;
        if ($data['add_show_id'] != -1) {
            $show = new Application_Model_Show($showId);
            $show->deletePossiblyInvalidInstances($data, $endDate, $isRecorded, $repeatType);
        }
        //check if we are adding or updating a show, and if updating
        //erase all the show's show_days information first.
        if ($data['add_show_id'] != -1) {
            CcShowDaysQuery::create()->filterByDbShowId($data['add_show_id'])->delete();
        }
        //don't set day for monthly repeat type, it's invalid.
        if ($data['add_show_repeats'] && $data['add_show_repeat_type'] == 2) {
            $showDay = new CcShowDays();
            $showDay->setDbFirstShow($startDateTime->format("Y-m-d"));
            $showDay->setDbLastShow($endDate);
            $showDay->setDbStartTime($startDateTime->format("H:i:s"));
            $showDay->setDbTimezone(date_default_timezone_get());
            $showDay->setDbDuration($data['add_show_duration']);
            $showDay->setDbRepeatType($repeatType);
            $showDay->setDbShowId($showId);
            $showDay->setDbRecord($isRecorded);
            $showDay->save();
        } else {
            foreach ($data['add_show_day_check'] as $day) {
                $daysAdd = 0;
                $startDateTimeClone = clone $startDateTime;
                if ($startDow !== $day) {
                    if ($startDow > $day) {
                        $daysAdd = 6 - $startDow + 1 + $day;
                    } else {
                        $daysAdd = $day - $startDow;
                    }
                    $startDateTimeClone->add(new DateInterval("P" . $daysAdd . "D"));
                }
                if (is_null($endDate) || $startDateTimeClone->getTimestamp() <= $endDateTime->getTimestamp()) {
                    $showDay = new CcShowDays();
                    $showDay->setDbFirstShow($startDateTimeClone->format("Y-m-d"));
                    $showDay->setDbLastShow($endDate);
                    $showDay->setDbStartTime($startDateTimeClone->format("H:i"));
                    $showDay->setDbTimezone(date_default_timezone_get());
                    $showDay->setDbDuration($data['add_show_duration']);
                    $showDay->setDbDay($day);
                    $showDay->setDbRepeatType($repeatType);
                    $showDay->setDbShowId($showId);
                    $showDay->setDbRecord($isRecorded);
                    $showDay->save();
                }
            }
        }
        //check if we are adding or updating a show, and if updating
        //erase all the show's future show_rebroadcast information first.
        if ($data['add_show_id'] != -1 && isset($data['add_show_rebroadcast']) && $data['add_show_rebroadcast']) {
            CcShowRebroadcastQuery::create()->filterByDbShowId($data['add_show_id'])->delete();
        }
        //adding rows to cc_show_rebroadcast
        /* TODO: Document magic constant 10 and define it properly somewhere
           --RG */
        if ($isRecorded && $data['add_show_rebroadcast'] && $repeatType != -1) {
            for ($i = 1; $i <= 10; $i++) {
                if ($data['add_show_rebroadcast_date_' . $i]) {
                    $showRebroad = new CcShowRebroadcast();
                    $showRebroad->setDbDayOffset($data['add_show_rebroadcast_date_' . $i]);
                    $showRebroad->setDbStartTime($data['add_show_rebroadcast_time_' . $i]);
                    $showRebroad->setDbShowId($showId);
                    $showRebroad->save();
                }
            }
        } elseif ($isRecorded && $data['add_show_rebroadcast'] && $repeatType == -1) {
            for ($i = 1; $i <= 10; $i++) {
                if ($data['add_show_rebroadcast_date_absolute_' . $i]) {
                    //$con = Propel::getConnection(CcShowPeer::DATABASE_NAME);
                    //$sql = "SELECT date '{$data['add_show_rebroadcast_date_absolute_'.$i]}' - date '{$data['add_show_start_date']}' ";
                    $sql = <<<SQL
SELECT :rebroadcast::date - :start::date
SQL;
                    $offset_days = Application_Common_Database::prepareAndExecute($sql, array('rebroadcast' => $data["add_show_rebroadcast_date_absolute_{$i}"], 'start' => $data['add_show_start_date']), "column");
                    //$r = $con->query($sql);
                    //$offset_days = $r->fetchColumn(0);
                    $showRebroad = new CcShowRebroadcast();
                    $showRebroad->setDbDayOffset($offset_days . " days");
                    $showRebroad->setDbStartTime($data['add_show_rebroadcast_time_absolute_' . $i]);
                    $showRebroad->setDbShowId($showId);
                    $showRebroad->save();
                }
            }
        }
        //check if we are adding or updating a show, and if updating
        //erase all the show's show_rebroadcast information first.
        if ($data['add_show_id'] != -1) {
            CcShowHostsQuery::create()->filterByDbShow($data['add_show_id'])->delete();
        }
        if (is_array($data['add_show_hosts'])) {
            //add selected hosts to cc_show_hosts table.
            foreach ($data['add_show_hosts'] as $host) {
                $showHost = new CcShowHosts();
                $showHost->setDbShow($showId);
                $showHost->setDbHost($host);
                $showHost->save();
            }
        }
        if ($data['add_show_id'] != -1) {
            $con = Propel::getConnection(CcSchedulePeer::DATABASE_NAME);
            $con->beginTransaction();
            //current timesamp in UTC.
            $current_timestamp = gmdate("Y-m-d H:i:s");
            try {
                //update the status flag in cc_schedule.
                $instances = CcShowInstancesQuery::create()->filterByDbEnds($current_timestamp, Criteria::GREATER_THAN)->filterByDbShowId($data['add_show_id'])->find($con);
                foreach ($instances as $instance) {
                    $instance->updateScheduleStatus($con);
                }
                $con->commit();
            } catch (Exception $e) {
                $con->rollback();
                Logging::info("Couldn't update schedule status.");
                Logging::info($e->getMessage());
            }
        }
        Application_Model_Show::populateShowUntil($showId);
        Application_Model_RabbitMq::PushSchedule();
        return $showId;
    }
Esempio n. 12
0
 /**
  *
  * Attempts to retrieve the cc_show_instance belonging to a cc_show
  * that starts at $starts. We have to pass in the start
  * time in case the show is repeating
  *
  * Returns the instance if one was found (one that is not a recording
  * and modified instance is false (has not been deleted))
  */
 private function getInstance($starts)
 {
     $temp = clone $starts;
     $temp->setTimezone(new DateTimeZone($this->oldShowTimezone));
     $temp->setTime($this->localShowStartHour, $this->localShowStartMin);
     $temp->setTimezone(new DateTimeZone("UTC"));
     $ccShowInstance = CcShowInstancesQuery::create()->filterByDbStarts($temp->format("Y-m-d H:i:s"), Criteria::EQUAL)->filterByDbShowId($this->ccShow->getDbId(), Criteria::EQUAL)->filterByDbRebroadcast(0, Criteria::EQUAL)->limit(1)->find();
     if ($ccShowInstance->isEmpty()) {
         return false;
     } else {
         return $ccShowInstance[0];
     }
 }
Esempio n. 13
0
    public static function checkOverlappingShows($show_start, $show_end, $update = false, $instanceId = null, $showId = null)
    {
        //if the show instance does not exist or was deleted, return false
        if (!is_null($showId)) {
            $ccShowInstance = CcShowInstancesQuery::create()->filterByDbShowId($showId)->filterByDbStarts($show_start->format("Y-m-d H:i:s"))->findOne();
        } elseif (!is_null($instanceId)) {
            $ccShowInstance = CcShowInstancesQuery::create()->filterByDbId($instanceId)->findOne();
        }
        if ($update && ($ccShowInstance && $ccShowInstance->getDbModifiedInstance() == true)) {
            return false;
        }
        $overlapping = false;
        $params = array(':show_end1' => $show_end->format('Y-m-d H:i:s'), ':show_end2' => $show_end->format('Y-m-d H:i:s'), ':show_end3' => $show_end->format('Y-m-d H:i:s'));
        /* If a show is being edited, exclude it from the query
         * In both cases (new and edit) we only grab shows that
         * are scheduled 2 days prior
         */
        if ($update) {
            $sql = <<<SQL
SELECT id,
       starts,
       ends
FROM cc_show_instances
WHERE (ends <= :show_end1
       OR starts <= :show_end2)
  AND date(starts) >= (date(:show_end3) - INTERVAL '2 days')
  AND modified_instance = FALSE
SQL;
            if (is_null($showId)) {
                $sql .= <<<SQL
  AND id != :instanceId
ORDER BY ends
SQL;
                $params[':instanceId'] = $instanceId;
            } else {
                $sql .= <<<SQL
  AND show_id != :showId
ORDER BY ends
SQL;
                $params[':showId'] = $showId;
            }
            $rows = Application_Common_Database::prepareAndExecute($sql, $params, 'all');
        } else {
            $sql = <<<SQL
SELECT id,
       starts,
       ends
FROM cc_show_instances
WHERE (ends <= :show_end1
       OR starts <= :show_end2)
  AND date(starts) >= (date(:show_end3) - INTERVAL '2 days')
  AND modified_instance = FALSE
ORDER BY ends
SQL;
            $rows = Application_Common_Database::prepareAndExecute($sql, array(':show_end1' => $show_end->format('Y-m-d H:i:s'), ':show_end2' => $show_end->format('Y-m-d H:i:s'), ':show_end3' => $show_end->format('Y-m-d H:i:s')), 'all');
        }
        foreach ($rows as $row) {
            $start = new DateTime($row["starts"], new DateTimeZone('UTC'));
            $end = new DateTime($row["ends"], new DateTimeZone('UTC'));
            if ($show_start->getTimestamp() < $end->getTimestamp() && $show_end->getTimestamp() > $start->getTimestamp()) {
                $overlapping = true;
                break;
            }
        }
        return $overlapping;
    }
Esempio n. 14
0
 public function cancelShow($p_id)
 {
     $this->con->beginTransaction();
     try {
         $instance = CcShowInstancesQuery::create()->findPK($p_id);
         if (!$instance->getDbRecord()) {
             $items = CcScheduleQuery::create()->filterByDbInstanceId($p_id)->filterByDbEnds($this->nowDT, Criteria::GREATER_THAN)->find($this->con);
             if (count($items) > 0) {
                 $remove = array();
                 $ts = $this->nowDT->format('U');
                 for ($i = 0; $i < count($items); $i++) {
                     $remove[$i]["instance"] = $p_id;
                     $remove[$i]["timestamp"] = $ts;
                     $remove[$i]["id"] = $items[$i]->getDbId();
                 }
                 $this->removeItems($remove, false);
             }
         } else {
             $rebroadcasts = $instance->getCcShowInstancessRelatedByDbId(null, $this->con);
             $rebroadcasts->delete($this->con);
         }
         $instance->setDbEnds($this->nowDT);
         $instance->save($this->con);
         $this->con->commit();
         if ($instance->getDbRecord()) {
             Application_Model_RabbitMq::SendMessageToShowRecorder("cancel_recording");
         }
     } catch (Exception $e) {
         $this->con->rollback();
         throw $e;
     }
 }
Esempio n. 15
0
 public static function updateShowInstance($data, $controller)
 {
     $isSaas = Application_Model_Preference::GetPlanLevel() != 'disabled';
     $formWhat = new Application_Form_AddShowWhat();
     $formWhen = new Application_Form_AddShowWhen();
     $formRepeats = new Application_Form_AddShowRepeats();
     $formWho = new Application_Form_AddShowWho();
     $formStyle = new Application_Form_AddShowStyle();
     $formLive = new Application_Form_AddShowLiveStream();
     $formWhat->removeDecorator('DtDdWrapper');
     $formWhen->removeDecorator('DtDdWrapper');
     $formRepeats->removeDecorator('DtDdWrapper');
     $formWho->removeDecorator('DtDdWrapper');
     $formStyle->removeDecorator('DtDdWrapper');
     $formLive->removeDecorator('DtDdWrapper');
     if (!$isSaas) {
         $formRecord = new Application_Form_AddShowRR();
         $formAbsoluteRebroadcast = new Application_Form_AddShowAbsoluteRebroadcastDates();
         $formRebroadcast = new Application_Form_AddShowRebroadcastDates();
         $formRecord->removeDecorator('DtDdWrapper');
         $formAbsoluteRebroadcast->removeDecorator('DtDdWrapper');
         $formRebroadcast->removeDecorator('DtDdWrapper');
     }
     $when = $formWhen->isValid($data);
     if ($when && $formWhen->checkReliantFields($data, true, null, true)) {
         $start_dt = new DateTime($data['add_show_start_date'] . " " . $data['add_show_start_time'], new DateTimeZone(date_default_timezone_get()));
         $start_dt->setTimezone(new DateTimeZone('UTC'));
         $end_dt = new DateTime($data['add_show_end_date_no_repeat'] . " " . $data['add_show_end_time'], new DateTimeZone(date_default_timezone_get()));
         $end_dt->setTimezone(new DateTimeZone('UTC'));
         $ccShowInstance = CcShowInstancesQuery::create()->findPK($data["add_show_instance_id"]);
         $ccShowInstance->setDbStarts($start_dt);
         $ccShowInstance->setDbEnds($end_dt);
         $ccShowInstance->save();
         Application_Model_Schedule::createNewFormSections($controller->view);
         return true;
     } else {
         $formWhat->disable();
         $formWhen->disableRepeatCheckbox();
         $formRepeats->disable();
         $formWho->disable();
         $formStyle->disable();
         //$formLive->disable();
         $controller->view->what = $formWhat;
         $controller->view->when = $formWhen;
         $controller->view->repeats = $formRepeats;
         $controller->view->who = $formWho;
         $controller->view->style = $formStyle;
         $controller->view->live = $formLive;
         if (!$isSaas) {
             $controller->view->rr = $formRecord;
             $controller->view->absoluteRebroadcast = $formAbsoluteRebroadcast;
             $controller->view->rebroadcast = $formRebroadcast;
             //$formRecord->disable();
             //$formAbsoluteRebroadcast->disable();
             //$formRebroadcast->disable();
         }
         return false;
     }
 }
Esempio n. 16
0
 /**
  * If this collection has already been initialized with
  * an identical criteria, it returns the collection.
  * Otherwise if this CcShowInstances is new, it will return
  * an empty collection; or if this CcShowInstances has previously
  * been saved, it will retrieve related CcShowInstancessRelatedByDbId from storage.
  *
  * This method is protected by default in order to keep the public
  * api reasonable.  You can provide public methods for those you
  * actually need in CcShowInstances.
  *
  * @param      Criteria $criteria optional Criteria object to narrow the query
  * @param      PropelPDO $con optional connection object
  * @param      string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
  * @return     PropelCollection|array CcShowInstances[] List of CcShowInstances objects
  */
 public function getCcShowInstancessRelatedByDbIdJoinCcFiles($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     $query = CcShowInstancesQuery::create(null, $criteria);
     $query->joinWith('CcFiles', $join_behavior);
     return $this->getCcShowInstancessRelatedByDbId($query, $con);
 }
Esempio n. 17
0
    public function getInstanceOnDate($p_dateTime)
    {
        $timestamp = $p_dateTime->format("Y-m-d H:i:s");
        $sql = <<<SQL
SELECT id
FROM cc_show_instances
WHERE date(starts) = date(:timestamp::TIMESTAMP)
  AND show_id = :showId
  AND rebroadcast = 0;
SQL;
        try {
            $row = Application_Common_Database::prepareAndExecute($sql, array(':showId' => $this->getId(), ':timestamp' => $timestamp), 'column');
            return CcShowInstancesQuery::create()->findPk($row);
        } catch (Exception $e) {
            return null;
        }
    }
Esempio n. 18
0
 public function setRecordedFile($file_id)
 {
     $showInstance = CcShowInstancesQuery::create()->findPK($this->_instanceId);
     $showInstance->setDbRecordedFile($file_id)->save();
     $rebroadcasts = CcShowInstancesQuery::create()->filterByDbOriginalShow($this->_instanceId)->find();
     foreach ($rebroadcasts as $rebroadcast) {
         try {
             $rebroad = new Application_Model_ShowInstance($rebroadcast->getDbId());
             $rebroad->addFileToShow($file_id, false);
         } catch (Exception $e) {
             Logging::info($e->getMessage());
         }
     }
 }
Esempio n. 19
0
 public function isHostOfShowInstance($instanceId)
 {
     $showInstance = CcShowInstancesQuery::create()->findPk($instanceId);
     return CcShowHostsQuery::create()->filterByDbShow($showInstance->getDbShowId())->filterByDbHost($this->getDbId())->count() > 0;
 }