Merge branch '2.5.x' into 2.5.x-saas
This commit is contained in:
commit
2a783f3825
32 changed files with 1200 additions and 378 deletions
|
@ -65,7 +65,8 @@ class ApiController extends Zend_Controller_Action
|
|||
public function versionAction()
|
||||
{
|
||||
$this->_helper->json->sendJson( array(
|
||||
"version" => Application_Model_Preference::GetAirtimeVersion()));
|
||||
"airtime_version" => Application_Model_Preference::GetAirtimeVersion(),
|
||||
"api_version" => AIRTIME_API_VERSION));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,6 +9,49 @@ class ListenerstatController extends Zend_Controller_Action
|
|||
->addActionContext('get-data', 'json')
|
||||
->initContext();
|
||||
}
|
||||
|
||||
private function getStartEnd()
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
|
||||
$userTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone());
|
||||
$utcTimezone = new DateTimeZone("UTC");
|
||||
$utcNow = new DateTime("now", $utcTimezone);
|
||||
|
||||
$start = $request->getParam("start");
|
||||
$end = $request->getParam("end");
|
||||
|
||||
if (empty($start) || empty($end)) {
|
||||
$startsDT = clone $utcNow;
|
||||
$startsDT->sub(new DateInterval("P1D"));
|
||||
$endsDT = clone $utcNow;
|
||||
}
|
||||
else {
|
||||
|
||||
try {
|
||||
$startsDT = new DateTime($start, $userTimezone);
|
||||
$startsDT->setTimezone($utcTimezone);
|
||||
|
||||
$endsDT = new DateTime($end, $userTimezone);
|
||||
$endsDT->setTimezone($utcTimezone);
|
||||
|
||||
if ($startsDT > $endsDT) {
|
||||
throw new Exception("start greater than end");
|
||||
}
|
||||
}
|
||||
catch (Exception $e) {
|
||||
Logging::info($e);
|
||||
Logging::info($e->getMessage());
|
||||
|
||||
$startsDT = clone $utcNow;
|
||||
$startsDT->sub(new DateInterval("P1D"));
|
||||
$endsDT = clone $utcNow;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return array($startsDT, $endsDT);
|
||||
}
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
|
@ -26,25 +69,17 @@ class ListenerstatController extends Zend_Controller_Action
|
|||
|
||||
$this->view->headLink()->appendStylesheet($baseUrl.'css/jquery.ui.timepicker.css?'.$CC_CONFIG['airtime_version']);
|
||||
|
||||
//default time is the last 24 hours.
|
||||
$now = time();
|
||||
$from = $request->getParam("from", $now - (24*60*60));
|
||||
$to = $request->getParam("to", $now);
|
||||
|
||||
$utcTimezone = new DateTimeZone("UTC");
|
||||
$displayTimeZone = new DateTimeZone(Application_Model_Preference::GetTimezone());
|
||||
|
||||
$start = DateTime::createFromFormat("U", $from, $utcTimezone);
|
||||
$start->setTimezone($displayTimeZone);
|
||||
$end = DateTime::createFromFormat("U", $to, $utcTimezone);
|
||||
$end->setTimezone($displayTimeZone);
|
||||
list($startsDT, $endsDT) = $this->getStartEnd();
|
||||
$userTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone());
|
||||
$startsDT->setTimezone($userTimezone);
|
||||
$endsDT->setTimezone($userTimezone);
|
||||
|
||||
$form = new Application_Form_DateRange();
|
||||
$form->populate(array(
|
||||
'his_date_start' => $start->format("Y-m-d"),
|
||||
'his_time_start' => $start->format("H:i"),
|
||||
'his_date_end' => $end->format("Y-m-d"),
|
||||
'his_time_end' => $end->format("H:i")
|
||||
'his_date_start' => $startsDT->format("Y-m-d"),
|
||||
'his_time_start' => $startsDT->format("H:i"),
|
||||
'his_date_end' => $endsDT->format("Y-m-d"),
|
||||
'his_time_end' => $endsDT->format("H:i")
|
||||
));
|
||||
|
||||
$errorStatus = Application_Model_StreamSetting::GetAllListenerStatErrors();
|
||||
|
@ -63,17 +98,8 @@ class ListenerstatController extends Zend_Controller_Action
|
|||
}
|
||||
|
||||
public function getDataAction(){
|
||||
$request = $this->getRequest();
|
||||
$current_time = time();
|
||||
|
||||
$params = $request->getParams();
|
||||
|
||||
$starts_epoch = $request->getParam("startTimestamp", $current_time - (60*60*24));
|
||||
$ends_epoch = $request->getParam("endTimestamp", $current_time);
|
||||
|
||||
$startsDT = DateTime::createFromFormat("U", $starts_epoch, new DateTimeZone("UTC"));
|
||||
$endsDT = DateTime::createFromFormat("U", $ends_epoch, new DateTimeZone("UTC"));
|
||||
|
||||
list($startsDT, $endsDT) = $this->getStartEnd();
|
||||
|
||||
$data = Application_Model_ListenerStat::getDataPointsWithinRange($startsDT->format("Y-m-d H:i:s"), $endsDT->format("Y-m-d H:i:s"));
|
||||
$this->_helper->json->sendJson($data);
|
||||
}
|
||||
|
|
|
@ -17,35 +17,68 @@ class PlayouthistoryController extends Zend_Controller_Action
|
|||
->addActionContext('update-list-item', 'json')
|
||||
->addActionContext('update-file-item', 'json')
|
||||
->initContext();
|
||||
}
|
||||
}
|
||||
|
||||
private function getStartEnd()
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
|
||||
$userTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone());
|
||||
$utcTimezone = new DateTimeZone("UTC");
|
||||
$utcNow = new DateTime("now", $utcTimezone);
|
||||
|
||||
$start = $request->getParam("start");
|
||||
$end = $request->getParam("end");
|
||||
|
||||
if (empty($start) || empty($end)) {
|
||||
$startsDT = clone $utcNow;
|
||||
$startsDT->sub(new DateInterval("P1D"));
|
||||
$endsDT = clone $utcNow;
|
||||
}
|
||||
else {
|
||||
|
||||
try {
|
||||
$startsDT = new DateTime($start, $userTimezone);
|
||||
$startsDT->setTimezone($utcTimezone);
|
||||
|
||||
$endsDT = new DateTime($end, $userTimezone);
|
||||
$endsDT->setTimezone($utcTimezone);
|
||||
|
||||
if ($startsDT > $endsDT) {
|
||||
throw new Exception("start greater than end");
|
||||
}
|
||||
}
|
||||
catch (Exception $e) {
|
||||
Logging::info($e);
|
||||
Logging::info($e->getMessage());
|
||||
|
||||
$startsDT = clone $utcNow;
|
||||
$startsDT->sub(new DateInterval("P1D"));
|
||||
$endsDT = clone $utcNow;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return array($startsDT, $endsDT);
|
||||
}
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$CC_CONFIG = Config::getConfig();
|
||||
|
||||
$request = $this->getRequest();
|
||||
|
||||
$baseUrl = Application_Common_OsPath::getBaseDir();
|
||||
|
||||
//default time is the last 24 hours.
|
||||
$now = time();
|
||||
$from = $request->getParam("from", $now - (24*60*60));
|
||||
$to = $request->getParam("to", $now);
|
||||
|
||||
$utcTimezone = new DateTimeZone("UTC");
|
||||
$displayTimeZone = new DateTimeZone(Application_Model_Preference::GetTimezone());
|
||||
|
||||
$start = DateTime::createFromFormat("U", $from, $utcTimezone);
|
||||
$start->setTimezone($displayTimeZone);
|
||||
$end = DateTime::createFromFormat("U", $to, $utcTimezone);
|
||||
$end->setTimezone($displayTimeZone);
|
||||
list($startsDT, $endsDT) = $this->getStartEnd();
|
||||
|
||||
$userTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone());
|
||||
$startsDT->setTimezone($userTimezone);
|
||||
$endsDT->setTimezone($userTimezone);
|
||||
|
||||
$form = new Application_Form_DateRange();
|
||||
$form->populate(array(
|
||||
'his_date_start' => $start->format("Y-m-d"),
|
||||
'his_time_start' => $start->format("H:i"),
|
||||
'his_date_end' => $end->format("Y-m-d"),
|
||||
'his_time_end' => $end->format("H:i")
|
||||
'his_date_start' => $startsDT->format("Y-m-d"),
|
||||
'his_time_start' => $startsDT->format("H:i"),
|
||||
'his_date_end' => $endsDT->format("Y-m-d"),
|
||||
'his_time_end' => $endsDT->format("H:i")
|
||||
));
|
||||
|
||||
$this->view->date_form = $form;
|
||||
|
@ -87,15 +120,10 @@ class PlayouthistoryController extends Zend_Controller_Action
|
|||
{
|
||||
try {
|
||||
$request = $this->getRequest();
|
||||
$current_time = time();
|
||||
|
||||
$params = $request->getParams();
|
||||
|
||||
$starts_epoch = $request->getParam("start", $current_time - (60*60*24));
|
||||
$ends_epoch = $request->getParam("end", $current_time);
|
||||
|
||||
$startsDT = DateTime::createFromFormat("U", $starts_epoch, new DateTimeZone("UTC"));
|
||||
$endsDT = DateTime::createFromFormat("U", $ends_epoch, new DateTimeZone("UTC"));
|
||||
$params = $request->getParams();
|
||||
$instance = $request->getParam("instance_id", null);
|
||||
|
||||
list($startsDT, $endsDT) = $this->getStartEnd();
|
||||
|
||||
$historyService = new Application_Service_HistoryService();
|
||||
$r = $historyService->getFileSummaryData($startsDT, $endsDT, $params);
|
||||
|
@ -114,18 +142,12 @@ class PlayouthistoryController extends Zend_Controller_Action
|
|||
public function itemHistoryFeedAction()
|
||||
{
|
||||
try {
|
||||
$request = $this->getRequest();
|
||||
$current_time = time();
|
||||
|
||||
$params = $request->getParams();
|
||||
|
||||
$starts_epoch = $request->getParam("start", $current_time - (60*60*24));
|
||||
$ends_epoch = $request->getParam("end", $current_time);
|
||||
$instance = $request->getParam("instance_id", null);
|
||||
|
||||
$startsDT = DateTime::createFromFormat("U", $starts_epoch, new DateTimeZone("UTC"));
|
||||
$endsDT = DateTime::createFromFormat("U", $ends_epoch, new DateTimeZone("UTC"));
|
||||
|
||||
$request = $this->getRequest();
|
||||
$params = $request->getParams();
|
||||
$instance = $request->getParam("instance_id", null);
|
||||
|
||||
list($startsDT, $endsDT) = $this->getStartEnd();
|
||||
|
||||
$historyService = new Application_Service_HistoryService();
|
||||
$r = $historyService->getPlayedItemData($startsDT, $endsDT, $params, $instance);
|
||||
|
||||
|
@ -144,12 +166,10 @@ class PlayouthistoryController extends Zend_Controller_Action
|
|||
{
|
||||
try {
|
||||
$request = $this->getRequest();
|
||||
$current_time = time();
|
||||
$starts_epoch = $request->getParam("start", $current_time - (60*60*24));
|
||||
$ends_epoch = $request->getParam("end", $current_time);
|
||||
|
||||
$startsDT = DateTime::createFromFormat("U", $starts_epoch, new DateTimeZone("UTC"));
|
||||
$endsDT = DateTime::createFromFormat("U", $ends_epoch, new DateTimeZone("UTC"));
|
||||
$params = $request->getParams();
|
||||
$instance = $request->getParam("instance_id", null);
|
||||
|
||||
list($startsDT, $endsDT) = $this->getStartEnd();
|
||||
|
||||
$historyService = new Application_Service_HistoryService();
|
||||
$shows = $historyService->getShowList($startsDT, $endsDT);
|
||||
|
|
|
@ -230,29 +230,66 @@ class ShowbuilderController extends Zend_Controller_Action
|
|||
$end_time = $end->format("Y-m-d H:i:s");
|
||||
|
||||
$this->view->title = "{$show_name}: {$start_time} - {$end_time}";
|
||||
$this->view->start = $instance->getDbStarts("U");
|
||||
$this->view->end = $instance->getDbEnds("U");
|
||||
$this->view->start = $start_time;
|
||||
$this->view->end = $end_time;
|
||||
|
||||
$this->view->dialog = $this->view->render('showbuilder/builderDialog.phtml');
|
||||
}
|
||||
|
||||
private function getStartEnd()
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
|
||||
$userTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone());
|
||||
$utcTimezone = new DateTimeZone("UTC");
|
||||
$utcNow = new DateTime("now", $utcTimezone);
|
||||
|
||||
$start = $request->getParam("start");
|
||||
$end = $request->getParam("end");
|
||||
|
||||
if (empty($start) || empty($end)) {
|
||||
$startsDT = clone $utcNow;
|
||||
$startsDT->sub(new DateInterval("P1D"));
|
||||
$endsDT = clone $utcNow;
|
||||
}
|
||||
else {
|
||||
|
||||
try {
|
||||
$startsDT = new DateTime($start, $userTimezone);
|
||||
$startsDT->setTimezone($utcTimezone);
|
||||
|
||||
$endsDT = new DateTime($end, $userTimezone);
|
||||
$endsDT->setTimezone($utcTimezone);
|
||||
|
||||
if ($startsDT > $endsDT) {
|
||||
throw new Exception("start greater than end");
|
||||
}
|
||||
}
|
||||
catch (Exception $e) {
|
||||
Logging::info($e);
|
||||
Logging::info($e->getMessage());
|
||||
|
||||
$startsDT = clone $utcNow;
|
||||
$startsDT->sub(new DateInterval("P1D"));
|
||||
$endsDT = clone $utcNow;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return array($startsDT, $endsDT);
|
||||
}
|
||||
|
||||
public function checkBuilderFeedAction()
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
$current_time = time();
|
||||
|
||||
$starts_epoch = $request->getParam("start", $current_time);
|
||||
//default ends is 24 hours after starts.
|
||||
$ends_epoch = $request->getParam("end", $current_time + (60*60*24));
|
||||
$request = $this->getRequest();
|
||||
$show_filter = intval($request->getParam("showFilter", 0));
|
||||
$my_shows = intval($request->getParam("myShows", 0));
|
||||
$timestamp = intval($request->getParam("timestamp", -1));
|
||||
$instances = $request->getParam("instances", array());
|
||||
$my_shows = intval($request->getParam("myShows", 0));
|
||||
$timestamp = intval($request->getParam("timestamp", -1));
|
||||
$instances = $request->getParam("instances", array());
|
||||
|
||||
$startsDT = DateTime::createFromFormat("U", $starts_epoch, new DateTimeZone("UTC"));
|
||||
$endsDT = DateTime::createFromFormat("U", $ends_epoch, new DateTimeZone("UTC"));
|
||||
list($startsDT, $endsDT) = $this->getStartEnd();
|
||||
|
||||
$opts = array("myShows" => $my_shows, "showFilter" => $show_filter);
|
||||
$opts = array("myShows" => $my_shows, "showFilter" => $show_filter);
|
||||
$showBuilder = new Application_Model_ShowBuilder($startsDT, $endsDT, $opts);
|
||||
|
||||
//only send the schedule back if updates have been made.
|
||||
|
@ -263,18 +300,14 @@ class ShowbuilderController extends Zend_Controller_Action
|
|||
|
||||
public function builderFeedAction()
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
$current_time = time();
|
||||
|
||||
$starts_epoch = $request->getParam("start", $current_time);
|
||||
//default ends is 24 hours after starts.
|
||||
$ends_epoch = $request->getParam("end", $current_time + (60*60*24));
|
||||
$current_time = time();
|
||||
|
||||
$request = $this->getRequest();
|
||||
$show_filter = intval($request->getParam("showFilter", 0));
|
||||
$show_instance_filter = intval($request->getParam("showInstanceFilter", 0));
|
||||
$my_shows = intval($request->getParam("myShows", 0));
|
||||
$my_shows = intval($request->getParam("myShows", 0));
|
||||
|
||||
$startsDT = DateTime::createFromFormat("U", $starts_epoch, new DateTimeZone("UTC"));
|
||||
$endsDT = DateTime::createFromFormat("U", $ends_epoch, new DateTimeZone("UTC"));
|
||||
list($startsDT, $endsDT) = $this->getStartEnd();
|
||||
|
||||
$opts = array("myShows" => $my_shows,
|
||||
"showFilter" => $show_filter,
|
||||
|
|
|
@ -590,15 +590,14 @@ class Application_Model_Scheduler
|
|||
* to that show
|
||||
*/
|
||||
if ($linked) {
|
||||
$instance_sql = "SELECT * FROM cc_show_instances ".
|
||||
"WHERE show_id = ".$ccShow["id"];
|
||||
$instances = Application_Common_Database::prepareAndExecute(
|
||||
$instance_sql);
|
||||
$instances = CcShowInstancesQuery::create()
|
||||
->filterByDbShowId($ccShow["id"])
|
||||
->filterByDbStarts(gmdate("Y-m-d H:i:s"), Criteria::GREATER_THAN)
|
||||
->find();
|
||||
} else {
|
||||
$instance_sql = "SELECT * FROM cc_show_instances ".
|
||||
"WHERE id = ".$schedule["instance"];
|
||||
$instances = Application_Common_Database::prepareAndExecute(
|
||||
$instance_sql);
|
||||
$instances = CcShowInstancesQuery::create()
|
||||
->filterByDbId($schedule["instance"])
|
||||
->find();
|
||||
}
|
||||
|
||||
$excludePositions = array();
|
||||
|
@ -606,7 +605,8 @@ class Application_Model_Scheduler
|
|||
//reset
|
||||
$this->applyCrossfades = true;
|
||||
|
||||
$instanceId = $instance["id"];
|
||||
//$instanceId = $instance["id"];
|
||||
$instanceId = $instance->getDbId();
|
||||
if ($id !== 0) {
|
||||
/* We use the selected cursor's position to find the same
|
||||
* positions in every other linked instance
|
||||
|
@ -632,7 +632,7 @@ class Application_Model_Scheduler
|
|||
//show instance has no scheduled tracks
|
||||
if (empty($pos)) {
|
||||
$pos = 0;
|
||||
$nextStartDT = new DateTime($instance["starts"], new DateTimeZone("UTC"));
|
||||
$nextStartDT = new DateTime($instance->getDbStarts(), new DateTimeZone("UTC"));
|
||||
} else {
|
||||
|
||||
$linkedItem_sql = "SELECT ends FROM cc_schedule ".
|
||||
|
@ -658,7 +658,7 @@ class Application_Model_Scheduler
|
|||
}
|
||||
//selected empty row to add after
|
||||
else {
|
||||
$showStartDT = new DateTime($instance["starts"], new DateTimeZone("UTC"));
|
||||
$showStartDT = new DateTime($instance->getDbStarts(), new DateTimeZone("UTC"));
|
||||
$nextStartDT = $this->findNextStartTime($showStartDT, $instanceId);
|
||||
|
||||
//first item in show so start position counter at 0
|
||||
|
@ -706,6 +706,9 @@ class Application_Model_Scheduler
|
|||
$doUpdate = false;
|
||||
$values = array();
|
||||
|
||||
//array that stores the cc_file ids so we can update the is_scheduled flag
|
||||
$fileIds = array();
|
||||
|
||||
foreach ($filesToInsert as &$file) {
|
||||
//item existed previously and is being moved.
|
||||
//need to keep same id for resources if we want REST.
|
||||
|
@ -761,9 +764,6 @@ class Application_Model_Scheduler
|
|||
$file['fadein'] = Application_Common_DateHelper::secondsToPlaylistTime($file['fadein']);
|
||||
$file['fadeout'] = Application_Common_DateHelper::secondsToPlaylistTime($file['fadeout']);
|
||||
|
||||
//array that stores the cc_file ids so we can update the is_scheduled flag
|
||||
$fileIds = array();
|
||||
|
||||
switch ($file["type"]) {
|
||||
case 0:
|
||||
$fileId = $file["id"];
|
||||
|
|
|
@ -47,6 +47,9 @@ class CcShow extends BaseCcShow {
|
|||
*/
|
||||
public function getFirstCcShowDay($criteria = null, PropelPDO $con = null)
|
||||
{
|
||||
/*CcShowPeer::clearInstancePool();
|
||||
CcShowPeer::clearRelatedInstancePool();*/
|
||||
|
||||
if(null === $this->collCcShowDayss || null !== $criteria) {
|
||||
if ($this->isNew() && null === $this->collCcShowDayss) {
|
||||
// return empty collection
|
||||
|
|
|
@ -304,24 +304,20 @@ class Application_Service_SchedulerService
|
|||
|
||||
private static function replaceInstanceContentCheck($currentShowStamp, $showStamp)
|
||||
{
|
||||
/*$currentShowStamp = CcScheduleQuery::create()
|
||||
->filterByDbInstanceId($ccShowInstance->getDbId())
|
||||
->orderByDbStarts()
|
||||
->find();*/
|
||||
|
||||
$counter = 0;
|
||||
foreach ($showStamp as $item) {
|
||||
if ($item["file_id"] != $currentShowStamp[$counter]["file_id"] ||
|
||||
$item["stream_id"] != $currentShowStamp[$counter]["stream_id"]) {
|
||||
/*CcScheduleQuery::create()
|
||||
->filterByDbInstanceId($ccShowInstance->getDbId())
|
||||
->delete();*/
|
||||
$delete_sql = "DELETE FROM cc_schedule ".
|
||||
"WHERE instance_id = {$currentShowStamp[$counter]["instance_id"]}";
|
||||
Application_Common_Database::prepareAndExecute(
|
||||
$delete_sql, array(), Application_Common_Database::EXECUTE);
|
||||
return true;
|
||||
}
|
||||
/*CcScheduleQuery::create()
|
||||
->filterByDbInstanceId($ccShowInstance->getDbId())
|
||||
->delete();*/
|
||||
$delete_sql = "DELETE FROM cc_schedule ".
|
||||
"WHERE instance_id = {$currentShowStamp[$counter]["instance_id"]}";
|
||||
Application_Common_Database::prepareAndExecute(
|
||||
$delete_sql, array(), Application_Common_Database::EXECUTE);
|
||||
return true;
|
||||
}
|
||||
$counter += 1;
|
||||
}
|
||||
|
||||
/* If we get here, the content in the show instance is the same
|
||||
|
|
|
@ -20,6 +20,8 @@ class Application_Service_ShowService
|
|||
private $localShowStartHour;
|
||||
private $localShowStartMin;
|
||||
private $origCcShowDay;
|
||||
private $origShowRepeatStatus;
|
||||
private $instanceIdsForScheduleUpdates;
|
||||
|
||||
public function __construct($showId=null, $showData=null, $isUpdate=false)
|
||||
{
|
||||
|
@ -39,6 +41,7 @@ class Application_Service_ShowService
|
|||
$this->isRecorded = (isset($showData['add_show_record']) && $showData['add_show_record']) ? 1 : 0;
|
||||
$this->isRebroadcast = (isset($showData['add_show_rebroadcast']) && $showData['add_show_rebroadcast']) ? 1 : 0;
|
||||
$this->isUpdate = $isUpdate;
|
||||
$this->instanceIdsForScheduleUpdates = array();
|
||||
}
|
||||
|
||||
public function editRepeatingShowInstance($showData) {
|
||||
|
@ -156,8 +159,10 @@ class Application_Service_ShowService
|
|||
{
|
||||
if ($this->ccShow->isRepeating()) {
|
||||
$this->origCcShowDay = clone $this->ccShow->getFirstRepeatingCcShowDay();
|
||||
$this->origShowRepeatStatus = true;
|
||||
} else {
|
||||
$this->origCcShowDay = clone $this->ccShow->getFirstCcShowDay();
|
||||
$this->origShowRepeatStatus = false;
|
||||
}
|
||||
|
||||
$this->oldShowTimezone = $this->origCcShowDay->getDbTimezone();
|
||||
|
@ -181,15 +186,18 @@ class Application_Service_ShowService
|
|||
if (!$currentUser->isAdminOrPM()) {
|
||||
throw new Exception("Permission denied");
|
||||
}
|
||||
|
||||
//update ccShow
|
||||
$this->setCcShow($showData);
|
||||
|
||||
$daysAdded = array();
|
||||
|
||||
if ($this->isUpdate) {
|
||||
$daysAdded = $this->delegateInstanceCleanup($showData);
|
||||
if (!$this->ccShow->getCcShowDayss()->isEmpty()) {
|
||||
$this->storeOrigLocalShowInfo();
|
||||
}
|
||||
|
||||
$this->storeOrigLocalShowInfo();
|
||||
$daysAdded = $this->delegateInstanceCleanup($showData);
|
||||
|
||||
$this->deleteRebroadcastInstances();
|
||||
|
||||
|
@ -199,6 +207,8 @@ class Application_Service_ShowService
|
|||
//delete entry in cc_show_rebroadcast
|
||||
$this->deleteCcShowRebroadcasts();
|
||||
}
|
||||
|
||||
$this->storeInstanceIds();
|
||||
}
|
||||
|
||||
//update ccShowDays
|
||||
|
@ -214,6 +224,16 @@ class Application_Service_ShowService
|
|||
$this->delegateInstanceCreation($daysAdded);
|
||||
|
||||
if ($this->isUpdate) {
|
||||
|
||||
/* If the show is repeating and the start date changes we need
|
||||
* to ignore that difference when re-calculating schedule start times.
|
||||
* Otherwise it might calculate a difference of a week, for example.
|
||||
*/
|
||||
if ($this->ccShow->isRepeating() &&
|
||||
$this->origCcShowDay->getLocalStartDateAndTime()->format("Y-m-d") != $showData["add_show_start_date"]) {
|
||||
$showData["add_show_start_date"] = $this->origCcShowDay->getLocalStartDateAndTime()->format("Y-m-d");
|
||||
}
|
||||
|
||||
$this->adjustSchedule($showData);
|
||||
}
|
||||
|
||||
|
@ -227,15 +247,28 @@ class Application_Service_ShowService
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Returns an array of instance ids that already exist
|
||||
* We need this if a show is being updated so we can separate the
|
||||
* instances that already exist and any new instances that
|
||||
* get created (by adding a new repeat show day)
|
||||
*/
|
||||
private function storeInstanceIds()
|
||||
{
|
||||
$instances = $this->ccShow->getCcShowInstancess();
|
||||
foreach ($instances as $instance) {
|
||||
$this->instanceIdsForScheduleUpdates[] = $instance->getDbId();
|
||||
}
|
||||
}
|
||||
|
||||
private function adjustSchedule($showData)
|
||||
{
|
||||
$con = Propel::getConnection(CcSchedulePeer::DATABASE_NAME);
|
||||
$ccShowInstances = CcShowInstancesQuery::create()
|
||||
->filterByDbShowId($this->ccShow->getDbId())
|
||||
->find();
|
||||
|
||||
$this->updateScheduleStartEndTimes($showData);
|
||||
|
||||
$ccShowInstances = $this->ccShow->getCcShowInstancess();
|
||||
foreach ($ccShowInstances as $instance) {
|
||||
$instance->updateScheduleStatus($con);
|
||||
}
|
||||
|
@ -385,6 +418,13 @@ SQL;
|
|||
':timestamp' => gmdate("Y-m-d H:i:s")), 'execute');
|
||||
}
|
||||
|
||||
private function deleteAllShowDays($showId)
|
||||
{
|
||||
CcShowDaysQuery::create()
|
||||
->filterByDbShowId($showId)
|
||||
->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: This function is messy. Needs refactoring
|
||||
*
|
||||
|
@ -406,8 +446,14 @@ SQL;
|
|||
//CcShowDay object
|
||||
if ($this->ccShow->isRepeating()) {
|
||||
$currentShowDay = $this->ccShow->getFirstRepeatingCcShowDay();
|
||||
|
||||
//all cc_show_days
|
||||
$ccShowDays = $this->ccShow->getRepeatingCcShowDays();
|
||||
} else {
|
||||
$currentShowDay = $this->ccShow->getFirstCcShowDay();
|
||||
|
||||
//all cc_show_days
|
||||
$ccShowDays = $this->ccShow->getCcShowDayss();
|
||||
}
|
||||
|
||||
//new end date in the show's timezone (from the select box)
|
||||
|
@ -416,6 +462,11 @@ SQL;
|
|||
//repeat option was toggled
|
||||
if ($showData['add_show_repeats'] != $currentShowDay->isRepeating()) {
|
||||
$this->deleteAllRepeatInstances($currentShowDay, $showId);
|
||||
|
||||
if (!$showData["add_show_repeats"]) {
|
||||
$this->deleteAllShowDays($showId);
|
||||
}
|
||||
|
||||
//if repeat option was checked we need to treat the current show day
|
||||
//as a new show day so the repeat instances get created properly
|
||||
//in createWeeklyRepeatInstances()
|
||||
|
@ -447,17 +498,13 @@ SQL;
|
|||
//and the repeat type changed
|
||||
if ($currentRepeatType != -1 && $this->repeatType != $currentRepeatType) {
|
||||
$this->deleteAllInstances($showId);
|
||||
$this->deleteAllShowDays($showId);
|
||||
|
||||
// when repeating by day of the month (1st, 2nd, etc.) we do not store the repeat week days
|
||||
} elseif ($currentRepeatType != 2) {
|
||||
//repeat type is the same, check if the days of the week are the same
|
||||
$repeatingDaysChanged = false;
|
||||
|
||||
if ($this->ccShow->isRepeating()) {
|
||||
$ccShowDays = $this->ccShow->getRepeatingCcShowDays();
|
||||
} else {
|
||||
$ccShowDays = $this->ccShow->getCcShowDayss();
|
||||
}
|
||||
|
||||
$showDays = array();
|
||||
foreach ($ccShowDays as $day) {
|
||||
$showDays[] = $day->getDbDay();
|
||||
|
@ -508,12 +555,11 @@ SQL;
|
|||
//check if this is null if "no end"
|
||||
$currentShowEndDateTime = $this->getRepeatingEndDate();
|
||||
|
||||
if ($currentShowEndDateTime != $endDateTime) {
|
||||
|
||||
if ($endDateTime && $currentShowEndDateTime != $endDateTime) {
|
||||
$endDate = clone $endDateTime;
|
||||
$endDate->setTimezone(new DateTimeZone("UTC"));
|
||||
|
||||
//show "No End" option was toggled
|
||||
//show's "No End" option was toggled
|
||||
//or the end date comes earlier
|
||||
if (is_null($currentShowEndDateTime) || ($endDateTime < $currentShowEndDateTime)) {
|
||||
//"No End" option was unchecked so we need to delete the
|
||||
|
@ -531,11 +577,14 @@ SQL;
|
|||
|
||||
private function preserveLinkedShowContent()
|
||||
{
|
||||
/* Get show content from any linekd instance. It doesn't
|
||||
/* Get show content from any linked instance. It doesn't
|
||||
* matter which instance since content is the same in all.
|
||||
*/
|
||||
$ccShowInstance = $this->ccShow->getCcShowInstancess()->getFirst();
|
||||
|
||||
if (!$ccShowInstance) {
|
||||
return;
|
||||
}
|
||||
$ccSchedules = CcScheduleQuery::create()
|
||||
->filterByDbInstanceId($ccShowInstance->getDbId())
|
||||
->find();
|
||||
|
@ -881,7 +930,6 @@ SQL;
|
|||
private function updateScheduleStartEndTimes($showData)
|
||||
{
|
||||
$showId = $this->ccShow->getDbId();
|
||||
|
||||
//DateTime in show's local time
|
||||
$newStartDateTime = new DateTime($showData["add_show_start_date"]." ".
|
||||
$showData["add_show_start_time"],
|
||||
|
@ -890,12 +938,9 @@ SQL;
|
|||
$diff = $this->calculateShowStartDiff($newStartDateTime,
|
||||
$this->origCcShowDay->getLocalStartDateAndTime());
|
||||
|
||||
$ccShowInstances = $this->ccShow->getFutureCcShowInstancess();
|
||||
$instanceIds = array();
|
||||
foreach ($ccShowInstances as $ccShowInstance) {
|
||||
array_push($instanceIds, $ccShowInstance->getDbId());
|
||||
}
|
||||
Application_Service_SchedulerService::updateScheduleStartTime($instanceIds, $diff);
|
||||
Application_Service_SchedulerService::updateScheduleStartTime(
|
||||
$this->instanceIdsForScheduleUpdates,
|
||||
$diff);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1487,8 +1532,12 @@ SQL;
|
|||
if ($this->isUpdate) {
|
||||
$showDay = CcShowDaysQuery::create()
|
||||
->filterByDbShowId($showId)
|
||||
->filterByDbRepeatType($showData['add_show_repeat_type'])
|
||||
->filterByDbRepeatType($this->origCcShowDay->getDbRepeatType())
|
||||
->findOne();
|
||||
if (!$showDay) {
|
||||
//repeat type changed so we have to create a new show_day rule
|
||||
$showDay = new CcShowDays();
|
||||
}
|
||||
} else {
|
||||
$showDay = new CcShowDays();
|
||||
}
|
||||
|
@ -1520,16 +1569,30 @@ SQL;
|
|||
if (is_null($endDate) || $startDateTimeClone->getTimestamp() <= $endDateTime->getTimestamp()) {
|
||||
|
||||
if ($this->isUpdate) {
|
||||
if ($this->origCcShowDay->getDbRepeatType() == 2 ||
|
||||
$this->origCcShowDay->getDbRepeatType() == 3) {
|
||||
$day = null;
|
||||
} else if (!$this->origShowRepeatStatus) {
|
||||
//keep current show day to use for updating cc_show_day rule
|
||||
$keepDay = $day;
|
||||
$day = $this->origCcShowDay->getDbDay();
|
||||
}
|
||||
|
||||
$showDay = CcShowDaysQuery::create()
|
||||
->filterByDbShowId($showId)
|
||||
->filterByDbRepeatType($this->repeatType)
|
||||
->filterByDbRepeatType($this->origCcShowDay->getDbRepeatType())
|
||||
->filterByDbDay($day)
|
||||
->findOne();
|
||||
if (!$showDay) {
|
||||
//if no show day object was found it is because a new
|
||||
//repeating day of the week was added
|
||||
//repeating day of the week was added OR the repeat
|
||||
//type has changed
|
||||
$showDay = new CcShowDays();
|
||||
}
|
||||
|
||||
if (isset($keepDay)) {
|
||||
$day = $keepDay;
|
||||
}
|
||||
} else {
|
||||
$showDay = new CcShowDays();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue