CC-4961: Show linking
Refactoring all services thus far
This commit is contained in:
parent
5735baf237
commit
896e03d76b
7 changed files with 612 additions and 417 deletions
|
@ -5,7 +5,7 @@ class ScheduleController extends Zend_Controller_Action
|
||||||
|
|
||||||
protected $sched_sess = null;
|
protected $sched_sess = null;
|
||||||
|
|
||||||
private $service_schedule;
|
private $service_calendar;
|
||||||
|
|
||||||
public function init()
|
public function init()
|
||||||
{
|
{
|
||||||
|
@ -41,7 +41,7 @@ class ScheduleController extends Zend_Controller_Action
|
||||||
|
|
||||||
$this->sched_sess = new Zend_Session_Namespace("schedule");
|
$this->sched_sess = new Zend_Session_Namespace("schedule");
|
||||||
|
|
||||||
$this->service_schedule = new Application_Service_ScheduleService();
|
$this->service_calendar = new Application_Service_CalendarService();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function indexAction()
|
public function indexAction()
|
||||||
|
@ -798,12 +798,13 @@ class ScheduleController extends Zend_Controller_Action
|
||||||
$forms = $this->createShowFormAction();
|
$forms = $this->createShowFormAction();
|
||||||
|
|
||||||
list($data, $validateStartDate, $validateStartTime, $originalShowStartDateTime) =
|
list($data, $validateStartDate, $validateStartTime, $originalShowStartDateTime) =
|
||||||
$this->service_schedule->preEditShowValidationCheck($data);
|
$this->service_calendar->preEditShowValidationCheck($data);
|
||||||
|
|
||||||
if ($this->service_schedule->validateShowForms($forms, $data, $validateStartDate,
|
if ($this->service_calendar->validateShowForms($forms, $data, $validateStartDate,
|
||||||
$originalShowStartDateTime, true, $data["add_show_instance_id"])) {
|
$originalShowStartDateTime, true, $data["add_show_instance_id"])) {
|
||||||
|
|
||||||
$this->service_schedule->editShow($data);
|
//pass in true to indicate we are updating a show
|
||||||
|
$this->service_calendar->addUpdateShow($data, true);
|
||||||
|
|
||||||
$scheduler = new Application_Model_Scheduler();
|
$scheduler = new Application_Model_Scheduler();
|
||||||
$showInstances = CcShowInstancesQuery::create()->filterByDbShowId($data['add_show_id'])->find();
|
$showInstances = CcShowInstancesQuery::create()->filterByDbShowId($data['add_show_id'])->find();
|
||||||
|
@ -848,8 +849,8 @@ class ScheduleController extends Zend_Controller_Action
|
||||||
|
|
||||||
$this->view->addNewShow = true;
|
$this->view->addNewShow = true;
|
||||||
|
|
||||||
if ($this->service_schedule->validateShowForms($forms, $data)) {
|
if ($this->service_calendar->validateShowForms($forms, $data)) {
|
||||||
$this->service_schedule->createShow($data);
|
$this->service_calendar->addUpdateShow($data);
|
||||||
|
|
||||||
$this->view->newForm = $this->view->render('schedule/add-show-form.phtml');
|
$this->view->newForm = $this->view->render('schedule/add-show-form.phtml');
|
||||||
//send new show forms to the user
|
//send new show forms to the user
|
||||||
|
@ -864,7 +865,7 @@ class ScheduleController extends Zend_Controller_Action
|
||||||
|
|
||||||
public function createShowFormAction($populate=false)
|
public function createShowFormAction($populate=false)
|
||||||
{
|
{
|
||||||
$forms = $this->service_schedule->createShowForms();
|
$forms = $this->service_calendar->createShowForms();
|
||||||
|
|
||||||
// populate forms with default values
|
// populate forms with default values
|
||||||
if ($populate) {
|
if ($populate) {
|
||||||
|
@ -886,7 +887,7 @@ class ScheduleController extends Zend_Controller_Action
|
||||||
|
|
||||||
public function populateNewShowFormsAction($forms)
|
public function populateNewShowFormsAction($forms)
|
||||||
{
|
{
|
||||||
$this->service_schedule->populateNewShowForms(
|
$this->service_calendar->populateNewShowForms(
|
||||||
$forms["what"], $forms["when"], $forms["repeats"]);
|
$forms["what"], $forms["when"], $forms["repeats"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1169,17 +1169,17 @@ SQL;
|
||||||
|
|
||||||
/*$isRecorded = (isset($data['add_show_record']) && $data['add_show_record']) ? 1 : 0;*/
|
/*$isRecorded = (isset($data['add_show_record']) && $data['add_show_record']) ? 1 : 0;*/
|
||||||
|
|
||||||
if ($data['add_show_id'] != -1) {
|
/*if ($data['add_show_id'] != -1) {
|
||||||
$show = new Application_Model_Show($showId);
|
$show = new Application_Model_Show($showId);
|
||||||
//CC-4150 CULPRIT
|
//CC-4150 CULPRIT
|
||||||
$show->deletePossiblyInvalidInstances($data, $endDate, $isRecorded, $repeatType);
|
$show->deletePossiblyInvalidInstances($data, $endDate, $isRecorded, $repeatType);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
//check if we are adding or updating a show, and if updating
|
//check if we are adding or updating a show, and if updating
|
||||||
//erase all the show's show_days information first.
|
//erase all the show's show_days information first.
|
||||||
if ($data['add_show_id'] != -1) {
|
/*if ($data['add_show_id'] != -1) {
|
||||||
CcShowDaysQuery::create()->filterByDbShowId($data['add_show_id'])->delete();
|
CcShowDaysQuery::create()->filterByDbShowId($data['add_show_id'])->delete();
|
||||||
}
|
}*/
|
||||||
|
|
||||||
//don't set day for monthly repeat type, it's invalid.
|
//don't set day for monthly repeat type, it's invalid.
|
||||||
/*if ($data['add_show_repeats'] && $data['add_show_repeat_type'] == 2) {
|
/*if ($data['add_show_repeats'] && $data['add_show_repeat_type'] == 2) {
|
||||||
|
@ -1223,11 +1223,11 @@ SQL;
|
||||||
|
|
||||||
//check if we are adding or updating a show, and if updating
|
//check if we are adding or updating a show, and if updating
|
||||||
//erase all the show's future show_rebroadcast information first.
|
//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']) {
|
/*if (($data['add_show_id'] != -1) && isset($data['add_show_rebroadcast']) && $data['add_show_rebroadcast']) {
|
||||||
CcShowRebroadcastQuery::create()
|
CcShowRebroadcastQuery::create()
|
||||||
->filterByDbShowId($data['add_show_id'])
|
->filterByDbShowId($data['add_show_id'])
|
||||||
->delete();
|
->delete();
|
||||||
}
|
}*/
|
||||||
//adding rows to cc_show_rebroadcast
|
//adding rows to cc_show_rebroadcast
|
||||||
/* TODO: Document magic constant 10 and define it properly somewhere
|
/* TODO: Document magic constant 10 and define it properly somewhere
|
||||||
--RG */
|
--RG */
|
||||||
|
@ -1272,9 +1272,9 @@ SQL;
|
||||||
|
|
||||||
//check if we are adding or updating a show, and if updating
|
//check if we are adding or updating a show, and if updating
|
||||||
//erase all the show's show_rebroadcast information first.
|
//erase all the show's show_rebroadcast information first.
|
||||||
if ($data['add_show_id'] != -1) {
|
/*if ($data['add_show_id'] != -1) {
|
||||||
CcShowHostsQuery::create()->filterByDbShow($data['add_show_id'])->delete();
|
CcShowHostsQuery::create()->filterByDbShow($data['add_show_id'])->delete();
|
||||||
}
|
}*/
|
||||||
/*if (is_array($data['add_show_hosts'])) {
|
/*if (is_array($data['add_show_hosts'])) {
|
||||||
//add selected hosts to cc_show_hosts table.
|
//add selected hosts to cc_show_hosts table.
|
||||||
foreach ($data['add_show_hosts'] as $host) {
|
foreach ($data['add_show_hosts'] as $host) {
|
||||||
|
@ -1285,7 +1285,7 @@ SQL;
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
if ($data['add_show_id'] != -1) {
|
/*if ($data['add_show_id'] != -1) {
|
||||||
$con = Propel::getConnection(CcSchedulePeer::DATABASE_NAME);
|
$con = Propel::getConnection(CcSchedulePeer::DATABASE_NAME);
|
||||||
$con->beginTransaction();
|
$con->beginTransaction();
|
||||||
|
|
||||||
|
@ -1310,12 +1310,12 @@ SQL;
|
||||||
Logging::info("Couldn't update schedule status.");
|
Logging::info("Couldn't update schedule status.");
|
||||||
Logging::info($e->getMessage());
|
Logging::info($e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
/*Application_Model_Show::populateShowUntil($showId);
|
/*Application_Model_Show::populateShowUntil($showId);
|
||||||
Application_Model_RabbitMq::PushSchedule();*/
|
Application_Model_RabbitMq::PushSchedule();*/
|
||||||
|
|
||||||
return $showId;
|
/*return $showId;*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1399,39 +1399,39 @@ SQL;
|
||||||
if ($utcStartDateTime->getTimestamp() < $p_populateUntilDateTime->getTimestamp()) {
|
if ($utcStartDateTime->getTimestamp() < $p_populateUntilDateTime->getTimestamp()) {
|
||||||
$currentUtcTimestamp = gmdate("Y-m-d H:i:s");*/
|
$currentUtcTimestamp = gmdate("Y-m-d H:i:s");*/
|
||||||
|
|
||||||
$show = new Application_Model_Show($show_id);
|
/*$show = new Application_Model_Show($show_id);
|
||||||
if ($show->hasInstance()) {
|
if ($show->hasInstance()) {
|
||||||
$ccShowInstance = $show->getInstance();
|
$ccShowInstance = $show->getInstance();
|
||||||
$newInstance = false;
|
$newInstance = false;
|
||||||
} /*else {
|
}*/ /*else {
|
||||||
$ccShowInstance = new CcShowInstances();
|
$ccShowInstance = new CcShowInstances();
|
||||||
$newInstance = true;
|
$newInstance = true;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
if ($newInstance || $ccShowInstance->getDbStarts() > $currentUtcTimestamp) {
|
/*if ($newInstance || $ccShowInstance->getDbStarts() > $currentUtcTimestamp) {
|
||||||
$ccShowInstance->setDbShowId($show_id);
|
$ccShowInstance->setDbShowId($show_id);
|
||||||
$ccShowInstance->setDbStarts($utcStartDateTime);
|
$ccShowInstance->setDbStarts($utcStartDateTime);
|
||||||
$ccShowInstance->setDbEnds($utcEndDateTime);
|
$ccShowInstance->setDbEnds($utcEndDateTime);
|
||||||
$ccShowInstance->setDbRecord($record);
|
$ccShowInstance->setDbRecord($record);
|
||||||
$ccShowInstance->save();
|
$ccShowInstance->save();
|
||||||
}
|
}*/
|
||||||
|
|
||||||
$show_instance_id = $ccShowInstance->getDbId();
|
/* $show_instance_id = $ccShowInstance->getDbId();
|
||||||
$showInstance = new Application_Model_ShowInstance($show_instance_id);
|
$showInstance = new Application_Model_ShowInstance($show_instance_id);*/
|
||||||
|
|
||||||
if (!$newInstance) {
|
/*if (!$newInstance) {
|
||||||
$showInstance->correctScheduleStartTimes();
|
$showInstance->correctScheduleStartTimes();
|
||||||
}
|
}*/
|
||||||
|
|
||||||
/*$sql = "SELECT * FROM cc_show_rebroadcast WHERE show_id=:show_id";
|
/*$sql = "SELECT * FROM cc_show_rebroadcast WHERE show_id=:show_id";
|
||||||
$rebroadcasts = Application_Common_Database::prepareAndExecute($sql,
|
$rebroadcasts = Application_Common_Database::prepareAndExecute($sql,
|
||||||
array( ':show_id' => $show_id ), 'all');*/
|
array( ':show_id' => $show_id ), 'all');*/
|
||||||
|
|
||||||
if ($showInstance->isRecorded()) {
|
/*if ($showInstance->isRecorded()) {
|
||||||
//only do this for editing
|
//only do this for editing
|
||||||
$showInstance->deleteRebroadcasts();
|
$showInstance->deleteRebroadcasts();
|
||||||
self::createRebroadcastInstances($rebroadcasts, $currentUtcTimestamp, $show_id, $show_instance_id, $start, $duration, $timezone);
|
self::createRebroadcastInstances($rebroadcasts, $currentUtcTimestamp, $show_id, $show_instance_id, $start, $duration, $timezone);
|
||||||
}
|
}*/
|
||||||
/*}*/
|
/*}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1471,21 +1471,21 @@ SQL;
|
||||||
//convert $last_show into a UTC DateTime object, or null if there is no last show.
|
//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;*/
|
||||||
|
|
||||||
$sql = "SELECT * FROM cc_show_rebroadcast WHERE show_id=:show_id";
|
/*$sql = "SELECT * FROM cc_show_rebroadcast WHERE show_id=:show_id";
|
||||||
|
|
||||||
$rebroadcasts = Application_Common_Database::prepareAndExecute( $sql,
|
$rebroadcasts = Application_Common_Database::prepareAndExecute( $sql,
|
||||||
array( ':show_id' => $show_id ), 'all');
|
array( ':show_id' => $show_id ), 'all');
|
||||||
|
|
||||||
$show = new Application_Model_Show($show_id);
|
$show = new Application_Model_Show($show_id);*/
|
||||||
|
|
||||||
while ($utcStartDateTime->getTimestamp() <= $p_populateUntilDateTime->getTimestamp()
|
/*while ($utcStartDateTime->getTimestamp() <= $p_populateUntilDateTime->getTimestamp()
|
||||||
&& (is_null($utcLastShowDateTime) || $utcStartDateTime->getTimestamp() < $utcLastShowDateTime->getTimestamp())){
|
&& (is_null($utcLastShowDateTime) || $utcStartDateTime->getTimestamp() < $utcLastShowDateTime->getTimestamp())){*/
|
||||||
|
|
||||||
list($utcStartDateTime, $utcEndDateTime) = self::createUTCStartEndDateTime($start, $duration, $timezone);
|
/*list($utcStartDateTime, $utcEndDateTime) = self::createUTCStartEndDateTime($start, $duration, $timezone);*/
|
||||||
|
|
||||||
//determine if we are adding a new show
|
//determine if we are adding a new show
|
||||||
//or editing a show
|
//or editing a show
|
||||||
if ($show->hasInstanceOnDate($utcStartDateTime)) {
|
/* if ($show->hasInstanceOnDate($utcStartDateTime)) {
|
||||||
$ccShowInstance = $show->getInstanceOnDate($utcStartDateTime);
|
$ccShowInstance = $show->getInstanceOnDate($utcStartDateTime);
|
||||||
|
|
||||||
if ($ccShowInstance->getDbModifiedInstance()) {
|
if ($ccShowInstance->getDbModifiedInstance()) {
|
||||||
|
@ -1498,12 +1498,12 @@ SQL;
|
||||||
} else {
|
} else {
|
||||||
$ccShowInstance = new CcShowInstances();
|
$ccShowInstance = new CcShowInstances();
|
||||||
$newInstance = true;
|
$newInstance = true;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
/* When editing the start/end time of a repeating show, we don't want to
|
/* When editing the start/end time of a repeating show, we don't want to
|
||||||
* change shows that started in the past. So check the start time.
|
* change shows that started in the past. So check the start time.
|
||||||
*/
|
*/
|
||||||
if ($newInstance || $ccShowInstance->getDbStarts() > $currentUtcTimestamp) {
|
/*if ($newInstance || $ccShowInstance->getDbStarts() > $currentUtcTimestamp) {
|
||||||
$ccShowInstance->setDbShowId($show_id);
|
$ccShowInstance->setDbShowId($show_id);
|
||||||
$ccShowInstance->setDbStarts($utcStartDateTime);
|
$ccShowInstance->setDbStarts($utcStartDateTime);
|
||||||
$ccShowInstance->setDbEnds($utcEndDateTime);
|
$ccShowInstance->setDbEnds($utcEndDateTime);
|
||||||
|
@ -1513,21 +1513,22 @@ SQL;
|
||||||
|
|
||||||
|
|
||||||
$show_instance_id = $ccShowInstance->getDbId();
|
$show_instance_id = $ccShowInstance->getDbId();
|
||||||
$showInstance = new Application_Model_ShowInstance($show_instance_id);
|
$showInstance = new Application_Model_ShowInstance($show_instance_id);*/
|
||||||
|
|
||||||
/* If we are updating a show then make sure that the scheduled content within
|
/* If we are updating a show then make sure that the scheduled content within
|
||||||
* the show is updated to the correct time. */
|
* the show is updated to the correct time. */
|
||||||
if (!$newInstance) {
|
// don't we already do this in deletePossiblyInvalidInstances???
|
||||||
|
/*if (!$newInstance) {
|
||||||
$showInstance->correctScheduleStartTimes();
|
$showInstance->correctScheduleStartTimes();
|
||||||
}
|
}*/
|
||||||
|
|
||||||
$showInstance->deleteRebroadcasts();
|
/*$showInstance->deleteRebroadcasts();
|
||||||
self::createRebroadcastInstances($rebroadcasts, $currentUtcTimestamp, $show_id, $show_instance_id, $start, $duration, $timezone);
|
self::createRebroadcastInstances($rebroadcasts, $currentUtcTimestamp, $show_id, $show_instance_id, $start, $duration, $timezone);
|
||||||
list($start, $utcStartDateTime) = self::advanceRepeatingDate($p_interval, $start, $timezone);
|
list($start, $utcStartDateTime) = self::advanceRepeatingDate($p_interval, $start, $timezone);*/
|
||||||
|
|
||||||
}
|
/*}*/
|
||||||
|
|
||||||
Application_Model_Show::setNextPop($start, $show_id, $day);
|
/*Application_Model_Show::setNextPop($start, $show_id, $day);*/
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function advanceRepeatingDate($p_interval, $start, $timezone)
|
private static function advanceRepeatingDate($p_interval, $start, $timezone)
|
||||||
|
@ -1581,7 +1582,7 @@ SQL;
|
||||||
*/
|
*/
|
||||||
private static function createUTCStartEndDateTime($p_start, $p_duration, $p_timezone=null, $p_offset=null)
|
private static function createUTCStartEndDateTime($p_start, $p_duration, $p_timezone=null, $p_offset=null)
|
||||||
{
|
{
|
||||||
$timezone = $p_timezone ? $p_timezone : date_default_timezone_get();
|
/*$timezone = $p_timezone ? $p_timezone : date_default_timezone_get();
|
||||||
|
|
||||||
$startDateTime = new DateTime($p_start, new DateTimeZone($timezone));
|
$startDateTime = new DateTime($p_start, new DateTimeZone($timezone));
|
||||||
if (isset($p_offset)) {
|
if (isset($p_offset)) {
|
||||||
|
@ -1595,7 +1596,7 @@ SQL;
|
||||||
list($hours, $mins) = array_slice($duration, 0, 2);
|
list($hours, $mins) = array_slice($duration, 0, 2);
|
||||||
$endDateTime->add(new DateInterval("PT{$hours}H{$mins}M"));
|
$endDateTime->add(new DateInterval("PT{$hours}H{$mins}M"));
|
||||||
|
|
||||||
return array($startDateTime, $endDateTime);
|
return array($startDateTime, $endDateTime);*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create rebroadcast instances for a created show marked for recording
|
/* Create rebroadcast instances for a created show marked for recording
|
||||||
|
@ -1621,7 +1622,7 @@ SQL;
|
||||||
{
|
{
|
||||||
//Y-m-d
|
//Y-m-d
|
||||||
//use only the date part of the show start time stamp for the offsets to work properly.
|
//use only the date part of the show start time stamp for the offsets to work properly.
|
||||||
$date = explode(" ", $p_startTime);
|
/*$date = explode(" ", $p_startTime);
|
||||||
$start_date = $date[0];
|
$start_date = $date[0];
|
||||||
|
|
||||||
foreach ($p_rebroadcasts as $rebroadcast) {
|
foreach ($p_rebroadcasts as $rebroadcast) {
|
||||||
|
@ -1643,7 +1644,7 @@ SQL;
|
||||||
$newRebroadcastInstance->setDbOriginalShow($p_showInstanceId);
|
$newRebroadcastInstance->setDbOriginalShow($p_showInstanceId);
|
||||||
$newRebroadcastInstance->save();
|
$newRebroadcastInstance->save();
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
271
airtime_mvc/application/services/CalendarService.php
Normal file
271
airtime_mvc/application/services/CalendarService.php
Normal file
|
@ -0,0 +1,271 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class Application_Service_CalendarService
|
||||||
|
{
|
||||||
|
private $service_show;
|
||||||
|
private $service_showDays;
|
||||||
|
private $service_showInstances;
|
||||||
|
private $service_user;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->service_show = new Application_Service_ShowService();
|
||||||
|
$this->service_showInstances = new Application_Service_ShowInstanceService();
|
||||||
|
$this->service_user = new Application_Service_UserService();
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* Form stuff begins here
|
||||||
|
* Typically I would keep form creation and validation
|
||||||
|
* in the controller but since shows require 9 forms,
|
||||||
|
* the controller will become too fat.
|
||||||
|
* Maybe we should create a special form show service?
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return array of schedule 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Popluates the what, when, and repeat forms
|
||||||
|
* with default values
|
||||||
|
*/
|
||||||
|
public function populateNewShowForms($formWhat, $formWhen, $formRepeats)
|
||||||
|
{
|
||||||
|
$formWhat->populate(
|
||||||
|
array('add_show_id' => '-1',
|
||||||
|
'add_show_instance_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' => '01h 00m'));
|
||||||
|
|
||||||
|
$formRepeats->populate(array('add_show_end_date' => date("Y-m-d")));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function populateForm($form, $values)
|
||||||
|
{
|
||||||
|
$form->populate($values);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Validates show forms
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function validateShowForms($forms, $formData, $validateStartDate = true,
|
||||||
|
$originalStartDate=null, $editShow=false, $instanceId=null)
|
||||||
|
{
|
||||||
|
$what = $forms["what"]->isValid($formData);
|
||||||
|
$live = $forms["live"]->isValid($formData);
|
||||||
|
$record = $forms["record"]->isValid($formData);
|
||||||
|
$who = $forms["who"]->isValid($formData);
|
||||||
|
$style = $forms["style"]->isValid($formData);
|
||||||
|
$when = $forms["when"]->isWhenFormValid($formData, $validateStartDate,
|
||||||
|
$originalStartDate, $editShow, $instanceId);
|
||||||
|
|
||||||
|
$repeats = true;
|
||||||
|
if ($formData["add_show_repeats"]) {
|
||||||
|
$repeats = $forms["repeats"]->isValid($formData);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Make the absolute rebroadcast form valid since
|
||||||
|
* it does not get used if the show is repeating
|
||||||
|
*/
|
||||||
|
$forms["abs_rebroadcast"]->reset();
|
||||||
|
$absRebroadcast = true;
|
||||||
|
|
||||||
|
$rebroadcast = true;
|
||||||
|
if ($formData["add_show_rebroadcast"]) {
|
||||||
|
$formData["add_show_duration"] = $this->formatShowDuration(
|
||||||
|
$formData["add_show_duration"]);
|
||||||
|
$rebroadcast = $forms["rebroadcast"]->isValid($formData);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
* Make the rebroadcast form valid since it does
|
||||||
|
* not get used if the show is not repeating.
|
||||||
|
* Instead, we use the absolute rebroadcast form
|
||||||
|
*/
|
||||||
|
$forms["rebroadcast"]->reset();
|
||||||
|
$rebroadcast = true;
|
||||||
|
|
||||||
|
$absRebroadcast = true;
|
||||||
|
if ($formData["add_show_rebroadcast"]) {
|
||||||
|
$formData["add_show_duration"] = $this->formatShowDuration(
|
||||||
|
$formData["add_show_duration"]);
|
||||||
|
$absRebroadcast = $forms["abs_rebroadcast"]->isValid($formData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($what && $live && $record && $who && $style && $when &&
|
||||||
|
$repeats && $absRebroadcast && $rebroadcast) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* Form stuff ends
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function formatShowDuration($duration) {
|
||||||
|
$hPos = strpos($duration, 'h');
|
||||||
|
$mPos = strpos($duration, 'm');
|
||||||
|
|
||||||
|
$hValue = 0;
|
||||||
|
$mValue = 0;
|
||||||
|
|
||||||
|
if ($hPos !== false) {
|
||||||
|
$hValue = trim(substr($duration, 0, $hPos));
|
||||||
|
}
|
||||||
|
if ($mPos !== false) {
|
||||||
|
$hPos = $hPos === false ? 0 : $hPos+1;
|
||||||
|
$mValue = trim(substr($duration, $hPos, -1 ));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $hValue.":".$mValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addUpdateShow($showData, $isUpdate=false)
|
||||||
|
{
|
||||||
|
//CcSubj object
|
||||||
|
$currentUser = $this->service_user->getCurrentUser();
|
||||||
|
|
||||||
|
$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;
|
||||||
|
|
||||||
|
$showData["add_show_duration"] = $this->formatShowDuration(
|
||||||
|
$showData["add_show_duration"]);
|
||||||
|
|
||||||
|
$con = Propel::getConnection();
|
||||||
|
$con->beginTransaction();
|
||||||
|
try {
|
||||||
|
if (!$currentUser->isAdminOrPM()) {
|
||||||
|
throw new Exception("Permission denied");
|
||||||
|
}
|
||||||
|
//update ccShow
|
||||||
|
$ccShow = $this->service_show->setShow($showData, $isUpdate);
|
||||||
|
$showId = $ccShow->getDbId();
|
||||||
|
|
||||||
|
if ($isUpdate) {
|
||||||
|
$this->service_showInstances->deleteInvalidInstances($showData, $isRecorded, $repeatType);
|
||||||
|
$this->service_showInstances->updateScheduleStatus($showId);
|
||||||
|
$this->service_showInstances->deleteRebroadcastInstances($showId);
|
||||||
|
$this->service_showDays->deleteShowDays();
|
||||||
|
$this->service_show->deleteShowHosts($showId);
|
||||||
|
if ($isRebroadcast) {
|
||||||
|
//delete entry in cc_show_rebroadcast
|
||||||
|
$this->service_show->deleteShowRebroadcasts($showId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//update ccShowDays
|
||||||
|
$this->service_showDays = new Application_Service_ShowDaysService($showId);
|
||||||
|
$this->service_showDays->setShowDays($showData, $repeatType, $isRecorded);
|
||||||
|
|
||||||
|
//update ccShowRebroadcasts
|
||||||
|
$this->service_show->setShowRebroadcasts($showData, $showId, $repeatType, $isRecorded);
|
||||||
|
|
||||||
|
//update ccShowHosts
|
||||||
|
$this->service_show->setShowHosts($showData, $showId);
|
||||||
|
|
||||||
|
//create new ccShowInstances
|
||||||
|
$this->service_showInstances->delegateShowInstanceCreation($showId, $isRebroadcast, $isUpdate);
|
||||||
|
|
||||||
|
$con->commit();
|
||||||
|
Application_Model_RabbitMq::PushSchedule();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$con->rollback();
|
||||||
|
$isUpdate ? $action = "update" : $action = "creation";
|
||||||
|
Logging::info("EXCEPTION: Show ".$action." failed.");
|
||||||
|
Logging::info($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Before we send the form data in for validation, there
|
||||||
|
* are a few fields we may need to adjust first
|
||||||
|
* @param $formData
|
||||||
|
*/
|
||||||
|
public function preEditShowValidationCheck($formData) {
|
||||||
|
$validateStartDate = true;
|
||||||
|
$validateStartTime = true;
|
||||||
|
$this->service_showDays = new Application_Service_ShowDaysService(
|
||||||
|
$formData["add_show_id"]);
|
||||||
|
|
||||||
|
//CcShowDays object of the show currently being edited
|
||||||
|
$currentShowDay = $this->service_showDays->getCurrentShowDay();
|
||||||
|
|
||||||
|
if (!array_key_exists('add_show_start_date', $formData)) {
|
||||||
|
//Changing the start date was disabled, since the
|
||||||
|
//array key does not exist. We need to repopulate this entry from the db.
|
||||||
|
//The start date will be returned in UTC time, so lets convert it to local time.
|
||||||
|
$dt = Application_Common_DateHelper::ConvertToLocalDateTime(
|
||||||
|
$this->service_showDays->getStartDateAndTime());
|
||||||
|
$formData['add_show_start_date'] = $dt->format("Y-m-d");
|
||||||
|
|
||||||
|
if (!array_key_exists('add_show_start_time', $formData)) {
|
||||||
|
$formData['add_show_start_time'] = $dt->format("H:i");
|
||||||
|
$validateStartTime = false;
|
||||||
|
}
|
||||||
|
$validateStartDate = false;
|
||||||
|
}
|
||||||
|
$formData['add_show_record'] = $currentShowDay->getDbRecord();
|
||||||
|
|
||||||
|
//if the show is repeating, set the start date to the next
|
||||||
|
//repeating instance in the future
|
||||||
|
if ($currentShowDay->isRepeating()) {
|
||||||
|
$nextFutureRepeatShow = $this->service_showInstances
|
||||||
|
->getNextFutureRepeatShowTime($formData["add_show_id"]);
|
||||||
|
$originalShowStartDateTime = $nextFutureRepeatShow["starts"];
|
||||||
|
} else {
|
||||||
|
$originalShowStartDateTime = Application_Common_DateHelper::ConvertToLocalDateTime(
|
||||||
|
$this->service_showDays->getStartDateAndTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
return array($formData, $validateStartDate, $validateStartTime, $originalShowStartDateTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,276 +1,26 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
class Application_Service_ScheduleService
|
class Application_Service_ScheduleService
|
||||||
{
|
{
|
||||||
private $service_show;
|
|
||||||
private $service_showDays;
|
|
||||||
private $service_showInstances;
|
|
||||||
private $service_user;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->service_show = new Application_Service_ShowService();
|
|
||||||
$this->service_showInstances = new Application_Service_ShowInstanceService();
|
|
||||||
$this->service_user = new Application_Service_UserService();
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* Form stuff begins here
|
|
||||||
* Typically I would keep form creation and validation
|
|
||||||
* in the controller but since shows require 9 forms,
|
|
||||||
* the controller will become too fat.
|
|
||||||
* Maybe we should create a special form show service?
|
|
||||||
*/
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return array of schedule forms
|
* Enter description here ...
|
||||||
|
* @param array $instanceIds
|
||||||
*/
|
*/
|
||||||
public function createShowForms()
|
public static function updateScheduleStartTime($instanceIds, $diff)
|
||||||
{
|
{
|
||||||
$formWhat = new Application_Form_AddShowWhat();
|
if (count($instanceIds) > 0 && $diff != 0) {
|
||||||
$formWho = new Application_Form_AddShowWho();
|
$showIdList = implode(",", $instanceIds);
|
||||||
$formWhen = new Application_Form_AddShowWhen();
|
$sql = <<<SQL
|
||||||
$formRepeats = new Application_Form_AddShowRepeats();
|
UPDATE cc_schedule
|
||||||
$formStyle = new Application_Form_AddShowStyle();
|
SET starts = starts + diff1::INTERVAL,
|
||||||
$formLive = new Application_Form_AddShowLiveStream();
|
ends = ends + diff2::INTERVAL
|
||||||
$formRecord = new Application_Form_AddShowRR();
|
WHERE instance_id IN :showIds
|
||||||
$formAbsoluteRebroadcast = new Application_Form_AddShowAbsoluteRebroadcastDates();
|
SQL;
|
||||||
$formRebroadcast = new Application_Form_AddShowRebroadcastDates();
|
|
||||||
|
|
||||||
$formWhat->removeDecorator('DtDdWrapper');
|
Application_Common_Database::prepareAndExecute($sql,
|
||||||
$formWho->removeDecorator('DtDdWrapper');
|
array(':diff1' => $diff, ':diff2' => $diff,
|
||||||
$formWhen->removeDecorator('DtDdWrapper');
|
':showIds' => $showIdList),
|
||||||
$formRepeats->removeDecorator('DtDdWrapper');
|
'execute');
|
||||||
$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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Popluates the what, when, and repeat forms
|
|
||||||
* with default values
|
|
||||||
*/
|
|
||||||
public function populateNewShowForms($formWhat, $formWhen, $formRepeats)
|
|
||||||
{
|
|
||||||
$formWhat->populate(
|
|
||||||
array('add_show_id' => '-1',
|
|
||||||
'add_show_instance_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' => '01h 00m'));
|
|
||||||
|
|
||||||
$formRepeats->populate(array('add_show_end_date' => date("Y-m-d")));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function populateForm($form, $values)
|
|
||||||
{
|
|
||||||
$form->populate($values);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Validates show forms
|
|
||||||
*
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public function validateShowForms($forms, $formData, $validateStartDate = true,
|
|
||||||
$originalStartDate=null, $editShow=false, $instanceId=null)
|
|
||||||
{
|
|
||||||
$what = $forms["what"]->isValid($formData);
|
|
||||||
$live = $forms["live"]->isValid($formData);
|
|
||||||
$record = $forms["record"]->isValid($formData);
|
|
||||||
$who = $forms["who"]->isValid($formData);
|
|
||||||
$style = $forms["style"]->isValid($formData);
|
|
||||||
$when = $forms["when"]->isWhenFormValid($formData, $validateStartDate,
|
|
||||||
$originalStartDate, $editShow, $instanceId);
|
|
||||||
|
|
||||||
$repeats = true;
|
|
||||||
if ($formData["add_show_repeats"]) {
|
|
||||||
$repeats = $forms["repeats"]->isValid($formData);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Make the absolute rebroadcast form valid since
|
|
||||||
* it does not get used if the show is repeating
|
|
||||||
*/
|
|
||||||
$forms["abs_rebroadcast"]->reset();
|
|
||||||
$absRebroadcast = true;
|
|
||||||
|
|
||||||
$rebroadcast = true;
|
|
||||||
if ($formData["add_show_rebroadcast"]) {
|
|
||||||
$formData["add_show_duration"] = $this->formatShowDuration(
|
|
||||||
$formData["add_show_duration"]);
|
|
||||||
$rebroadcast = $forms["rebroadcast"]->isValid($formData);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
/*
|
|
||||||
* Make the rebroadcast form valid since it does
|
|
||||||
* not get used if the show is not repeating.
|
|
||||||
* Instead, we use the absolute rebroadcast form
|
|
||||||
*/
|
|
||||||
$forms["rebroadcast"]->reset();
|
|
||||||
$rebroadcast = true;
|
|
||||||
|
|
||||||
$absRebroadcast = true;
|
|
||||||
if ($formData["add_show_rebroadcast"]) {
|
|
||||||
$formData["add_show_duration"] = $this->formatShowDuration(
|
|
||||||
$formData["add_show_duration"]);
|
|
||||||
$absRebroadcast = $forms["abs_rebroadcast"]->isValid($formData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($what && $live && $record && $who && $style && $when &&
|
|
||||||
$repeats && $absRebroadcast && $rebroadcast) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
* Form stuff ends
|
|
||||||
*/
|
|
||||||
|
|
||||||
public function formatShowDuration($duration) {
|
|
||||||
$hPos = strpos($duration, 'h');
|
|
||||||
$mPos = strpos($duration, 'm');
|
|
||||||
|
|
||||||
$hValue = 0;
|
|
||||||
$mValue = 0;
|
|
||||||
|
|
||||||
if ($hPos !== false) {
|
|
||||||
$hValue = trim(substr($duration, 0, $hPos));
|
|
||||||
}
|
|
||||||
if ($mPos !== false) {
|
|
||||||
$hPos = $hPos === false ? 0 : $hPos+1;
|
|
||||||
$mValue = trim(substr($duration, $hPos, -1 ));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $hValue.":".$mValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Creates a new show, which entails creating entries in
|
|
||||||
* the following tables:
|
|
||||||
* cc_show
|
|
||||||
* cc_show_days
|
|
||||||
* cc_show_hosts
|
|
||||||
* cc_show_rebroadcast
|
|
||||||
* cc_show_instances
|
|
||||||
*/
|
|
||||||
public function createShow($showData)
|
|
||||||
{
|
|
||||||
//CcSubj object
|
|
||||||
$currentUser = $this->service_user->getCurrentUser();
|
|
||||||
|
|
||||||
$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;
|
|
||||||
|
|
||||||
$showData["add_show_duration"] = $this->formatShowDuration(
|
|
||||||
$showData["add_show_duration"]);
|
|
||||||
|
|
||||||
if ($currentUser->isAdminOrPM()) {
|
|
||||||
//create ccShow
|
|
||||||
$ccShow = $this->service_show->setShow($showData, true);
|
|
||||||
$showId = $ccShow->getDbId();
|
|
||||||
|
|
||||||
//create ccShowDays
|
|
||||||
$this->service_showDays = new Application_Service_ShowDaysService($showId);
|
|
||||||
$this->service_showDays->setShowDays(
|
|
||||||
$showData, $currentUser->getDbId(), $repeatType, $isRecorded);
|
|
||||||
|
|
||||||
//create ccShowRebroadcasts
|
|
||||||
$this->service_show->setShowRebroadcasts($showData, $showId, $repeatType, $isRecorded);
|
|
||||||
|
|
||||||
//create ccShowHosts
|
|
||||||
$this->service_show->setShowHosts($showData, $showId);
|
|
||||||
|
|
||||||
//create ccShowInstances
|
|
||||||
$this->service_showInstances->delegateShowInstanceCreation($showId, $isRebroadcast);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function editShow($showData)
|
|
||||||
{
|
|
||||||
//CcSubj object
|
|
||||||
$currentUser = $this->service_user->getCurrentUser();
|
|
||||||
|
|
||||||
$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;
|
|
||||||
|
|
||||||
$showData["add_show_duration"] = $this->formatShowDuration(
|
|
||||||
$showData["add_show_duration"]);
|
|
||||||
|
|
||||||
if ($currentUser->isAdminOrPM()) {
|
|
||||||
$ccShow = $this->service_show->setShow($showData, false);
|
|
||||||
|
|
||||||
$this->service_showInstances->updateShowInstances($showData, $isRecorded, $repeatType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Before we send the form data in for validation, there
|
|
||||||
* are a few fields we may need to adjust first
|
|
||||||
* @param $formData
|
|
||||||
*/
|
|
||||||
public function preEditShowValidationCheck($formData) {
|
|
||||||
$validateStartDate = true;
|
|
||||||
$validateStartTime = true;
|
|
||||||
$this->service_showDays = new Application_Service_ShowDaysService(
|
|
||||||
$formData["add_show_id"]);
|
|
||||||
|
|
||||||
//CcShowDays object of the show currently being edited
|
|
||||||
$currentShowDay = $this->service_showDays->getCurrentShowDay();
|
|
||||||
|
|
||||||
if (!array_key_exists('add_show_start_date', $formData)) {
|
|
||||||
//Changing the start date was disabled, since the
|
|
||||||
//array key does not exist. We need to repopulate this entry from the db.
|
|
||||||
//The start date will be returned in UTC time, so lets convert it to local time.
|
|
||||||
$dt = Application_Common_DateHelper::ConvertToLocalDateTime(
|
|
||||||
$this->service_showDays->getStartDateAndTime());
|
|
||||||
$formData['add_show_start_date'] = $dt->format("Y-m-d");
|
|
||||||
|
|
||||||
if (!array_key_exists('add_show_start_time', $formData)) {
|
|
||||||
$formData['add_show_start_time'] = $dt->format("H:i");
|
|
||||||
$validateStartTime = false;
|
|
||||||
}
|
|
||||||
$validateStartDate = false;
|
|
||||||
}
|
|
||||||
$formData['add_show_record'] = $currentShowDay->getDbRecord();
|
|
||||||
|
|
||||||
//if the show is repeating, set the start date to the next
|
|
||||||
//repeating instance in the future
|
|
||||||
if ($currentShowDay->isRepeating()) {
|
|
||||||
$nextFutureRepeatShow = $this->service_showInstances
|
|
||||||
->getNextFutureRepeatShowTime($formData["add_show_id"]);
|
|
||||||
$originalShowStartDateTime = $nextFutureRepeatShow["starts"];
|
|
||||||
} else {
|
|
||||||
$originalShowStartDateTime = Application_Common_DateHelper::ConvertToLocalDateTime(
|
|
||||||
$this->service_showDays->getStartDateAndTime());
|
|
||||||
}
|
|
||||||
|
|
||||||
return array($formData, $validateStartDate, $validateStartTime, $originalShowStartDateTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -9,6 +9,17 @@ class Application_Service_ShowDaysService
|
||||||
$this->showId = $id;
|
$this->showId = $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Deletes all the cc_show_days entries for a specific show
|
||||||
|
* that is currently being edited. They will get recreated with
|
||||||
|
* the new show day specs
|
||||||
|
*/
|
||||||
|
public function deleteShowDays()
|
||||||
|
{
|
||||||
|
CcShowDaysQuery::create()->filterByDbShowId($this->showId)->delete();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Determines what the show end date should be based on
|
* Determines what the show end date should be based on
|
||||||
|
@ -22,13 +33,11 @@ class Application_Service_ShowDaysService
|
||||||
if ($showData['add_show_no_end']) {
|
if ($showData['add_show_no_end']) {
|
||||||
$endDate = NULL;
|
$endDate = NULL;
|
||||||
} elseif ($showData['add_show_repeats']) {
|
} elseif ($showData['add_show_repeats']) {
|
||||||
$endDateTime = new DateTime($showData['add_show_end_date']);
|
$endDate = new DateTime($showData['add_show_end_date']);
|
||||||
$endDateTime->add(new DateInterval("P1D"));
|
$endDate->add(new DateInterval("P1D"));
|
||||||
$endDate = $endDateTime->format("Y-m-d");
|
|
||||||
} else {
|
} else {
|
||||||
$endDateTime = new DateTime($showData['add_show_start_date']);
|
$endDate = new DateTime($showData['add_show_start_date']);
|
||||||
$endDateTime->add(new DateInterval("P1D"));
|
$endDate->add(new DateInterval("P1D"));
|
||||||
$endDate = $endDateTime->format("Y-m-d");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $endDate;
|
return $endDate;
|
||||||
|
@ -42,12 +51,18 @@ class Application_Service_ShowDaysService
|
||||||
* @param $userId
|
* @param $userId
|
||||||
* @param $repeatType
|
* @param $repeatType
|
||||||
* @param $isRecorded
|
* @param $isRecorded
|
||||||
|
* @param $showDay ccShowDay object we are setting values on
|
||||||
*/
|
*/
|
||||||
public function setShowDays($showData, $userId, $repeatType, $isRecorded)
|
public function setShowDays($showData, $repeatType, $isRecorded)
|
||||||
{
|
{
|
||||||
$startDateTime = new DateTime($showData['add_show_start_date']." ".$showData['add_show_start_time']);
|
$startDateTime = new DateTime($showData['add_show_start_date']." ".$showData['add_show_start_time']);
|
||||||
|
|
||||||
$endDate = $this->calculateEndDate($showData);
|
$endDateTime = $this->calculateEndDate($showData);
|
||||||
|
if (!is_null($endDateTime)) {
|
||||||
|
$endDate = $endDateTime->format("Y-m-d");
|
||||||
|
} else {
|
||||||
|
$endDate = $endDateTime;
|
||||||
|
}
|
||||||
|
|
||||||
/* What we are doing here is checking if the show repeats or if
|
/* What we are doing here is checking if the show repeats or if
|
||||||
* any repeating days have been checked. If not, then by default
|
* any repeating days have been checked. If not, then by default
|
||||||
|
@ -67,7 +82,7 @@ class Application_Service_ShowDaysService
|
||||||
$showDay->setDbFirstShow($startDateTime->format("Y-m-d"));
|
$showDay->setDbFirstShow($startDateTime->format("Y-m-d"));
|
||||||
$showDay->setDbLastShow($endDate);
|
$showDay->setDbLastShow($endDate);
|
||||||
$showDay->setDbStartTime($startDateTime->format("H:i:s"));
|
$showDay->setDbStartTime($startDateTime->format("H:i:s"));
|
||||||
$showDay->setDbTimezone(Application_Model_Preference::GetUserTimezone($userId));
|
$showDay->setDbTimezone(Application_Model_Preference::GetTimezone());
|
||||||
$showDay->setDbDuration($showData['add_show_duration']);
|
$showDay->setDbDuration($showData['add_show_duration']);
|
||||||
$showDay->setDbRepeatType($repeatType);
|
$showDay->setDbRepeatType($repeatType);
|
||||||
$showDay->setDbShowId($this->showId);
|
$showDay->setDbShowId($this->showId);
|
||||||
|
@ -90,7 +105,7 @@ class Application_Service_ShowDaysService
|
||||||
$showDay->setDbFirstShow($startDateTimeClone->format("Y-m-d"));
|
$showDay->setDbFirstShow($startDateTimeClone->format("Y-m-d"));
|
||||||
$showDay->setDbLastShow($endDate);
|
$showDay->setDbLastShow($endDate);
|
||||||
$showDay->setDbStartTime($startDateTimeClone->format("H:i"));
|
$showDay->setDbStartTime($startDateTimeClone->format("H:i"));
|
||||||
$showDay->setDbTimezone(Application_Model_Preference::GetUserTimezone($userId));
|
$showDay->setDbTimezone(Application_Model_Preference::GetTimezone());
|
||||||
$showDay->setDbDuration($showData['add_show_duration']);
|
$showDay->setDbDuration($showData['add_show_duration']);
|
||||||
$showDay->setDbDay($day);
|
$showDay->setDbDay($day);
|
||||||
$showDay->setDbRepeatType($repeatType);
|
$showDay->setDbRepeatType($repeatType);
|
||||||
|
@ -110,10 +125,6 @@ class Application_Service_ShowDaysService
|
||||||
*/
|
*/
|
||||||
public function getShowDays()
|
public function getShowDays()
|
||||||
{
|
{
|
||||||
/*$sql = "SELECT * FROM cc_show_days WHERE show_id = :show_id";
|
|
||||||
|
|
||||||
return Application_Common_Database::prepareAndExecute(
|
|
||||||
$sql, array(":show_id" => $this->showId), 'all');*/
|
|
||||||
return CcShowDaysQuery::create()->filterByDbShowId(
|
return CcShowDaysQuery::create()->filterByDbShowId(
|
||||||
$this->showId)->find();
|
$this->showId)->find();
|
||||||
}
|
}
|
||||||
|
@ -140,4 +151,31 @@ class Application_Service_ShowDaysService
|
||||||
return CcShowDaysQuery::create()->filterByDbShowId($this->showId)
|
return CcShowDaysQuery::create()->filterByDbShowId($this->showId)
|
||||||
->findOne();
|
->findOne();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getRepeatingEndDate()
|
||||||
|
{
|
||||||
|
$sql = <<<SQL
|
||||||
|
SELECT last_show
|
||||||
|
FROM cc_show_days
|
||||||
|
WHERE show_id = :showId
|
||||||
|
ORDER BY last_show DESC
|
||||||
|
SQL;
|
||||||
|
|
||||||
|
$query = Application_Common_Database::prepareAndExecute( $sql,
|
||||||
|
array( 'showId' => $this->showId ), 'column' );
|
||||||
|
|
||||||
|
return ($query !== false) ? $query : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getNextStartDateTime($showDay)
|
||||||
|
{
|
||||||
|
$nextPopDate = $showDay->getDbNextPopDate();
|
||||||
|
$startTime = $showDay->getDbStartTime();
|
||||||
|
|
||||||
|
if (isset($nextPopDate)) {
|
||||||
|
return $nextPopDate." ".$startTime;
|
||||||
|
} else {
|
||||||
|
return $showDay->getDbFirstShow()." ".$startTime;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -22,7 +22,7 @@ class Application_Service_ShowInstanceService
|
||||||
* Receives a cc_show id and determines whether to create a
|
* Receives a cc_show id and determines whether to create a
|
||||||
* single show instance or repeating show instances
|
* single show instance or repeating show instances
|
||||||
*/
|
*/
|
||||||
public function delegateShowInstanceCreation($showId, $isRebroadcast)
|
public function delegateShowInstanceCreation($showId, $isRebroadcast, $isUpdate)
|
||||||
{
|
{
|
||||||
$populateUntil = $this->service_show->getPopulateShowUntilDateTIme();
|
$populateUntil = $this->service_show->getPopulateShowUntilDateTIme();
|
||||||
|
|
||||||
|
@ -32,10 +32,10 @@ class Application_Service_ShowInstanceService
|
||||||
foreach ($showDays as $day) {
|
foreach ($showDays as $day) {
|
||||||
switch ($day->getDbRepeatType()) {
|
switch ($day->getDbRepeatType()) {
|
||||||
case NO_REPEAT:
|
case NO_REPEAT:
|
||||||
$this->createNonRepeatingShowInstance($day, $populateUntil, $isRebroadcast);
|
$this->createNonRepeatingShowInstance($day, $populateUntil, $isRebroadcast, $isUpdate);
|
||||||
break;
|
break;
|
||||||
case REPEAT_WEEKLY:
|
case REPEAT_WEEKLY:
|
||||||
$this->createWeeklyRepeatingShowInstances($day, $populateUntil, "P7D", $isRebroadcast);
|
$this->createWeeklyRepeatingShowInstances($day, $populateUntil, "P7D", $isRebroadcast, $isUpdate);
|
||||||
break;
|
break;
|
||||||
case REPEAT_BI_WEEKLY:
|
case REPEAT_BI_WEEKLY:
|
||||||
$this->createWeeklyRepeatingShowInstances($day, $populateUntil, "P14D", $isRebroadcast);
|
$this->createWeeklyRepeatingShowInstances($day, $populateUntil, "P14D", $isRebroadcast);
|
||||||
|
@ -57,7 +57,7 @@ class Application_Service_ShowInstanceService
|
||||||
* @param $showDay
|
* @param $showDay
|
||||||
* @param $populateUntil
|
* @param $populateUntil
|
||||||
*/
|
*/
|
||||||
private function createNonRepeatingShowInstance($showDay, $populateUntil, $isRebroadcast)
|
private function createNonRepeatingShowInstance($showDay, $populateUntil, $isRebroadcast, $isUpdate)
|
||||||
{
|
{
|
||||||
$start = $showDay->getDbFirstShow()." ".$showDay->getDbStartTime();
|
$start = $showDay->getDbFirstShow()." ".$showDay->getDbStartTime();
|
||||||
|
|
||||||
|
@ -66,6 +66,15 @@ class Application_Service_ShowInstanceService
|
||||||
|
|
||||||
if ($utcStartDateTime->getTimestamp() < $populateUntil->getTimestamp()) {
|
if ($utcStartDateTime->getTimestamp() < $populateUntil->getTimestamp()) {
|
||||||
$ccShowInstance = new CcShowInstances();
|
$ccShowInstance = new CcShowInstances();
|
||||||
|
if ($isUpdate) {
|
||||||
|
$ccShowInstance = $this->getInstance($utcStartDateTime, $showDay->getDbShowId());
|
||||||
|
//update schedule start times
|
||||||
|
//ccShowDays object of the show being edited
|
||||||
|
$currentShowDay = $this->service_showDays->getCurrentShowDay();
|
||||||
|
$diff = $this->calculateShowStartDiff($utcStartDateTime,
|
||||||
|
$currentShowDay->getUTCStartDateAndTime());
|
||||||
|
Application_Service_ScheduleService::updateScheduleStartTime(array($ccShowInstance->getDbId()), $diff);
|
||||||
|
}
|
||||||
$ccShowInstance->setDbShowId($showDay->getDbShowId());
|
$ccShowInstance->setDbShowId($showDay->getDbShowId());
|
||||||
$ccShowInstance->setDbStarts($utcStartDateTime);
|
$ccShowInstance->setDbStarts($utcStartDateTime);
|
||||||
$ccShowInstance->setDbEnds($utcEndDateTime);
|
$ccShowInstance->setDbEnds($utcEndDateTime);
|
||||||
|
@ -87,35 +96,26 @@ class Application_Service_ShowInstanceService
|
||||||
* @param unknown_type $isRebroadcast
|
* @param unknown_type $isRebroadcast
|
||||||
*/
|
*/
|
||||||
private function createWeeklyRepeatingShowInstances($showDay, $populateUntil,
|
private function createWeeklyRepeatingShowInstances($showDay, $populateUntil,
|
||||||
$repeatInterval, $isRebroadcast)
|
$repeatInterval, $isRebroadcast, $isUpdate)
|
||||||
{
|
{
|
||||||
$show_id = $showDay->getDbShowId();
|
$show_id = $showDay->getDbShowId();
|
||||||
$next_pop_date = $showDay->getDbNextPopDate();
|
|
||||||
$first_show = $showDay->getDbFirstShow(); //non-UTC
|
$first_show = $showDay->getDbFirstShow(); //non-UTC
|
||||||
$last_show = $showDay->getDbLastShow(); //non-UTC
|
$last_show = $showDay->getDbLastShow(); //non-UTC
|
||||||
$start_time = $showDay->getDbStartTime(); //non-UTC
|
|
||||||
$duration = $showDay->getDbDuration();
|
$duration = $showDay->getDbDuration();
|
||||||
$day = $showDay->getDbDay();
|
$day = $showDay->getDbDay();
|
||||||
$record = $showDay->getDbRecord();
|
$record = $showDay->getDbRecord();
|
||||||
$timezone = $showDay->getDbTimezone();
|
$timezone = $showDay->getDbTimezone();
|
||||||
|
|
||||||
$currentUtcTimestamp = gmdate("Y-m-d H:i:s");
|
$start = $this->service_showDays->getNextStartDateTime($showDay);
|
||||||
|
|
||||||
if (isset($next_pop_date)) {
|
$datePeriod = $this->getDatePeriod($start, $timezone, $last_show,
|
||||||
$start = $next_pop_date." ".$start_time;
|
|
||||||
} else {
|
|
||||||
$start = $first_show." ".$start_time;
|
|
||||||
}
|
|
||||||
|
|
||||||
$period = $this->getDatePeriod($start, $timezone, $last_show,
|
|
||||||
$repeatInterval, $populateUntil);
|
$repeatInterval, $populateUntil);
|
||||||
|
|
||||||
$utcStartDateTime = Application_Common_DateHelper::ConvertToUtcDateTime($start, $timezone);
|
|
||||||
$utcLastShowDateTime = $last_show ?
|
$utcLastShowDateTime = $last_show ?
|
||||||
Application_Common_DateHelper::ConvertToUtcDateTime($last_show, $timezone) : null;
|
Application_Common_DateHelper::ConvertToUtcDateTime($last_show, $timezone) : null;
|
||||||
|
|
||||||
$utcEndDateTime = null;
|
$utcEndDateTime = null;
|
||||||
foreach ($period as $date) {
|
foreach ($datePeriod 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);
|
||||||
/*
|
/*
|
||||||
|
@ -127,14 +127,23 @@ class Application_Service_ShowInstanceService
|
||||||
$utcStartDateTime->getTimestamp() < $utcLastShowDateTime->getTimestamp()) ) {
|
$utcStartDateTime->getTimestamp() < $utcLastShowDateTime->getTimestamp()) ) {
|
||||||
|
|
||||||
$ccShowInstance = new CcShowInstances();
|
$ccShowInstance = new CcShowInstances();
|
||||||
$ccShowInstance->setDbShowId($show_id);
|
if ($isUpdate) {
|
||||||
$ccShowInstance->setDbStarts($utcStartDateTime);
|
$ccShowInstance = $this->getInstance($utcStartDateTime, $show_id);
|
||||||
$ccShowInstance->setDbEnds($utcEndDateTime);
|
}
|
||||||
$ccShowInstance->setDbRecord($record);
|
|
||||||
$ccShowInstance->save();
|
/* When editing the start/end time of a repeating show, we don't want to
|
||||||
|
* change shows that started in the past. So check the start time.
|
||||||
|
*/
|
||||||
|
if (!$isUpdate || $ccShowInstance->getDbStarts() > gmdate("Y-m-d H:i:s")) {
|
||||||
|
$ccShowInstance->setDbShowId($show_id);
|
||||||
|
$ccShowInstance->setDbStarts($utcStartDateTime);
|
||||||
|
$ccShowInstance->setDbEnds($utcEndDateTime);
|
||||||
|
$ccShowInstance->setDbRecord($record);
|
||||||
|
$ccShowInstance->save();
|
||||||
|
}
|
||||||
|
|
||||||
if ($isRebroadcast) {
|
if ($isRebroadcast) {
|
||||||
$this->createRebroadcastShowInstances($showDay, $date->format("Y-m-d"), $ccShowInstance->getDbId());
|
$this->createRebroadcastInstances($showDay, $date->format("Y-m-d"), $ccShowInstance->getDbId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -147,10 +156,10 @@ class Application_Service_ShowInstanceService
|
||||||
* Enter description here ...
|
* Enter description here ...
|
||||||
* @param $showDay
|
* @param $showDay
|
||||||
*/
|
*/
|
||||||
private function createRebroadcastShowInstances($showDay, $showStartDate, $instanceId)
|
private function createRebroadcastInstances($showDay, $showStartDate, $instanceId)
|
||||||
{
|
{
|
||||||
$currentUtcTimestamp = gmdate("Y-m-d H:i:s");
|
$currentUtcTimestamp = gmdate("Y-m-d H:i:s");
|
||||||
$showId = $showDay["show_id"];
|
$showId = $showDay->getDbShowId();
|
||||||
|
|
||||||
$sql = "SELECT * FROM cc_show_rebroadcast WHERE show_id=:show_id";
|
$sql = "SELECT * FROM cc_show_rebroadcast WHERE show_id=:show_id";
|
||||||
$rebroadcasts = Application_Common_Database::prepareAndExecute($sql,
|
$rebroadcasts = Application_Common_Database::prepareAndExecute($sql,
|
||||||
|
@ -162,7 +171,7 @@ class Application_Service_ShowInstanceService
|
||||||
$offset = array("days"=>$days[0], "hours"=>$time[0], "mins"=>$time[1]);
|
$offset = array("days"=>$days[0], "hours"=>$time[0], "mins"=>$time[1]);
|
||||||
|
|
||||||
list($utcStartDateTime, $utcEndDateTime) = $this->service_show->createUTCStartEndDateTime(
|
list($utcStartDateTime, $utcEndDateTime) = $this->service_show->createUTCStartEndDateTime(
|
||||||
$showStartDate, $showDay["duration"], $showDay["timezone"], $offset);
|
$showStartDate, $showDay->getDbDuration(), $showDay->getDbTimezone(), $offset);
|
||||||
|
|
||||||
if ($utcStartDateTime->format("Y-m-d H:i:s") > $currentUtcTimestamp) {
|
if ($utcStartDateTime->format("Y-m-d H:i:s") > $currentUtcTimestamp) {
|
||||||
$ccShowInstance = new CcShowInstances();
|
$ccShowInstance = new CcShowInstances();
|
||||||
|
@ -177,9 +186,30 @@ class Application_Service_ShowInstanceService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function deleteRebroadcastShowInstances()
|
public function updateScheduleStatus($showId)
|
||||||
{
|
{
|
||||||
|
$con = Propel::getConnection(CcSchedulePeer::DATABASE_NAME);
|
||||||
|
$instances = CcShowInstancesQuery::create()
|
||||||
|
->filterByDbEnds(gmdate("Y-m-d H:i:s"), Criteria::GREATER_THAN)
|
||||||
|
->filterByDbShowId($showId)
|
||||||
|
->find();
|
||||||
|
|
||||||
|
foreach ($instances as $instance) {
|
||||||
|
$instance->updateScheduleStatus($con);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteRebroadcastInstances($showId)
|
||||||
|
{
|
||||||
|
$sql = <<<SQL
|
||||||
|
DELETE FROM cc_show_instances
|
||||||
|
WHERE starts > :timestamp::TIMESTAMP
|
||||||
|
AND show_id = :showId
|
||||||
|
AND rebroadcast = 1;
|
||||||
|
SQL;
|
||||||
|
Application_Common_Database::prepareAndExecute( $sql, array(
|
||||||
|
':showId' => $showId,
|
||||||
|
':timestamp' => gmdate("Y-m-d H:i:s")), 'execute');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -231,7 +261,80 @@ SQL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function is messy. But sometimes there is no easy way to do it.
|
*
|
||||||
|
* Returns all the show instances of the show currently
|
||||||
|
* being edited.
|
||||||
|
* @param $showId
|
||||||
|
*/
|
||||||
|
public function getCurrentInstances($showId)
|
||||||
|
{
|
||||||
|
return CcShowInstancesQuery::create()
|
||||||
|
->filterByDbShowId($showId)
|
||||||
|
->filterByDbModifiedInstance(false)
|
||||||
|
->orderBy("starts");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Attempts to retrieve the cc_show_instance belonging to a cc_show
|
||||||
|
* that starts at $starts. We have to pass in the start
|
||||||
|
* time in case the show is repeating
|
||||||
|
*
|
||||||
|
* Returns the instance if one was found (one that is not a recording
|
||||||
|
* and modified instance is false (has not been deleted))
|
||||||
|
*/
|
||||||
|
public function getInstance($starts, $showId)
|
||||||
|
{
|
||||||
|
$ccShowInstance = CcShowInstancesQuery::create()
|
||||||
|
->filterByDbStarts($starts->format("Y-m-d H:i:s"), Criteria::EQUAL)
|
||||||
|
->filterByDbShowId($showId, Criteria::EQUAL)
|
||||||
|
->filterByDbModifiedInstance(false, Criteria::EQUAL)
|
||||||
|
->filterByDbRebroadcast(0, Criteria::EQUAL)
|
||||||
|
->limit(1)
|
||||||
|
->find();
|
||||||
|
|
||||||
|
if ($ccShowInstance->isEmpty()) {
|
||||||
|
throw new Exception("Show instance not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ccShowInstance[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAllFutureInstanceIds($showId)
|
||||||
|
{
|
||||||
|
$sql = <<<SQL
|
||||||
|
SELECT id
|
||||||
|
FROM cc_show_instances
|
||||||
|
WHERE show_id = :showId
|
||||||
|
AND starts > :timestamp::TIMESTAMP
|
||||||
|
AND modified_instance != TRUE
|
||||||
|
SQL;
|
||||||
|
$rows = Application_Common_Database::prepareAndExecute($sql,
|
||||||
|
array( ':showId' => $showId,
|
||||||
|
':timestamp' => gmdate("Y-m-d H:i:s")), "all");
|
||||||
|
|
||||||
|
$ids = array();
|
||||||
|
foreach ($ids as $id) {
|
||||||
|
$ids[] = $id['id'];
|
||||||
|
}
|
||||||
|
return $ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Returns the difference in seconds between a show's new and
|
||||||
|
* old start time
|
||||||
|
*
|
||||||
|
* @param $newStartDateTime DateTime object
|
||||||
|
* @param $oldStartDateTime DateTime object
|
||||||
|
*/
|
||||||
|
public function calculateShowStartDiff($newStartDateTime, $oldStartDateTime)
|
||||||
|
{
|
||||||
|
return $newStartDateTime->getTimestamp() - $oldStartDateTime->getTimestamp();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO: This function is messy. Needs refactoring
|
||||||
*
|
*
|
||||||
* When editing a show we may need to perform some actions to reflect the new specs:
|
* When editing a show we may need to perform some actions to reflect the new specs:
|
||||||
* - Delete some show instances
|
* - Delete some show instances
|
||||||
|
@ -242,7 +345,7 @@ SQL;
|
||||||
* @param $isRecorded value computed from the edit show form
|
* @param $isRecorded value computed from the edit show form
|
||||||
* @param $repeatType value computed from the edit show form
|
* @param $repeatType value computed from the edit show form
|
||||||
*/
|
*/
|
||||||
public function updateShowInstances($showData, $isRecorded, $repeatType)
|
public function deleteInvalidInstances($showData, $isRecorded, $repeatType)
|
||||||
{
|
{
|
||||||
$showId = $showData["add_show_id"];
|
$showId = $showData["add_show_id"];
|
||||||
|
|
||||||
|
@ -250,7 +353,13 @@ SQL;
|
||||||
//ccShowDays object of the show being edited
|
//ccShowDays object of the show being edited
|
||||||
$currentShowDay = $this->service_showDays->getCurrentShowDay();
|
$currentShowDay = $this->service_showDays->getCurrentShowDay();
|
||||||
|
|
||||||
$endDate = $this->service_showDays->calculateEndDate($showData);
|
//new end date in users' local time
|
||||||
|
$endDateTime = $this->service_showDays->calculateEndDate($showData);
|
||||||
|
if (!is_null($endDateTime)) {
|
||||||
|
$endDate = $endDateTime->format("Y-m-d");
|
||||||
|
} else {
|
||||||
|
$endDate = $endDateTime;
|
||||||
|
}
|
||||||
|
|
||||||
//repeat option was toggled
|
//repeat option was toggled
|
||||||
if ($showData['add_show_repeats'] != $currentShowDay->isRepeating()) {
|
if ($showData['add_show_repeats'] != $currentShowDay->isRepeating()) {
|
||||||
|
@ -258,9 +367,9 @@ SQL;
|
||||||
}
|
}
|
||||||
|
|
||||||
//duration has changed
|
//duration has changed
|
||||||
if ($showData['add_show_duration'] != $currentShowDay->getDbDuration()) {
|
/*if ($showData['add_show_duration'] != $currentShowDay->getDbDuration()) {
|
||||||
$this->updateDuration($showData);
|
$this->updateInstanceDuration($showData);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
if ($showData['add_show_repeats']) {
|
if ($showData['add_show_repeats']) {
|
||||||
|
|
||||||
|
@ -315,7 +424,7 @@ SQL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($showData['add_show_start_date'] != $localShowStart->format("Y-m-d")
|
if ($showData['add_show_start_date'] != $localShowStart->format("Y-m-d")
|
||||||
|| $showData['add_show_start_time'] != $localShowStart->format("H:i:s")){
|
|| $showData['add_show_start_time'] != $localShowStart->format("H:i")) {
|
||||||
|
|
||||||
//start date has been pushed forward so we need to delete
|
//start date has been pushed forward so we need to delete
|
||||||
//any instances of this show scheduled before the new start date
|
//any instances of this show scheduled before the new start date
|
||||||
|
@ -323,70 +432,65 @@ SQL;
|
||||||
$this->deleteInstancesBeforeDate($showData['add_show_start_date'], $showId);
|
$this->deleteInstancesBeforeDate($showData['add_show_start_date'], $showId);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->updateStartDateAndTime($showData, $currentShowDay);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
//Check if end date for the repeat option has changed. If so, need to take care
|
|
||||||
//of deleting possible invalid Show Instances.
|
|
||||||
if ((strlen($this->getRepeatingEndDate()) == 0) == $showData['add_show_no_end']) {
|
|
||||||
//show "Never Ends" option was toggled.
|
|
||||||
if ($showData['add_show_no_end']) {
|
|
||||||
} else {
|
|
||||||
$this->removeAllInstancesFromDate($p_endDate);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($this->getRepeatingEndDate() != $showData['add_show_end_date']) {
|
|
||||||
//end date was changed.
|
|
||||||
|
|
||||||
$newDate = strtotime($showData['add_show_end_date']);
|
$currentShowEndDate = $this->service_showDays->getRepeatingEndDate();
|
||||||
$oldDate = strtotime($this->getRepeatingEndDate());
|
//check if "no end" option has changed
|
||||||
if ($newDate < $oldDate) {
|
if ($currentShowEndDate != $showData['add_show_no_end']) {
|
||||||
$this->removeAllInstancesFromDate($p_endDate);
|
//show "No End" option was toggled
|
||||||
|
if (!$showData['add_show_no_end']) {
|
||||||
|
//"No End" option was unchecked so we need to delete the
|
||||||
|
//repeat instances that are scheduled after the new end date
|
||||||
|
$this->deleteInstancesFromDate($endDate, $showId);
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
}
|
|
||||||
|
if ($currentShowEndDate != $showData['add_show_end_date']) {
|
||||||
|
//end date was changed
|
||||||
|
$newEndDate = strtotime($showData['add_show_end_date']);
|
||||||
|
$oldEndDate = strtotime($currentShowEndDate);
|
||||||
|
if ($newEndDate < $oldEndDate) {
|
||||||
|
//end date was pushed back so we have to delete any
|
||||||
|
//instances of this show scheduled after the new end date
|
||||||
|
$this->deleteInstancesFromDate($endDate, $showId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}//if repeats
|
||||||
|
|
||||||
|
/*$newStartDateTime = new DateTime($showData["add_show_start_date"]." ".
|
||||||
|
$showData["add_show_start_time"],
|
||||||
|
new DateTimeZone(Application_Model_Preference::GetTimezone()));
|
||||||
|
|
||||||
|
$diff = $this->calculateShowStartDiff($newStartDateTime,
|
||||||
|
$currentShowDay->getLocalStartDateAndTime());
|
||||||
|
|
||||||
|
$this->updateInstanceStartEndTime($showId, $diff);
|
||||||
|
$instanceIds = $this->getAllFutureInstanceIds($showId);
|
||||||
|
Application_Service_ScheduleService::updateScheduleStartTime($instanceIds, $diff);*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Updates the start date and time for cc_show_instances
|
* Updates the start and end time for cc_show_instances
|
||||||
* and entries in cc_schedule
|
|
||||||
*
|
*
|
||||||
* @param $showData edit show form data
|
* @param $showData edit show form data
|
||||||
*/
|
*/
|
||||||
public function updateStartDateAndTime($showData, $currentShowDay)
|
public function updateInstanceStartEndTime($showId, $diff)
|
||||||
{
|
{
|
||||||
$date = new Application_Common_DateHelper();
|
|
||||||
//current time in UTC
|
|
||||||
$timestamp = $date->getTimestamp();
|
|
||||||
|
|
||||||
$dtOld = $currentShowDay->getUTCStartDateAndTime();
|
|
||||||
$dtNew = new DateTime($showData['add_show_start_date']." ".$showData['add_show_start_time'],
|
|
||||||
new DateTimeZone(date_default_timezone_get()));
|
|
||||||
$diff = $dtOld->getTimestamp() - $dtNew->getTimestamp();
|
|
||||||
$sql = <<<SQL
|
$sql = <<<SQL
|
||||||
UPDATE cc_show_instances
|
UPDATE cc_show_instances
|
||||||
SET starts = starts + :diff1::INTERVAL,
|
SET starts = starts + :diff1::INTERVAL,
|
||||||
ends = ends + :diff2::INTERVAL
|
ends = ends + :diff2::INTERVAL
|
||||||
WHERE show_id = :showId
|
WHERE show_id = :showId
|
||||||
AND starts > :timestamp
|
AND starts > :timestamp::TIMESTAMP
|
||||||
SQL;
|
SQL;
|
||||||
|
|
||||||
Application_Common_Database::prepareAndExecute($sql,
|
Application_Common_Database::prepareAndExecute($sql,
|
||||||
array(':diff1' => $diff, ':diff2' => $diff,
|
array(':diff1' => $diff, ':diff2' => $diff,
|
||||||
':showId' => $showData["add_show_id"], ':timestamp' => $timestamp),
|
':showId' => $showId, ':timestamp' => gmdate("Y-m-d H:i:s")),
|
||||||
'execute');
|
'execute');
|
||||||
|
|
||||||
/*$showInstanceIds = $this->getAllFutureInstanceIds();
|
|
||||||
if (count($showInstanceIds) > 0 && $diff != 0) {
|
|
||||||
$showIdsImploded = implode(",", $showInstanceIds);
|
|
||||||
$sql = "UPDATE cc_schedule "
|
|
||||||
."SET starts = starts + INTERVAL '$diff sec', "
|
|
||||||
."ends = ends + INTERVAL '$diff sec' "
|
|
||||||
."WHERE instance_id IN ($showIdsImploded)";
|
|
||||||
$con->exec($sql);
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deleteAllRepeatInstances($currentShowDay, $showId)
|
public function deleteAllRepeatInstances($currentShowDay, $showId)
|
||||||
|
@ -451,11 +555,9 @@ WHERE EXTRACT(DOW FROM starts) IN ($uncheckedDays)
|
||||||
AND show_id = :showId
|
AND show_id = :showId
|
||||||
SQL;
|
SQL;
|
||||||
|
|
||||||
Application_Common_Database::prepareAndExecute( $sql,
|
Application_Common_Database::prepareAndExecute( $sql, array(
|
||||||
array(
|
":timestamp" => gmdate("Y-m-d H:i:s"), ":showId" => $showId),
|
||||||
":timestamp" => gmdate("Y-m-d H:i:s"),
|
"execute");
|
||||||
":showId" => $showId,
|
|
||||||
), "execute");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deleteInstancesBeforeDate($newStartDate, $showId)
|
public function deleteInstancesBeforeDate($newStartDate, $showId)
|
||||||
|
@ -473,21 +575,31 @@ SQL;
|
||||||
":showId" => $showId), "execute");
|
":showId" => $showId), "execute");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateDuration($showData)
|
public function deleteInstancesFromDate($endDate, $showId)
|
||||||
{
|
{
|
||||||
$date = new Application_Common_DateHelper;
|
$sql = <<<SQL
|
||||||
$timestamp = $date->getUtcTimestamp();
|
DELETE FROM cc_show_instances
|
||||||
|
WHERE date(starts) >= :endDate::DATE
|
||||||
|
AND starts > :timestamp::TIMESTAMP
|
||||||
|
AND show_id = :showId
|
||||||
|
SQL;
|
||||||
|
Application_Common_Database::prepareAndExecute($sql, array(
|
||||||
|
':endDate' => $endDate, ':timestamp' => gmdate("Y-m-d H:i:s"),
|
||||||
|
':showId' => $showId), 'execute');
|
||||||
|
}
|
||||||
|
|
||||||
|
/* public function updateInstanceDuration($showData)
|
||||||
|
{
|
||||||
$sql = <<<SQL
|
$sql = <<<SQL
|
||||||
UPDATE cc_show_instances
|
UPDATE cc_show_instances
|
||||||
SET ends = starts + :add_show_duration::INTERVAL
|
SET ends = starts + :add_show_duration::INTERVAL
|
||||||
WHERE show_id = :show_id
|
WHERE show_id = :show_id
|
||||||
AND ends > :timestamp::TIMESTAMP
|
AND ends > :timestamp::TIMESTAMP
|
||||||
SQL;
|
SQL;
|
||||||
|
|
||||||
Application_Common_Database::prepareAndExecute( $sql, array(
|
Application_Common_Database::prepareAndExecute( $sql, array(
|
||||||
':add_show_duration' => $showData['add_show_duration'],
|
':add_show_duration' => $showData['add_show_duration'],
|
||||||
':show_id' => $showData['add_show_id'],
|
':show_id' => $showData['add_show_id'],
|
||||||
':timestamp' => $timestamp), "execute");
|
':timestamp' => gmdate("Y-m-d H:i:s")), "execute");
|
||||||
}
|
}*/
|
||||||
}
|
}
|
|
@ -10,9 +10,9 @@ class Application_Service_ShowService
|
||||||
* @param $ccShow
|
* @param $ccShow
|
||||||
* @param $showData
|
* @param $showData
|
||||||
*/
|
*/
|
||||||
public function setShow($showData, $isNewShow)
|
public function setShow($showData, $isUpdate)
|
||||||
{
|
{
|
||||||
if ($isNewShow) {
|
if (!$isUpdate) {
|
||||||
$ccShow = new CcShow();
|
$ccShow = new CcShow();
|
||||||
} else {
|
} else {
|
||||||
$ccShow = CcShowQuery::create()->findPk($showData["add_show_id"]);
|
$ccShow = CcShowQuery::create()->findPk($showData["add_show_id"]);
|
||||||
|
@ -33,6 +33,17 @@ class Application_Service_ShowService
|
||||||
return $ccShow;
|
return $ccShow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Deletes all the cc_show_rebroadcast entries for a specific show
|
||||||
|
* that is currently being edited. They will get recreated with
|
||||||
|
* the new show specs
|
||||||
|
*/
|
||||||
|
public function deleteShowRebroadcasts($showId)
|
||||||
|
{
|
||||||
|
CcShowRebroadcastQuery::create()->filterByDbShowId($showId)>delete();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Sets the fields for a cc_show_rebroadcast table row
|
* Sets the fields for a cc_show_rebroadcast table row
|
||||||
|
@ -70,6 +81,17 @@ class Application_Service_ShowService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
public function deleteShowHosts($showId)
|
||||||
|
{
|
||||||
|
CcShowHostsQuery::create()->filterByDbShow($showId)->delete();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Sets the fields for a cc_show_hosts table row
|
* Sets the fields for a cc_show_hosts table row
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue