public function __construct($showId = null, $instanceId = null)
 {
     if (!is_null($showId)) {
         $this->ccShow = CcShowQuery::create()->findPk($showId);
     }
     $this->instanceId = $instanceId;
 }
Esempio n. 2
0
 private function getShowNames()
 {
     $showNames = array("0" => "-------------------------");
     $shows = CcShowQuery::create()->setFormatter(ModelCriteria::FORMAT_ON_DEMAND)->orderByDbName()->find();
     foreach ($shows as $show) {
         $showNames[$show->getDbId()] = $show->getDbName();
     }
     return $showNames;
 }
Esempio n. 3
0
 public function delete($rabbitmqPush = true)
 {
     // see if it was recording show
     $recording = $this->isRecorded();
     // get show id
     $showId = $this->getShowId();
     $show = $this->getShow();
     $current_timestamp = gmdate("Y-m-d H:i:s");
     if ($current_timestamp <= $this->getShowInstanceEnd()) {
         if ($show->isRepeating()) {
             CcShowInstancesQuery::create()->findPK($this->_instanceId)->setDbModifiedInstance(true)->save();
             if ($this->isRebroadcast()) {
                 return;
             }
             //delete the rebroadcasts of the removed recorded show.
             if ($recording) {
                 CcShowInstancesQuery::create()->filterByDbOriginalShow($this->_instanceId)->delete();
             }
             /* Automatically delete all files scheduled in cc_schedules table. */
             CcScheduleQuery::create()->filterByDbInstanceId($this->_instanceId)->delete();
             if ($this->checkToDeleteShow($showId)) {
                 CcShowQuery::create()->filterByDbId($showId)->delete();
             }
         } else {
             if ($this->isRebroadcast()) {
                 $this->_showInstance->delete();
             } else {
                 $show->delete();
             }
         }
     }
     if ($rabbitmqPush) {
         Application_Model_RabbitMq::PushSchedule();
     }
 }
Esempio n. 4
0
 /**
  * Get the associated CcShow object
  *
  * @param      PropelPDO Optional Connection object.
  * @return     CcShow The associated CcShow object.
  * @throws     PropelException
  */
 public function getCcShow(PropelPDO $con = null)
 {
     if ($this->aCcShow === null && $this->show_id !== null) {
         $this->aCcShow = CcShowQuery::create()->findPk($this->show_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->aCcShow->addCcShowInstancess($this);
         		 */
     }
     return $this->aCcShow;
 }
 public function checkLiveStreamAuthAction()
 {
     $request = $this->getRequest();
     $username = $request->getParam('username');
     $password = $request->getParam('password');
     $djtype = $request->getParam('djtype');
     if ($djtype == 'master') {
         //check against master
         if ($username == Application_Model_Preference::GetLiveStreamMasterUsername() && $password == Application_Model_Preference::GetLiveStreamMasterPassword()) {
             $this->view->msg = true;
         } else {
             $this->view->msg = false;
         }
     } elseif ($djtype == "dj") {
         //check against show dj auth
         $showInfo = Application_Model_Show::getCurrentShow();
         // there is current playing show
         if (isset($showInfo[0]['id'])) {
             $current_show_id = $showInfo[0]['id'];
             $CcShow = CcShowQuery::create()->findPK($current_show_id);
             // get custom pass info from the show
             $custom_user = $CcShow->getDbLiveStreamUser();
             $custom_pass = $CcShow->getDbLiveStreamPass();
             // get hosts ids
             $show = new Application_Model_Show($current_show_id);
             $hosts_ids = $show->getHostsIds();
             // check against hosts auth
             if ($CcShow->getDbLiveStreamUsingAirtimeAuth()) {
                 foreach ($hosts_ids as $host) {
                     $h = new Application_Model_User($host['subjs_id']);
                     if ($username == $h->getLogin() && md5($password) == $h->getPassword()) {
                         $this->view->msg = true;
                         return;
                     }
                 }
             }
             // check against custom auth
             if ($CcShow->getDbLiveStreamUsingCustomAuth()) {
                 if ($username == $custom_user && $password == $custom_pass) {
                     $this->view->msg = true;
                 } else {
                     $this->view->msg = false;
                 }
             } else {
                 $this->view->msg = false;
             }
         } else {
             // no show is currently playing
             $this->view->msg = false;
         }
     }
 }
Esempio n. 6
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      PropelPDO $con
  * @return     void
  * @throws     PropelException
  * @see        BaseObject::setDeleted()
  * @see        BaseObject::isDeleted()
  */
 public function delete(PropelPDO $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getConnection(CcShowPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     try {
         $ret = $this->preDelete($con);
         if ($ret) {
             CcShowQuery::create()->filterByPrimaryKey($this->getPrimaryKey())->delete($con);
             $this->postDelete($con);
             $con->commit();
             $this->setDeleted(true);
         } else {
             $con->commit();
         }
     } catch (PropelException $e) {
         $con->rollBack();
         throw $e;
     }
 }
Esempio n. 7
0
 /**
  *  returns info about live stream override info
  */
 public function getLiveStreamInfo()
 {
     $info = array();
     if ($this->getId() == null) {
         return $info;
     } else {
         $ccShow = CcShowQuery::create()->findPK($this->_showId);
         $info['custom_username'] = $ccShow->getDbLiveStreamUser();
         $info['cb_airtime_auth'] = $ccShow->getDbLiveStreamUsingAirtimeAuth();
         $info['cb_custom_auth'] = $ccShow->getDbLiveStreamUsingCustomAuth();
         $info['custom_username'] = $ccShow->getDbLiveStreamUser();
         $info['custom_password'] = $ccShow->getDbLiveStreamPass();
         return $info;
     }
 }
Esempio n. 8
0
 public function getGenre()
 {
     $show = CcShowQuery::create()->findPK($this->getShowId());
     return $show->getDbGenre();
 }
Esempio n. 9
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. 10
0
 /**
  *
  * Sets the fields for a cc_show table row
  * @param $ccShow
  * @param $showData
  */
 private function setCcShow($showData)
 {
     if (!$this->isUpdate) {
         $ccShow = new CcShow();
     } else {
         $ccShow = CcShowQuery::create()->findPk($showData["add_show_id"]);
     }
     $ccShow->setDbName($showData['add_show_name']);
     $ccShow->setDbDescription($showData['add_show_description']);
     $ccShow->setDbUrl($showData['add_show_url']);
     $ccShow->setDbGenre($showData['add_show_genre']);
     $ccShow->setDbColor($showData['add_show_color']);
     $ccShow->setDbBackgroundColor($showData['add_show_background_color']);
     $ccShow->setDbLiveStreamUsingAirtimeAuth($showData['cb_airtime_auth'] == 1);
     $ccShow->setDbLiveStreamUsingCustomAuth($showData['cb_custom_auth'] == 1);
     $ccShow->setDbLiveStreamUser($showData['custom_username']);
     $ccShow->setDbLiveStreamPass($showData['custom_password']);
     // Once a show is unlinked it cannot be linked again
     if ($ccShow->getDbLinked() && !$showData["add_show_linked"]) {
         $ccShow->setDbIsLinkable(false);
     }
     $ccShow->setDbLinked($showData["add_show_linked"]);
     $ccShow->save();
     $this->ccShow = $ccShow;
 }