Refactored adding show forms to the view

This commit is contained in:
denise 2013-03-08 16:08:43 -05:00
parent 8415dfdf6f
commit d8ced29dd0
3 changed files with 73 additions and 37 deletions

View File

@ -94,20 +94,7 @@ class ScheduleController extends Zend_Controller_Action
$this->view->headLink()->appendStylesheet($baseUrl.'css/showbuilder.css?'.$CC_CONFIG['airtime_version']); $this->view->headLink()->appendStylesheet($baseUrl.'css/showbuilder.css?'.$CC_CONFIG['airtime_version']);
//End Show builder JS/CSS requirements //End Show builder JS/CSS requirements
$forms = $this->service_schedule->createShowForms(); $this->createShowFormAction(true);
// 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"];
$user = Application_Model_User::getCurrentUser(); $user = Application_Model_User::getCurrentUser();
if ($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER))) { if ($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER))) {
@ -746,7 +733,8 @@ class ScheduleController extends Zend_Controller_Action
$user = Application_Model_User::getCurrentUser(); $user = Application_Model_User::getCurrentUser();
if ($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER))) { 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'); $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; $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(); $forms = $this->service_schedule->createShowForms();
// populate forms with default values
if ($populate) {
$this->populateNewShowFormsAction($forms);
}
$this->view->what = $forms["what"]; $this->view->what = $forms["what"];
$this->view->when = $forms["when"]; $this->view->when = $forms["when"];
$this->view->repeats = $forms["repeats"]; $this->view->repeats = $forms["repeats"];
@ -891,16 +903,13 @@ class ScheduleController extends Zend_Controller_Action
$this->view->who = $forms["who"]; $this->view->who = $forms["who"];
$this->view->style = $forms["style"]; $this->view->style = $forms["style"];
$this->view->addNewShow = true; return $forms;
}
if ($this->service_schedule->validateShowForms($forms, $data)) { public function populateNewShowFormsAction($forms)
$this->view->newForm = $this->view->render('schedule/add-show-form.phtml'); {
$this->service_schedule->createShow($data); $this->service_schedule->populateNewShowForms(
Logging::debug("Show creation succeeded"); $forms["what"], $forms["when"], $forms["repeats"]);
} else {
$this->view->form = $this->view->render('schedule/add-show-form.phtml');
Logging::debug("Show creation failed");
}
} }
public function cancelShowAction() public function cancelShowAction()

View File

@ -67,7 +67,7 @@ class Application_Service_ShowInstanceService
$ccShowInstance->save(); $ccShowInstance->save();
if ($isRebroadcast) { 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; $start = $first_show." ".$start_time;
} }
/* $period = $this->getDatePeriod($start, $timezone, $last_show,
* Create a DatePeriod object in the user's local time $repeatInterval, $populateUntil);
* 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);
$utcStartDateTime = Application_Common_DateHelper::ConvertToUtcDateTime($start, $timezone); $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 ?
$utcLastShowDateTime = $last_show ? Application_Common_DateHelper::ConvertToUtcDateTime($last_show, $timezone) : null; Application_Common_DateHelper::ConvertToUtcDateTime($last_show, $timezone) : null;
$utcEndDateTime = null;
foreach ($period as $date) { foreach ($period as $date) {
list($utcStartDateTime, $utcEndDateTime) = $this->service_show->createUTCStartEndDateTime( list($utcStartDateTime, $utcEndDateTime) = $this->service_show->createUTCStartEndDateTime(
$date->format("Y-m-d H:i:s"), $duration, $timezone); $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 * last show date is null OR start date is less than last show date
*/ */
if ($utcStartDateTime->getTimestamp() <= $populateUntil->getTimestamp() && if ($utcStartDateTime->getTimestamp() <= $populateUntil->getTimestamp() &&
is_null($utcLastShowDateTime) || $utcStartDateTime->getTimestamp() < $utcLastShowDateTime->getTimestamp()) { ( is_null($utcLastShowDateTime) ||
$utcStartDateTime->getTimestamp() < $utcLastShowDateTime->getTimestamp()) ) {
$ccShowInstance = new CcShowInstances(); $ccShowInstance = new CcShowInstances();
$ccShowInstance->setDbShowId($show_id); $ccShowInstance->setDbShowId($show_id);
@ -130,11 +128,12 @@ class Application_Service_ShowInstanceService
$ccShowInstance->save(); $ccShowInstance->save();
if ($isRebroadcast) { 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);
}
} }

View File

@ -227,7 +227,18 @@ class Application_Service_ShowService
return array($startDateTime, $endDateTime); 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); $nextInfo = explode(" ", $nextDate);