Refactored adding show forms to the view
This commit is contained in:
parent
8415dfdf6f
commit
d8ced29dd0
|
@ -94,20 +94,7 @@ class ScheduleController extends Zend_Controller_Action
|
|||
$this->view->headLink()->appendStylesheet($baseUrl.'css/showbuilder.css?'.$CC_CONFIG['airtime_version']);
|
||||
//End Show builder JS/CSS requirements
|
||||
|
||||
$forms = $this->service_schedule->createShowForms();
|
||||
// populate forms with default values
|
||||
$this->service_schedule->populateNewShowForms(
|
||||
$forms["what"], $forms["when"], $forms["repeats"]);
|
||||
|
||||
$this->view->what = $forms["what"];
|
||||
$this->view->when = $forms["when"];
|
||||
$this->view->repeats = $forms["repeats"];
|
||||
$this->view->live = $forms["live"];
|
||||
$this->view->rr = $forms["record"];
|
||||
$this->view->absoluteRebroadcast = $forms["abs_rebroadcast"];
|
||||
$this->view->rebroadcast = $forms["rebroadcast"];
|
||||
$this->view->who = $forms["who"];
|
||||
$this->view->style = $forms["style"];
|
||||
$this->createShowFormAction(true);
|
||||
|
||||
$user = Application_Model_User::getCurrentUser();
|
||||
if ($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER))) {
|
||||
|
@ -746,7 +733,8 @@ class ScheduleController extends Zend_Controller_Action
|
|||
$user = Application_Model_User::getCurrentUser();
|
||||
|
||||
if ($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER))) {
|
||||
Application_Model_Schedule::createNewFormSections($this->view);
|
||||
//Application_Model_Schedule::createNewFormSections($this->view);
|
||||
$this->createShowFormAction(true);
|
||||
$this->view->form = $this->view->render('schedule/add-show-form.phtml');
|
||||
}
|
||||
}
|
||||
|
@ -879,8 +867,32 @@ class ScheduleController extends Zend_Controller_Action
|
|||
$data['add_show_day_check'] = null;
|
||||
}
|
||||
|
||||
$forms = $this->createShowFormAction();
|
||||
|
||||
$this->view->addNewShow = true;
|
||||
|
||||
if ($this->service_schedule->validateShowForms($forms, $data)) {
|
||||
$this->view->newForm = $this->view->render('schedule/add-show-form.phtml');
|
||||
$this->service_schedule->createShow($data);
|
||||
|
||||
//send new show forms to the user
|
||||
$this->createShowFormAction(true);
|
||||
Logging::debug("Show creation succeeded");
|
||||
} else {
|
||||
$this->view->form = $this->view->render('schedule/add-show-form.phtml');
|
||||
Logging::debug("Show creation failed");
|
||||
}
|
||||
}
|
||||
|
||||
public function createShowFormAction($populate=false)
|
||||
{
|
||||
$forms = $this->service_schedule->createShowForms();
|
||||
|
||||
// populate forms with default values
|
||||
if ($populate) {
|
||||
$this->populateNewShowFormsAction($forms);
|
||||
}
|
||||
|
||||
$this->view->what = $forms["what"];
|
||||
$this->view->when = $forms["when"];
|
||||
$this->view->repeats = $forms["repeats"];
|
||||
|
@ -891,16 +903,13 @@ class ScheduleController extends Zend_Controller_Action
|
|||
$this->view->who = $forms["who"];
|
||||
$this->view->style = $forms["style"];
|
||||
|
||||
$this->view->addNewShow = true;
|
||||
return $forms;
|
||||
}
|
||||
|
||||
if ($this->service_schedule->validateShowForms($forms, $data)) {
|
||||
$this->view->newForm = $this->view->render('schedule/add-show-form.phtml');
|
||||
$this->service_schedule->createShow($data);
|
||||
Logging::debug("Show creation succeeded");
|
||||
} else {
|
||||
$this->view->form = $this->view->render('schedule/add-show-form.phtml');
|
||||
Logging::debug("Show creation failed");
|
||||
}
|
||||
public function populateNewShowFormsAction($forms)
|
||||
{
|
||||
$this->service_schedule->populateNewShowForms(
|
||||
$forms["what"], $forms["when"], $forms["repeats"]);
|
||||
}
|
||||
|
||||
public function cancelShowAction()
|
||||
|
|
|
@ -67,7 +67,7 @@ class Application_Service_ShowInstanceService
|
|||
$ccShowInstance->save();
|
||||
|
||||
if ($isRebroadcast) {
|
||||
self::createRebroadcastShowInstances($showDay, $start, $ccShowInstance->getDbId());
|
||||
$this->createRebroadcastShowInstances($showDay, $start, $ccShowInstance->getDbId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -101,17 +101,14 @@ class Application_Service_ShowInstanceService
|
|||
$start = $first_show." ".$start_time;
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a DatePeriod object in the user's local time
|
||||
* It will get converted to UTC before the show instance gets created
|
||||
*/
|
||||
$period = new DatePeriod(new DateTime($start, new DateTimeZone($timezone)),
|
||||
new DateInterval($repeatInterval), $populateUntil);
|
||||
$period = $this->getDatePeriod($start, $timezone, $last_show,
|
||||
$repeatInterval, $populateUntil);
|
||||
|
||||
$utcStartDateTime = Application_Common_DateHelper::ConvertToUtcDateTime($start, $timezone);
|
||||
//convert $last_show into a UTC DateTime object, or null if there is no last show.
|
||||
$utcLastShowDateTime = $last_show ? Application_Common_DateHelper::ConvertToUtcDateTime($last_show, $timezone) : null;
|
||||
$utcLastShowDateTime = $last_show ?
|
||||
Application_Common_DateHelper::ConvertToUtcDateTime($last_show, $timezone) : null;
|
||||
|
||||
$utcEndDateTime = null;
|
||||
foreach ($period as $date) {
|
||||
list($utcStartDateTime, $utcEndDateTime) = $this->service_show->createUTCStartEndDateTime(
|
||||
$date->format("Y-m-d H:i:s"), $duration, $timezone);
|
||||
|
@ -120,7 +117,8 @@ class Application_Service_ShowInstanceService
|
|||
* last show date is null OR start date is less than last show date
|
||||
*/
|
||||
if ($utcStartDateTime->getTimestamp() <= $populateUntil->getTimestamp() &&
|
||||
is_null($utcLastShowDateTime) || $utcStartDateTime->getTimestamp() < $utcLastShowDateTime->getTimestamp()) {
|
||||
( is_null($utcLastShowDateTime) ||
|
||||
$utcStartDateTime->getTimestamp() < $utcLastShowDateTime->getTimestamp()) ) {
|
||||
|
||||
$ccShowInstance = new CcShowInstances();
|
||||
$ccShowInstance->setDbShowId($show_id);
|
||||
|
@ -130,11 +128,12 @@ class Application_Service_ShowInstanceService
|
|||
$ccShowInstance->save();
|
||||
|
||||
if ($isRebroadcast) {
|
||||
self::createRebroadcastShowInstances($showDay, $date->format("Y-m-d"), $ccShowInstance->getDbId());
|
||||
$this->createRebroadcastShowInstances($showDay, $date->format("Y-m-d"), $ccShowInstance->getDbId());
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->service_show->setNextPopulateUntilDate($nextDate, $show_id, $day);
|
||||
$nextDate = $utcEndDateTime->add(new DateInterval($repeatInterval));
|
||||
$this->service_show->setNextRepeatingShowDate($nextDate->format("Y-m-d"), $show_id, $day);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -176,4 +175,21 @@ class Application_Service_ShowInstanceService
|
|||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Create a DatePeriod object in the user's local time
|
||||
* It will get converted to UTC before the show instance gets created
|
||||
*/
|
||||
private function getDatePeriod($start, $timezone, $lastShow, $repeatInterval, $populateUntil)
|
||||
{
|
||||
if (isset($lastShow)) {
|
||||
$endDatePeriod = new DateTime($lastShow, new DateTimeZone($timezone));
|
||||
} else {
|
||||
$endDatePeriod = $populateUntil;
|
||||
}
|
||||
|
||||
return new DatePeriod(new DateTime($start, new DateTimeZone($timezone)),
|
||||
new DateInterval($repeatInterval), $endDatePeriod);
|
||||
}
|
||||
}
|
|
@ -227,7 +227,18 @@ class Application_Service_ShowService
|
|||
return array($startDateTime, $endDateTime);
|
||||
}
|
||||
|
||||
public function setNextPopulateUntilDate($nextDate, $showId, $day)
|
||||
/**
|
||||
*
|
||||
* Show instances for repeating shows only get created up
|
||||
* until what is visible on the calendar. We need to set the
|
||||
* date for when the next repeating show instance should be created
|
||||
* as the user browses the calendar further.
|
||||
*
|
||||
* @param $nextDate
|
||||
* @param $showId
|
||||
* @param $day
|
||||
*/
|
||||
public function setNextRepeatingShowDate($nextDate, $showId, $day)
|
||||
{
|
||||
$nextInfo = explode(" ", $nextDate);
|
||||
|
||||
|
|
Loading…
Reference in New Issue