Ejemplo n.º 1
0
 public function isUserType($type, $showId = '')
 {
     if (is_array($type)) {
         $result = false;
         foreach ($type as $t) {
             switch ($t) {
                 case UTYPE_ADMIN:
                     $result = $this->_userInstance->getDbType() === 'A';
                     break;
                 case UTYPE_HOST:
                     $userId = $this->_userInstance->getDbId();
                     $result = CcShowHostsQuery::create()->filterByDbShow($showId)->filterByDbHost($userId)->count() > 0;
                     break;
                 case UTYPE_PROGRAM_MANAGER:
                     $result = $this->_userInstance->getDbType() === 'P';
                     break;
             }
             if ($result) {
                 return $result;
             }
         }
     } else {
         switch ($type) {
             case UTYPE_ADMIN:
                 return $this->_userInstance->getDbType() === 'A';
             case UTYPE_HOST:
                 $userId = $this->_userInstance->getDbId();
                 return CcShowHostsQuery::create()->filterByDbShow($showId)->filterByDbHost($userId)->count() > 0;
             case UTYPE_PROGRAM_MANAGER:
                 return $this->_userInstance->getDbType() === 'P';
         }
     }
 }
Ejemplo n.º 2
0
 private function getUsersShows()
 {
     $shows = array();
     $host_shows = CcShowHostsQuery::create()->setFormatter(ModelCriteria::FORMAT_ON_DEMAND)->filterByDbHost($this->user->getId())->find();
     foreach ($host_shows as $host_show) {
         $shows[] = $host_show->getDbShow();
     }
     return $shows;
 }
Ejemplo n.º 3
0
 /**
  * If this collection has already been initialized with
  * an identical criteria, it returns the collection.
  * Otherwise if this CcSubjs is new, it will return
  * an empty collection; or if this CcSubjs has previously
  * been saved, it will retrieve related CcShowHostss 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 CcSubjs.
  *
  * @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 CcShowHosts[] List of CcShowHosts objects
  */
 public function getCcShowHostssJoinCcShow($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     $query = CcShowHostsQuery::create(null, $criteria);
     $query->joinWith('CcShow', $join_behavior);
     return $this->getCcShowHostss($query, $con);
 }
Ejemplo n.º 4
0
 public function populateShowFormAction()
 {
     $userInfo = Zend_Auth::getInstance()->getStorage()->read();
     $user = new Application_Model_User($userInfo->id);
     $isSaas = Application_Model_Preference::GetPlanLevel() == 'disabled' ? false : true;
     $showInstanceId = $this->_getParam('id');
     $this->view->action = "edit-show";
     try {
         $showInstance = new Application_Model_ShowInstance($showInstanceId);
     } catch (Exception $e) {
         $this->view->show_error = true;
         return false;
     }
     $isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER));
     $isDJ = $user->isHostOfShow($showInstance->getShowId());
     if (!($isAdminOrPM || $isDJ)) {
         return;
     }
     if ($isDJ) {
         $this->view->action = "dj-edit-show";
     }
     $formWhat = new Application_Form_AddShowWhat();
     $formWho = new Application_Form_AddShowWho();
     $formWhen = new Application_Form_AddShowWhen();
     $formRepeats = new Application_Form_AddShowRepeats();
     $formStyle = new Application_Form_AddShowStyle();
     $formLive = new Application_Form_AddShowLiveStream();
     $formWhat->removeDecorator('DtDdWrapper');
     $formWho->removeDecorator('DtDdWrapper');
     $formWhen->removeDecorator('DtDdWrapper');
     $formRepeats->removeDecorator('DtDdWrapper');
     $formStyle->removeDecorator('DtDdWrapper');
     $this->view->what = $formWhat;
     $this->view->when = $formWhen;
     $this->view->repeats = $formRepeats;
     $this->view->who = $formWho;
     $this->view->style = $formStyle;
     $this->view->live = $formLive;
     $this->view->addNewShow = false;
     $show = new Application_Model_Show($showInstance->getShowId());
     $formWhat->populate(array('add_show_id' => $show->getId(), 'add_show_instance_id' => $showInstanceId, 'add_show_name' => $show->getName(), 'add_show_url' => $show->getUrl(), 'add_show_genre' => $show->getGenre(), 'add_show_description' => $show->getDescription()));
     $startsDateTime = new DateTime($show->getStartDate() . " " . $show->getStartTime(), new DateTimeZone("UTC"));
     $endsDateTime = new DateTime($show->getEndDate() . " " . $show->getEndTime(), new DateTimeZone("UTC"));
     $startsDateTime->setTimezone(new DateTimeZone(date_default_timezone_get()));
     $endsDateTime->setTimezone(new DateTimeZone(date_default_timezone_get()));
     $formWhen->populate(array('add_show_start_date' => $startsDateTime->format("Y-m-d"), 'add_show_start_time' => $startsDateTime->format("H:i"), 'add_show_end_date_no_repeat' => $endsDateTime->format("Y-m-d"), 'add_show_end_time' => $endsDateTime->format("H:i"), 'add_show_duration' => $show->getDuration(true), 'add_show_repeats' => $show->isRepeating() ? 1 : 0));
     if ($show->isStartDateTimeInPast()) {
         // for a non-repeating show, we should never allow user to change the start time.
         // for the repeating show, we should allow because the form works as repeating template form
         if (!$showInstance->getShow()->isRepeating()) {
             $formWhen->disableStartDateAndTime();
         } else {
             $formWhen->getElement('add_show_start_date')->setOptions(array('disabled' => true));
         }
     }
     //need to get the days of the week in the php timezone (for the front end).
     $days = array();
     $showDays = CcShowDaysQuery::create()->filterByDbShowId($showInstance->getShowId())->find();
     foreach ($showDays as $showDay) {
         $showStartDay = new DateTime($showDay->getDbFirstShow(), new DateTimeZone($showDay->getDbTimezone()));
         $showStartDay->setTimezone(new DateTimeZone(date_default_timezone_get()));
         array_push($days, $showStartDay->format('w'));
     }
     $displayedEndDate = new DateTime($show->getRepeatingEndDate(), new DateTimeZone($showDays[0]->getDbTimezone()));
     $displayedEndDate->sub(new DateInterval("P1D"));
     //end dates are stored non-inclusively.
     $displayedEndDate->setTimezone(new DateTimeZone(date_default_timezone_get()));
     $formRepeats->populate(array('add_show_repeat_type' => $show->getRepeatType(), 'add_show_day_check' => $days, 'add_show_end_date' => $displayedEndDate->format("Y-m-d"), 'add_show_no_end' => $show->getRepeatingEndDate() == ''));
     $hosts = array();
     $showHosts = CcShowHostsQuery::create()->filterByDbShow($showInstance->getShowId())->find();
     foreach ($showHosts as $showHost) {
         array_push($hosts, $showHost->getDbHost());
     }
     $formWho->populate(array('add_show_hosts' => $hosts));
     $formStyle->populate(array('add_show_background_color' => $show->getBackgroundColor(), 'add_show_color' => $show->getColor()));
     $formLive->populate($show->getLiveStreamInfo());
     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');
         $this->view->rr = $formRecord;
         $this->view->absoluteRebroadcast = $formAbsoluteRebroadcast;
         $this->view->rebroadcast = $formRebroadcast;
         $formRecord->populate(array('add_show_record' => $show->isRecorded(), 'add_show_rebroadcast' => $show->isRebroadcast()));
         $formRecord->getElement('add_show_record')->setOptions(array('disabled' => true));
         $rebroadcastsRelative = $show->getRebroadcastsRelative();
         $rebroadcastFormValues = array();
         $i = 1;
         foreach ($rebroadcastsRelative as $rebroadcast) {
             $rebroadcastFormValues["add_show_rebroadcast_date_{$i}"] = $rebroadcast['day_offset'];
             $rebroadcastFormValues["add_show_rebroadcast_time_{$i}"] = Application_Common_DateHelper::removeSecondsFromTime($rebroadcast['start_time']);
             $i++;
         }
         $formRebroadcast->populate($rebroadcastFormValues);
         $rebroadcastsAbsolute = $show->getRebroadcastsAbsolute();
         $rebroadcastAbsoluteFormValues = array();
         $i = 1;
         foreach ($rebroadcastsAbsolute as $rebroadcast) {
             $rebroadcastAbsoluteFormValues["add_show_rebroadcast_date_absolute_{$i}"] = $rebroadcast['start_date'];
             $rebroadcastAbsoluteFormValues["add_show_rebroadcast_time_absolute_{$i}"] = $rebroadcast['start_time'];
             $i++;
         }
         $formAbsoluteRebroadcast->populate($rebroadcastAbsoluteFormValues);
         if (!$isAdminOrPM) {
             $formRecord->disable();
             $formAbsoluteRebroadcast->disable();
             $formRebroadcast->disable();
         }
     }
     if (!$isAdminOrPM) {
         $formWhat->disable();
         $formWho->disable();
         $formWhen->disable();
         $formRepeats->disable();
         $formStyle->disable();
     }
     $this->view->newForm = $this->view->render('schedule/add-show-form.phtml');
     $this->view->entries = 5;
 }
Ejemplo n.º 5
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(CcShowHostsPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     try {
         $ret = $this->preDelete($con);
         if ($ret) {
             CcShowHostsQuery::create()->filterByPrimaryKey($this->getPrimaryKey())->delete($con);
             $this->postDelete($con);
             $con->commit();
             $this->setDeleted(true);
         } else {
             $con->commit();
         }
     } catch (PropelException $e) {
         $con->rollBack();
         throw $e;
     }
 }
Ejemplo n.º 6
0
 public function editShowAction()
 {
     $userInfo = Zend_Auth::getInstance()->getStorage()->read();
     $user = new User($userInfo->id);
     if (!$user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER))) {
         return;
     }
     $showInstanceId = $this->_getParam('id');
     $formWhat = new Application_Form_AddShowWhat();
     $formWho = new Application_Form_AddShowWho();
     $formWhen = new Application_Form_AddShowWhen();
     $formRepeats = new Application_Form_AddShowRepeats();
     $formStyle = new Application_Form_AddShowStyle();
     $formRecord = new Application_Form_AddShowRR();
     $formAbsoluteRebroadcast = new Application_Form_AddShowAbsoluteRebroadcastDates();
     $formRebroadcast = new Application_Form_AddShowRebroadcastDates();
     $formWhat->removeDecorator('DtDdWrapper');
     $formWho->removeDecorator('DtDdWrapper');
     $formWhen->removeDecorator('DtDdWrapper');
     $formRepeats->removeDecorator('DtDdWrapper');
     $formStyle->removeDecorator('DtDdWrapper');
     $formRecord->removeDecorator('DtDdWrapper');
     $formAbsoluteRebroadcast->removeDecorator('DtDdWrapper');
     $formRebroadcast->removeDecorator('DtDdWrapper');
     $this->view->what = $formWhat;
     $this->view->when = $formWhen;
     $this->view->repeats = $formRepeats;
     $this->view->who = $formWho;
     $this->view->style = $formStyle;
     $this->view->rr = $formRecord;
     $this->view->absoluteRebroadcast = $formAbsoluteRebroadcast;
     $this->view->rebroadcast = $formRebroadcast;
     $this->view->addNewShow = false;
     $showInstance = new ShowInstance($showInstanceId);
     $show = new Show($showInstance->getShowId());
     $formWhat->populate(array('add_show_id' => $show->getId(), 'add_show_name' => $show->getName(), 'add_show_url' => $show->getUrl(), 'add_show_genre' => $show->getGenre(), 'add_show_description' => $show->getDescription()));
     $formWhen->populate(array('add_show_start_date' => $show->getStartDate(), 'add_show_start_time' => DateHelper::removeSecondsFromTime($show->getStartTime()), 'add_show_end_date_no_repeat' => $show->getEndDate(), 'add_show_end_time' => DateHelper::removeSecondsFromTime($show->getEndTime()), 'add_show_duration' => $show->getDuration(true), 'add_show_repeats' => $show->isRepeating() ? 1 : 0));
     if ($show->isStartDateTimeInPast()) {
         $formWhen->getElement('add_show_start_date')->setOptions(array('disabled' => true));
     }
     $days = array();
     $showDays = CcShowDaysQuery::create()->filterByDbShowId($showInstance->getShowId())->find();
     foreach ($showDays as $showDay) {
         array_push($days, $showDay->getDbDay());
     }
     $displayedEndDate = new DateTime($show->getRepeatingEndDate());
     $displayedEndDate->sub(new DateInterval("P1D"));
     //end dates are stored non-inclusively.
     $displayedEndDate = $displayedEndDate->format("Y-m-d");
     $formRepeats->populate(array('add_show_repeat_type' => $show->getRepeatType(), 'add_show_day_check' => $days, 'add_show_end_date' => $displayedEndDate, 'add_show_no_end' => $show->getRepeatingEndDate() == ''));
     $formRecord->populate(array('add_show_record' => $show->isRecorded(), 'add_show_rebroadcast' => $show->isRebroadcast()));
     $formRecord->getElement('add_show_record')->setOptions(array('disabled' => true));
     $rebroadcastsRelative = $show->getRebroadcastsRelative();
     $rebroadcastFormValues = array();
     $i = 1;
     foreach ($rebroadcastsRelative as $rebroadcast) {
         $rebroadcastFormValues["add_show_rebroadcast_date_{$i}"] = $rebroadcast['day_offset'];
         $rebroadcastFormValues["add_show_rebroadcast_time_{$i}"] = DateHelper::removeSecondsFromTime($rebroadcast['start_time']);
         $i++;
     }
     $formRebroadcast->populate($rebroadcastFormValues);
     $rebroadcastsAbsolute = $show->getRebroadcastsAbsolute();
     $rebroadcastAbsoluteFormValues = array();
     $i = 1;
     foreach ($rebroadcastsAbsolute as $rebroadcast) {
         $rebroadcastAbsoluteFormValues["add_show_rebroadcast_date_absolute_{$i}"] = $rebroadcast['start_date'];
         $rebroadcastAbsoluteFormValues["add_show_rebroadcast_time_absolute_{$i}"] = DateHelper::removeSecondsFromTime($rebroadcast['start_time']);
         $i++;
     }
     $formAbsoluteRebroadcast->populate($rebroadcastAbsoluteFormValues);
     $hosts = array();
     $showHosts = CcShowHostsQuery::create()->filterByDbShow($showInstance->getShowId())->find();
     foreach ($showHosts as $showHost) {
         array_push($hosts, $showHost->getDbHost());
     }
     $formWho->populate(array('add_show_hosts' => $hosts));
     $formStyle->populate(array('add_show_background_color' => $show->getBackgroundColor(), 'add_show_color' => $show->getColor()));
     $this->view->newForm = $this->view->render('schedule/add-show-form.phtml');
     $this->view->entries = 5;
 }
Ejemplo n.º 7
0
 public function isHostOfShow($showId)
 {
     $userId = $this->_userInstance->getDbId();
     return CcShowHostsQuery::create()->filterByDbShow($showId)->filterByDbHost($userId)->count() > 0;
 }
Ejemplo n.º 8
0
 /**
  * Create a show.
  *
  * Note: end dates are non inclusive.
  *
  * @param array $data
  * @return int
  *     Show ID
  */
 public static function create($data)
 {
     $con = Propel::getConnection(CcShowPeer::DATABASE_NAME);
     $sql = "SELECT EXTRACT(DOW FROM TIMESTAMP '{$data['add_show_start_date']} {$data['add_show_start_time']}')";
     $r = $con->query($sql);
     $startDow = $r->fetchColumn(0);
     if ($data['add_show_no_end']) {
         $endDate = NULL;
     } else {
         if ($data['add_show_repeats']) {
             $sql = "SELECT date '{$data['add_show_end_date']}' + INTERVAL '1 day' ";
             $r = $con->query($sql);
             $endDate = $r->fetchColumn(0);
         } else {
             $sql = "SELECT date '{$data['add_show_start_date']}' + INTERVAL '1 day' ";
             $r = $con->query($sql);
             $endDate = $r->fetchColumn(0);
         }
     }
     //only want the day of the week from the start date.
     if (!$data['add_show_repeats']) {
         $data['add_show_day_check'] = array($startDow);
     } else {
         if ($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->save();
     $showId = $ccShow->getDbId();
     $show = new Show($showId);
     $isRecorded = $data['add_show_record'] ? 1 : 0;
     if ($data['add_show_id'] != -1) {
         $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($data['add_show_start_date']);
         $showDay->setDbLastShow($endDate);
         $showDay->setDbStartTime($data['add_show_start_time']);
         $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) {
             if ($startDow !== $day) {
                 if ($startDow > $day) {
                     $daysAdd = 6 - $startDow + 1 + $day;
                 } else {
                     $daysAdd = $day - $startDow;
                 }
                 $sql = "SELECT date '{$data['add_show_start_date']}' + INTERVAL '{$daysAdd} day' ";
                 $r = $con->query($sql);
                 $start = $r->fetchColumn(0);
             } else {
                 $start = $data['add_show_start_date'];
             }
             if (strtotime($start) <= strtotime($endDate) || is_null($endDate)) {
                 $showDay = new CcShowDays();
                 $showDay->setDbFirstShow($start);
                 $showDay->setDbLastShow($endDate);
                 $showDay->setDbStartTime($data['add_show_start_time']);
                 $showDay->setDbDuration($data['add_show_duration']);
                 $showDay->setDbDay($day);
                 $showDay->setDbRepeatType($repeatType);
                 $showDay->setDbShowId($showId);
                 $showDay->setDbRecord($isRecorded);
                 $showDay->save();
             }
         }
     }
     $date = new DateHelper();
     $currentTimestamp = $date->getTimestamp();
     //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 && $data['add_show_rebroadcast']) {
         CcShowRebroadcastQuery::create()->filterByDbShowId($data['add_show_id'])->delete();
     }
     //adding rows to cc_show_rebroadcast
     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();
             }
         }
     } else {
         if ($isRecorded && $data['add_show_rebroadcast'] && $repeatType == -1) {
             for ($i = 1; $i <= 10; $i++) {
                 if ($data['add_show_rebroadcast_date_absolute_' . $i]) {
                     $sql = "SELECT date '{$data['add_show_rebroadcast_date_absolute_' . $i]}' - date '{$data['add_show_start_date']}' ";
                     $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();
         }
     }
     Show::populateShowUntil($showId);
     RabbitMq::PushSchedule();
     return $showId;
 }
Ejemplo 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;
    }
Ejemplo n.º 10
0
 /**
  *
  * Deletes all the cc_show_hosts entries for a specific show
  * that is currently being edited. They will get recreated with
  * the new show specs
  */
 private function deleteCcShowHosts()
 {
     CcShowHostsQuery::create()->filterByDbShow($this->ccShow->getDbId())->delete();
 }
Ejemplo n.º 11
0
 public function getShowList($startDT, $endDT)
 {
     $user = Application_Model_User::getCurrentUser();
     $shows = Application_Model_Show::getShows($startDT, $endDT);
     Logging::info($startDT->format("Y-m-d H:i:s"));
     Logging::info($endDT->format("Y-m-d H:i:s"));
     Logging::info($shows);
     //need to filter the list to only their shows
     if ($user->isHost()) {
         $showIds = array();
         foreach ($shows as $show) {
             $showIds[] = $show["show_id"];
         }
         $showIds = array_unique($showIds);
         Logging::info($showIds);
         $hostRecords = CcShowHostsQuery::create()->filterByDbHost($user->getId())->filterByDbShow($showIds)->find($this->con);
         $filteredShowIds = array();
         foreach ($hostRecords as $record) {
             $filteredShowIds[] = $record->getDbShow();
         }
         Logging::info($filteredShowIds);
         $filteredShows = array();
         foreach ($shows as $show) {
             if (in_array($show["show_id"], $filteredShowIds)) {
                 $filteredShows[] = $show;
             }
         }
     } else {
         $filteredShows = $shows;
     }
     $timezoneUTC = new DateTimeZone("UTC");
     $timezoneLocal = new DateTimeZone($this->timezone);
     foreach ($filteredShows as &$result) {
         //need to display the results in the station's timezone.
         $dateTime = new DateTime($result["starts"], $timezoneUTC);
         $dateTime->setTimezone($timezoneLocal);
         $result["starts"] = $dateTime->format("Y-m-d H:i:s");
         $dateTime = new DateTime($result["ends"], $timezoneUTC);
         $dateTime->setTimezone($timezoneLocal);
         $result["ends"] = $dateTime->format("Y-m-d H:i:s");
     }
     return $filteredShows;
 }
Ejemplo n.º 12
0
 public function isHostOfShowInstance($instanceId)
 {
     $showInstance = CcShowInstancesQuery::create()->findPk($instanceId);
     return CcShowHostsQuery::create()->filterByDbShow($showInstance->getDbShowId())->filterByDbHost($this->getDbId())->count() > 0;
 }