Пример #1
0
 /**
  * 
  * @return array of show forms
  */
 public function createShowForms()
 {
     $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();
     $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');
     $formLive->removeDecorator('DtDdWrapper');
     $formRecord->removeDecorator('DtDdWrapper');
     $formAbsoluteRebroadcast->removeDecorator('DtDdWrapper');
     $formRebroadcast->removeDecorator('DtDdWrapper');
     $forms = array();
     $forms["what"] = $formWhat;
     $forms["who"] = $formWho;
     $forms["when"] = $formWhen;
     $forms["repeats"] = $formRepeats;
     $forms["style"] = $formStyle;
     $forms["live"] = $formLive;
     $forms["record"] = $formRecord;
     $forms["abs_rebroadcast"] = $formAbsoluteRebroadcast;
     $forms["rebroadcast"] = $formRebroadcast;
     return $forms;
 }
Пример #2
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;
 }
Пример #3
0
 public function addShowAction()
 {
     $js = $this->_getParam('data');
     $data = array();
     //need to convert from serialized jQuery array.
     foreach ($js as $j) {
         $data[$j["name"]] = $j["value"];
     }
     $show = new Show($data['add_show_id']);
     $startDateModified = true;
     if ($data['add_show_id'] != -1 && !array_key_exists('add_show_start_date', $data)) {
         //show is being updated and changing the start date was disabled, since the
         //array key does not exist. We need to repopulate this entry from the db.
         $data['add_show_start_date'] = $show->getStartDate();
         $startDateModified = false;
     }
     $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;
     }
     $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');
     $what = $formWhat->isValid($data);
     $when = $formWhen->isValid($data);
     if ($when) {
         $when = $formWhen->checkReliantFields($data, $startDateModified);
     }
     //The way the following code works is that is parses the hour and
     //minute from a string with the format "1h 20m" or "2h" or "36m".
     //So we are detecting whether an hour or minute value exists via strpos
     //and then parse appropriately. A better way to do this in the future is
     //actually pass the format from javascript in the format hh:mm so we don't
     //have to do this extra String parsing.
     $hPos = strpos($data["add_show_duration"], 'h');
     $mPos = strpos($data["add_show_duration"], 'm');
     $hValue = 0;
     $mValue = 0;
     if ($hPos !== false) {
         $hValue = trim(substr($data["add_show_duration"], 0, $hPos));
     }
     if ($mPos !== false) {
         $hPos = $hPos === FALSE ? 0 : $hPos + 1;
         $mValue = trim(substr($data["add_show_duration"], $hPos, -1));
     }
     $data["add_show_duration"] = $hValue . ":" . $mValue;
     if ($data["add_show_repeats"]) {
         $repeats = $formRepeats->isValid($data);
         if ($repeats) {
             $repeats = $formRepeats->checkReliantFields($data);
         }
         $formAbsoluteRebroadcast->reset();
         //make it valid, results don't matter anyways.
         $rebroadAb = 1;
         if ($data["add_show_rebroadcast"]) {
             $rebroad = $formRebroadcast->isValid($data);
             if ($rebroad) {
                 $rebroad = $formRebroadcast->checkReliantFields($data);
             }
         } else {
             $rebroad = 1;
         }
     } else {
         $formRebroadcast->reset();
         //make it valid, results don't matter anyways.
         $repeats = 1;
         $rebroad = 1;
         if ($data["add_show_rebroadcast"]) {
             $rebroadAb = $formAbsoluteRebroadcast->isValid($data);
             if ($rebroadAb) {
                 $rebroadAb = $formAbsoluteRebroadcast->checkReliantFields($data);
             }
         } else {
             $rebroadAb = 1;
         }
     }
     $who = $formWho->isValid($data);
     $style = $formStyle->isValid($data);
     //If show is a new show (not updated), then get
     //isRecorded from POST data. Otherwise get it from
     //the database since the user is not allowed to
     //update this option.
     $record = false;
     if ($data['add_show_id'] != -1) {
         $data['add_show_record'] = $show->isRecorded();
         $record = $formRecord->isValid($data);
         $formRecord->getElement('add_show_record')->setOptions(array('disabled' => true));
     } else {
         $record = $formRecord->isValid($data);
     }
     if ($what && $when && $repeats && $who && $style && $record && $rebroadAb && $rebroad) {
         $userInfo = Zend_Auth::getInstance()->getStorage()->read();
         $user = new User($userInfo->id);
         if ($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER))) {
             Show::create($data);
         }
         //send back a new form for the user.
         Schedule::createNewFormSections($this->view);
         $this->view->newForm = $this->view->render('schedule/add-show-form.phtml');
     } else {
         $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 = true;
         //the form still needs to be "update" since
         //the validity test failed.
         if ($data['add_show_id'] != -1) {
             $this->view->addNewShow = false;
         }
         if (!$startDateModified) {
             $formWhen->getElement('add_show_start_date')->setOptions(array('disabled' => true));
         }
         $this->view->form = $this->view->render('schedule/add-show-form.phtml');
     }
 }
Пример #4
0
 public static function createNewFormSections($p_view)
 {
     $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');
     $p_view->what = $formWhat;
     $p_view->when = $formWhen;
     $p_view->repeats = $formRepeats;
     $p_view->who = $formWho;
     $p_view->style = $formStyle;
     $p_view->rr = $formRecord;
     $p_view->absoluteRebroadcast = $formAbsoluteRebroadcast;
     $p_view->rebroadcast = $formRebroadcast;
     $p_view->addNewShow = true;
     $formWhat->populate(array('add_show_id' => '-1'));
     $formWhen->populate(array('add_show_start_date' => date("Y-m-d"), 'add_show_start_time' => '00:00', 'add_show_end_date_no_repeate' => date("Y-m-d"), 'add_show_end_time' => '01:00', 'add_show_duration' => '1h'));
     $formRepeats->populate(array('add_show_end_date' => date("Y-m-d")));
 }
Пример #5
0
 public static function addUpdateShow($data, $controller, $validateStartDate, $originalStartDate = null, $update = false, $instanceId = null)
 {
     $userInfo = Zend_Auth::getInstance()->getStorage()->read();
     $user = new Application_Model_User($userInfo->id);
     $isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER));
     $isSaas = Application_Model_Preference::GetPlanLevel() != 'disabled';
     $record = false;
     $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');
     $formLive->removeDecorator('DtDdWrapper');
     $what = $formWhat->isValid($data);
     $when = $formWhen->isValid($data);
     $live = $formLive->isValid($data);
     if ($when) {
         $when = $formWhen->checkReliantFields($data, $validateStartDate, $originalStartDate, $update, $instanceId);
     }
     //The way the following code works is that is parses the hour and
     //minute from a string with the format "1h 20m" or "2h" or "36m".
     //So we are detecting whether an hour or minute value exists via strpos
     //and then parse appropriately. A better way to do this in the future is
     //actually pass the format from javascript in the format hh:mm so we don't
     //have to do this extra String parsing.
     $hPos = strpos($data["add_show_duration"], 'h');
     $mPos = strpos($data["add_show_duration"], 'm');
     $hValue = 0;
     $mValue = 0;
     if ($hPos !== false) {
         $hValue = trim(substr($data["add_show_duration"], 0, $hPos));
     }
     if ($mPos !== false) {
         $hPos = $hPos === false ? 0 : $hPos + 1;
         $mValue = trim(substr($data["add_show_duration"], $hPos, -1));
     }
     $data["add_show_duration"] = $hValue . ":" . $mValue;
     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');
         $record = $formRecord->isValid($data);
     }
     if ($data["add_show_repeats"]) {
         $repeats = $formRepeats->isValid($data);
         if ($repeats) {
             $repeats = $formRepeats->checkReliantFields($data);
         }
         if (!$isSaas) {
             $formAbsoluteRebroadcast->reset();
             //make it valid, results don't matter anyways.
             $rebroadAb = 1;
             if ($data["add_show_rebroadcast"]) {
                 $rebroad = $formRebroadcast->isValid($data);
                 if ($rebroad) {
                     $rebroad = $formRebroadcast->checkReliantFields($data);
                 }
             } else {
                 $rebroad = 1;
             }
         }
     } else {
         $repeats = 1;
         if (!$isSaas) {
             $formRebroadcast->reset();
             //make it valid, results don't matter anyways.
             $rebroad = 1;
             if ($data["add_show_rebroadcast"]) {
                 $rebroadAb = $formAbsoluteRebroadcast->isValid($data);
                 if ($rebroadAb) {
                     $rebroadAb = $formAbsoluteRebroadcast->checkReliantFields($data);
                 }
             } else {
                 $rebroadAb = 1;
             }
         }
     }
     $who = $formWho->isValid($data);
     $style = $formStyle->isValid($data);
     if ($what && $when && $repeats && $who && $style && $live) {
         if (!$isSaas) {
             if ($record && $rebroadAb && $rebroad) {
                 if ($isAdminOrPM) {
                     Application_Model_Show::create($data);
                 }
                 //send back a new form for the user.
                 Application_Model_Schedule::createNewFormSections($controller->view);
                 //$controller->view->newForm = $controller->view->render('schedule/add-show-form.phtml');
                 return true;
             } else {
                 $controller->view->what = $formWhat;
                 $controller->view->when = $formWhen;
                 $controller->view->repeats = $formRepeats;
                 $controller->view->who = $formWho;
                 $controller->view->style = $formStyle;
                 $controller->view->rr = $formRecord;
                 $controller->view->absoluteRebroadcast = $formAbsoluteRebroadcast;
                 $controller->view->rebroadcast = $formRebroadcast;
                 $controller->view->live = $formLive;
                 //$controller->view->addNewShow = !$editShow;
                 //$controller->view->form = $controller->view->render('schedule/add-show-form.phtml');
                 return false;
             }
         } else {
             if ($isAdminOrPM) {
                 Application_Model_Show::create($data);
             }
             //send back a new form for the user.
             Application_Model_Schedule::createNewFormSections($controller->view);
             //$controller->view->newForm = $controller->view->render('schedule/add-show-form.phtml');
             return true;
         }
     } else {
         $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;
         }
         //$controller->view->addNewShow = !$editShow;
         //$controller->view->form = $controller->view->render('schedule/add-show-form.phtml');
         return false;
     }
 }