Added back editing a repeating show instance feature
This commit is contained in:
parent
e259639d1a
commit
731b86b36c
5 changed files with 158 additions and 23 deletions
|
@ -22,7 +22,7 @@ class ScheduleController extends Zend_Controller_Action
|
|||
->addActionContext('get-current-playlist', 'json')
|
||||
->addActionContext('remove-group', 'json')
|
||||
->addActionContext('populate-show-form', 'json')
|
||||
->addActionContext('populate-show-instance-form', 'json')
|
||||
->addActionContext('populate-repeating-show-instance-form', 'json')
|
||||
->addActionContext('cancel-show', 'json')
|
||||
->addActionContext('cancel-current-show', 'json')
|
||||
->addActionContext('get-form', 'json')
|
||||
|
@ -30,7 +30,7 @@ class ScheduleController extends Zend_Controller_Action
|
|||
->addActionContext('content-context-menu', 'json')
|
||||
->addActionContext('set-time-scale', 'json')
|
||||
->addActionContext('set-time-interval', 'json')
|
||||
->addActionContext('edit-show-instance', 'json')
|
||||
->addActionContext('edit-repeating-show-instance', 'json')
|
||||
->addActionContext('dj-edit-show', 'json')
|
||||
->addActionContext('calculate-duration', 'json')
|
||||
->addActionContext('get-current-show', 'json')
|
||||
|
@ -365,7 +365,7 @@ class ScheduleController extends Zend_Controller_Action
|
|||
unset($this->view->showContent);
|
||||
}
|
||||
|
||||
public function populateShowInstanceFormAction()
|
||||
public function populateRepeatingShowInstanceFormAction()
|
||||
{
|
||||
$showId = $this->_getParam('showId');
|
||||
$instanceId = $this->_getParam('instanceId');
|
||||
|
@ -376,7 +376,7 @@ class ScheduleController extends Zend_Controller_Action
|
|||
$service_showForm->delegateShowInstanceFormPopulation($forms);
|
||||
|
||||
$this->view->addNewShow = false;
|
||||
$this->view->action = "edit-show-instance";
|
||||
$this->view->action = "edit-repeating-show-instance";
|
||||
$this->view->newForm = $this->view->render('schedule/add-show-form.phtml');
|
||||
}
|
||||
|
||||
|
@ -444,7 +444,7 @@ class ScheduleController extends Zend_Controller_Action
|
|||
$this->view->edit = true;
|
||||
}*/
|
||||
|
||||
/*public function editShowInstanceAction(){
|
||||
public function editRepeatingShowInstanceAction(){
|
||||
$js = $this->_getParam('data');
|
||||
$data = array();
|
||||
|
||||
|
@ -453,15 +453,39 @@ class ScheduleController extends Zend_Controller_Action
|
|||
$data[$j["name"]] = $j["value"];
|
||||
}
|
||||
|
||||
$success = Application_Model_Schedule::updateShowInstance($data, $this);
|
||||
if ($success) {
|
||||
$data['add_show_hosts'] = $this->_getParam('hosts');
|
||||
|
||||
$service_showForm = new Application_Service_ShowFormService(
|
||||
$data["add_show_id"], $data["add_show_instance_id"]);
|
||||
$service_show = new Application_Service_ShowService();
|
||||
|
||||
$forms = $this->createShowFormAction();
|
||||
|
||||
list($data, $validateStartDate, $validateStartTime, $originalShowStartDateTime) =
|
||||
$service_showForm->preEditShowValidationCheck($data);
|
||||
|
||||
if ($service_showForm->validateShowForms($forms, $data, $validateStartDate,
|
||||
$originalShowStartDateTime, true, $data["add_show_instance_id"])) {
|
||||
|
||||
//treat repeating instance has a new and separate show
|
||||
$service_show->deleteRepeatingInstance($data["add_show_instance_id"]);
|
||||
$service_show->addUpdateShow($data);
|
||||
|
||||
$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');
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
public function editShowAction()
|
||||
{
|
||||
|
|
|
@ -30,10 +30,8 @@ class Application_Service_CalendarService
|
|||
$isHostOfShow = $this->currentUser->isHostOfShow($this->showId);
|
||||
|
||||
//DateTime objects in UTC
|
||||
$startDT = new DateTime($this->ccShowInstance->getDbStarts(),
|
||||
new DateTimeZone("UTC"));
|
||||
$endDT = new DateTime($this->ccShowInstance->getDbEnds(),
|
||||
new DateTimeZone("UTC"));
|
||||
$startDT = $this->ccShowInstance->getDbStarts(null);
|
||||
$endDT = $this->ccShowInstance->getDbEnds(null);
|
||||
|
||||
//timestamps
|
||||
$start = $startDT->getTimestamp();
|
||||
|
@ -126,7 +124,7 @@ class Application_Service_CalendarService
|
|||
$menu["edit"]["items"]["instance"] = array(
|
||||
"name" => _("Edit This Instance"),
|
||||
"icon" => "edit",
|
||||
"url" => $baseUrl."Schedule/populate-show-instance-form");
|
||||
"url" => $baseUrl."Schedule/populate-repeating-show-instance-form");
|
||||
} else {
|
||||
$menu["edit"] = array(
|
||||
"name"=> _("Edit Show"),
|
||||
|
@ -141,7 +139,6 @@ class Application_Service_CalendarService
|
|||
//show is repeating so give user the option to delete all
|
||||
//repeating instances or just the one
|
||||
if ($isRepeating) {
|
||||
//create delete sub menu.
|
||||
$menu["del"] = array(
|
||||
"name"=> _("Delete"),
|
||||
"icon" => "delete",
|
||||
|
|
|
@ -8,9 +8,10 @@ class Application_Service_SchedulerService
|
|||
*/
|
||||
public static function updateScheduleStartTime($instanceIds, $diff)
|
||||
{
|
||||
$con = Propel::getConnection();
|
||||
if (count($instanceIds) > 0 && $diff != 0) {
|
||||
$showIdList = implode(",", $instanceIds);
|
||||
$sql = <<<SQL
|
||||
/*$sql = <<<SQL
|
||||
UPDATE cc_schedule
|
||||
SET starts = starts + :diff1::INTERVAL,
|
||||
ends = ends + :diff2::INTERVAL
|
||||
|
@ -20,7 +21,12 @@ SQL;
|
|||
Application_Common_Database::prepareAndExecute($sql,
|
||||
array(':diff1' => $diff, ':diff2' => $diff,
|
||||
':showIds' => $showIdList),
|
||||
'execute');
|
||||
'execute');*/
|
||||
$sql = "UPDATE cc_schedule "
|
||||
."SET starts = starts + INTERVAL '$diff sec', "
|
||||
."ends = ends + INTERVAL '$diff sec' "
|
||||
."WHERE instance_id IN ($showIdList)";
|
||||
$con->exec($sql);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -76,6 +76,17 @@ class Application_Service_ShowFormService
|
|||
public function delegateShowInstanceFormPopulation($forms)
|
||||
{
|
||||
$this->populateFormWhat($forms["what"]);
|
||||
$this->populateInstanceFormWhen($forms["when"]);
|
||||
$this->populateFormWho($forms["who"]);
|
||||
$this->populateFormLive($forms["live"]);
|
||||
$this->populateFormStyle($forms["style"]);
|
||||
|
||||
//no need to populate these forms since the user won't
|
||||
//be able to see them
|
||||
$forms["repeats"]->disable();
|
||||
$forms["record"]->disable();
|
||||
$forms["rebroadcast"]->disable();
|
||||
$forms["abs_rebroadcast"]->disable();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -92,6 +103,7 @@ class Application_Service_ShowFormService
|
|||
$this->populateFormRepeats($forms["repeats"]);
|
||||
$this->populateFormWho($forms["who"]);
|
||||
$this->populateFormStyle($forms["style"]);
|
||||
$this->populateFormLive($forms["live"]);
|
||||
$this->populateFormRecord($forms["record"]);
|
||||
$this->populateFormRebroadcastRelative($forms["rebroadcast"]);
|
||||
$this->populateFormRebroadcastAbsolute($forms["abs_rebroadcast"]);
|
||||
|
@ -137,6 +149,36 @@ class Application_Service_ShowFormService
|
|||
'add_show_repeats' => $ccShowDay->isRepeating() ? 1 : 0));
|
||||
}
|
||||
|
||||
private function populateInstanceFormWhen($form)
|
||||
{
|
||||
$ccShowInstance = CcShowInstancesQuery::create()->findPk($this->instanceId);
|
||||
|
||||
$timezone = new DateTimeZone(Application_Model_Preference::GetTimezone());
|
||||
//DateTime object in UTC
|
||||
$showStart = $ccShowInstance->getDbStarts(null);
|
||||
$showStart->setTimezone($timezone);
|
||||
|
||||
$showEnd = $ccShowInstance->getDbEnds(null);
|
||||
$showEnd->setTimezone($timezone);
|
||||
|
||||
//if the show has started, do not allow editing on the start time
|
||||
if ($showStart->getTimestamp() <= time()) {
|
||||
$form->disableStartDateAndTime();
|
||||
}
|
||||
|
||||
$form->populate(
|
||||
array(
|
||||
'add_show_start_date' => $showStart->format("Y-m-d"),
|
||||
'add_show_start_time' => $showStart->format("H:i"),
|
||||
'add_show_end_date_no_repeat' => $showEnd->format("Y-m-d"),
|
||||
'add_show_end_time' => $showEnd->format("H:i"),
|
||||
'add_show_duration' => $this->calculateDuration(
|
||||
$showStart->format("Y-m-d H:i:s"), $showEnd->format("Y-m-d H:i:s")),
|
||||
'add_show_repeats' => 0));
|
||||
|
||||
$form->getElement('add_show_repeats')->setOptions(array("disabled" => true));
|
||||
}
|
||||
|
||||
private function populateFormRepeats($form)
|
||||
{
|
||||
$ccShowDays = $this->ccShow->getCcShowDays();
|
||||
|
@ -194,6 +236,16 @@ class Application_Service_ShowFormService
|
|||
'add_show_color' => $this->ccShow->getDbColor()));
|
||||
}
|
||||
|
||||
private function populateFormLive($form)
|
||||
{
|
||||
$form->populate(
|
||||
array(
|
||||
"cb_airtime_auth" => $this->ccShow->getDbLiveStreamUsingAirtimeAuth(),
|
||||
"cb_custom_auth" => $this->ccShow->getDbLiveStreamUsingCustomAuth(),
|
||||
"custom_username" => $this->ccShow->getDbLiveStreamUser(),
|
||||
"custom_password" => $this->ccShow->getDbLiveStreamPass()));
|
||||
}
|
||||
|
||||
private function populateFormRecord($form)
|
||||
{
|
||||
$form->populate(
|
||||
|
@ -388,7 +440,7 @@ SQL;
|
|||
$sign = $duration->format('%r');
|
||||
return sprintf('%s%02dh %02dm', $sign, $hour, $min);
|
||||
} else {
|
||||
return $duration->format('%r%Hh %Im');
|
||||
return $duration->format('%Hh %Im');
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
return "Invalid Date";
|
||||
|
|
|
@ -17,6 +17,19 @@ class Application_Service_ShowService
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* When the user is editing a single instance of a repeating show
|
||||
* we want to treat it as a completely new show so we need to delete
|
||||
* the instance first
|
||||
*
|
||||
* @param $instanceId
|
||||
*/
|
||||
public function deleteRepeatingInstance($instanceId)
|
||||
{
|
||||
CcShowInstancesQuery::create()->findPk($instanceId)->delete();
|
||||
}
|
||||
|
||||
public function addUpdateShow($showData, $isUpdate=false)
|
||||
{
|
||||
$service_user = new Application_Service_UserService();
|
||||
|
@ -30,7 +43,6 @@ class Application_Service_ShowService
|
|||
} else {
|
||||
$repeatType = -1;
|
||||
}
|
||||
//$repeatType = ($showData['add_show_repeats']) ? $showData['add_show_repeat_type'] : -1;
|
||||
$isRecorded = (isset($showData['add_show_record']) && $showData['add_show_record']) ? 1 : 0;
|
||||
$isRebroadcast = (isset($showData['add_show_rebroadcast']) && $showData['add_show_rebroadcast']) ? 1 : 0;
|
||||
|
||||
|
@ -40,7 +52,7 @@ class Application_Service_ShowService
|
|||
$con = Propel::getConnection();
|
||||
$con->beginTransaction();
|
||||
try {
|
||||
if (!$this->currentUser->isAdminOrPM()) {
|
||||
if (!$currentUser->isAdminOrPM()) {
|
||||
throw new Exception("Permission denied");
|
||||
}
|
||||
//update ccShow
|
||||
|
@ -52,7 +64,7 @@ class Application_Service_ShowService
|
|||
// schedule start/end times
|
||||
$this->applyShowStartEndDifference($showData);
|
||||
$this->deleteRebroadcastInstances();
|
||||
$this->deleteCcShowDays();
|
||||
//$this->deleteCcShowDays();
|
||||
$this->deleteCcShowHosts();
|
||||
if ($isRebroadcast) {
|
||||
//delete entry in cc_show_rebroadcast
|
||||
|
@ -105,7 +117,7 @@ class Application_Service_ShowService
|
|||
if (!is_null($end)) {
|
||||
$populateUntil = $end;
|
||||
}
|
||||
|
||||
Logging::info($ccShowDays);
|
||||
foreach ($ccShowDays as $day) {
|
||||
switch ($day->getDbRepeatType()) {
|
||||
case NO_REPEAT:
|
||||
|
@ -379,6 +391,14 @@ SQL;
|
|||
}
|
||||
}
|
||||
|
||||
foreach ($daysRemoved as $day) {
|
||||
//delete the cc_show_day entries as well
|
||||
CcShowDaysQuery::create()
|
||||
->filterByDbShowId($showId)
|
||||
->filterByDbDay($day)
|
||||
->delete();
|
||||
}
|
||||
|
||||
$uncheckedDays = pg_escape_string(implode(",", $daysRemovedUTC));
|
||||
|
||||
$sql = <<<SQL
|
||||
|
@ -392,6 +412,7 @@ SQL;
|
|||
Application_Common_Database::prepareAndExecute( $sql, array(
|
||||
":timestamp" => gmdate("Y-m-d H:i:s"), ":showId" => $showId),
|
||||
"execute");
|
||||
|
||||
}
|
||||
|
||||
private function deleteAllInstances($showId)
|
||||
|
@ -857,6 +878,27 @@ SQL;
|
|||
}
|
||||
}
|
||||
|
||||
private function hasCcShowDay($repeatType, $day)
|
||||
{
|
||||
return $this->getCcShowDay($repeatType, $day) ? true : false;
|
||||
}
|
||||
|
||||
private function getCcShowDay($repeatType, $day)
|
||||
{
|
||||
$ccShowDay = CcShowDaysQuery::create()
|
||||
->filterByDbShowId($this->ccShow->getDbId())
|
||||
->filterByDbDay($day)
|
||||
->filterByDbRepeatType($repeatType)
|
||||
->limit(1)
|
||||
->find();
|
||||
|
||||
if ($ccShowDay->isEmpty()) {
|
||||
return false;
|
||||
} else {
|
||||
return $ccShowDay[0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Sets the fields for a cc_show table row
|
||||
|
@ -923,7 +965,11 @@ SQL;
|
|||
|
||||
// Don't set day for monthly repeat type, it's invalid
|
||||
if ($showData['add_show_repeats'] && $showData['add_show_repeat_type'] == 2) {
|
||||
$showDay = new CcShowDays();
|
||||
if ($this->hasCcShowDay($repeatType, null)) {
|
||||
$showDay = $this->getCcShowDay($repeatType, null);
|
||||
} else {
|
||||
$showDay = new CcShowDays();
|
||||
}
|
||||
$showDay->setDbFirstShow($startDateTime->format("Y-m-d"));
|
||||
$showDay->setDbLastShow($endDate);
|
||||
$showDay->setDbStartTime($startDateTime->format("H:i:s"));
|
||||
|
@ -932,6 +978,9 @@ SQL;
|
|||
$showDay->setDbRepeatType($repeatType);
|
||||
$showDay->setDbShowId($showId);
|
||||
$showDay->setDbRecord($isRecorded);
|
||||
//in case we are editing a show we need to set this to the first show
|
||||
//so when editing, the date period iterator will start from the beginning
|
||||
$showDay->setDbNextPopDate($startDateTime->format("Y-m-d"));
|
||||
$showDay->save();
|
||||
} else {
|
||||
foreach ($showData['add_show_day_check'] as $day) {
|
||||
|
@ -946,7 +995,11 @@ SQL;
|
|||
$startDateTimeClone->add(new DateInterval("P".$daysAdd."D"));
|
||||
}
|
||||
if (is_null($endDate) || $startDateTimeClone->getTimestamp() <= $endDateTime->getTimestamp()) {
|
||||
$showDay = new CcShowDays();
|
||||
if ($this->hasCcShowDay($repeatType, $day)) {
|
||||
$showDay = $this->getCcShowDay($repeatType, $day);
|
||||
} else {
|
||||
$showDay = new CcShowDays();
|
||||
}
|
||||
$showDay->setDbFirstShow($startDateTimeClone->format("Y-m-d"));
|
||||
$showDay->setDbLastShow($endDate);
|
||||
$showDay->setDbStartTime($startDateTimeClone->format("H:i"));
|
||||
|
@ -956,6 +1009,9 @@ SQL;
|
|||
$showDay->setDbRepeatType($repeatType);
|
||||
$showDay->setDbShowId($showId);
|
||||
$showDay->setDbRecord($isRecorded);
|
||||
//in case we are editing a show we need to set this to the first show
|
||||
//so when editing, the date period iterator will start from the beginning
|
||||
$showDay->setDbNextPopDate($startDateTimeClone->format("Y-m-d"));
|
||||
$showDay->save();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue