Merge branch '2.5.x' of github.com:sourcefabric/Airtime into 2.5.x

This commit is contained in:
Albert Santoni 2014-03-11 18:28:47 -04:00
commit 2cf9c5ca1b
12 changed files with 516 additions and 210 deletions

View File

@ -9,6 +9,49 @@ class ListenerstatController extends Zend_Controller_Action
->addActionContext('get-data', 'json') ->addActionContext('get-data', 'json')
->initContext(); ->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() 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']); $this->view->headLink()->appendStylesheet($baseUrl.'css/jquery.ui.timepicker.css?'.$CC_CONFIG['airtime_version']);
//default time is the last 24 hours. list($startsDT, $endsDT) = $this->getStartEnd();
$now = time(); $userTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone());
$from = $request->getParam("from", $now - (24*60*60)); $startsDT->setTimezone($userTimezone);
$to = $request->getParam("to", $now); $endsDT->setTimezone($userTimezone);
$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);
$form = new Application_Form_DateRange(); $form = new Application_Form_DateRange();
$form->populate(array( $form->populate(array(
'his_date_start' => $start->format("Y-m-d"), 'his_date_start' => $startsDT->format("Y-m-d"),
'his_time_start' => $start->format("H:i"), 'his_time_start' => $startsDT->format("H:i"),
'his_date_end' => $end->format("Y-m-d"), 'his_date_end' => $endsDT->format("Y-m-d"),
'his_time_end' => $end->format("H:i") 'his_time_end' => $endsDT->format("H:i")
)); ));
$errorStatus = Application_Model_StreamSetting::GetAllListenerStatErrors(); $errorStatus = Application_Model_StreamSetting::GetAllListenerStatErrors();
@ -63,17 +98,8 @@ class ListenerstatController extends Zend_Controller_Action
} }
public function getDataAction(){ public function getDataAction(){
$request = $this->getRequest(); list($startsDT, $endsDT) = $this->getStartEnd();
$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"));
$data = Application_Model_ListenerStat::getDataPointsWithinRange($startsDT->format("Y-m-d H:i:s"), $endsDT->format("Y-m-d H:i:s")); $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); $this->_helper->json->sendJson($data);
} }

View File

@ -17,35 +17,68 @@ class PlayouthistoryController extends Zend_Controller_Action
->addActionContext('update-list-item', 'json') ->addActionContext('update-list-item', 'json')
->addActionContext('update-file-item', 'json') ->addActionContext('update-file-item', 'json')
->initContext(); ->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() public function indexAction()
{ {
$CC_CONFIG = Config::getConfig(); $CC_CONFIG = Config::getConfig();
$request = $this->getRequest();
$baseUrl = Application_Common_OsPath::getBaseDir(); $baseUrl = Application_Common_OsPath::getBaseDir();
//default time is the last 24 hours. list($startsDT, $endsDT) = $this->getStartEnd();
$now = time();
$from = $request->getParam("from", $now - (24*60*60)); $userTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone());
$to = $request->getParam("to", $now); $startsDT->setTimezone($userTimezone);
$endsDT->setTimezone($userTimezone);
$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);
$form = new Application_Form_DateRange(); $form = new Application_Form_DateRange();
$form->populate(array( $form->populate(array(
'his_date_start' => $start->format("Y-m-d"), 'his_date_start' => $startsDT->format("Y-m-d"),
'his_time_start' => $start->format("H:i"), 'his_time_start' => $startsDT->format("H:i"),
'his_date_end' => $end->format("Y-m-d"), 'his_date_end' => $endsDT->format("Y-m-d"),
'his_time_end' => $end->format("H:i") 'his_time_end' => $endsDT->format("H:i")
)); ));
$this->view->date_form = $form; $this->view->date_form = $form;
@ -87,15 +120,10 @@ class PlayouthistoryController extends Zend_Controller_Action
{ {
try { try {
$request = $this->getRequest(); $request = $this->getRequest();
$current_time = time(); $params = $request->getParams();
$instance = $request->getParam("instance_id", null);
$params = $request->getParams();
list($startsDT, $endsDT) = $this->getStartEnd();
$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"));
$historyService = new Application_Service_HistoryService(); $historyService = new Application_Service_HistoryService();
$r = $historyService->getFileSummaryData($startsDT, $endsDT, $params); $r = $historyService->getFileSummaryData($startsDT, $endsDT, $params);
@ -114,18 +142,12 @@ class PlayouthistoryController extends Zend_Controller_Action
public function itemHistoryFeedAction() public function itemHistoryFeedAction()
{ {
try { try {
$request = $this->getRequest(); $request = $this->getRequest();
$current_time = time(); $params = $request->getParams();
$instance = $request->getParam("instance_id", null);
$params = $request->getParams();
list($startsDT, $endsDT) = $this->getStartEnd();
$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"));
$historyService = new Application_Service_HistoryService(); $historyService = new Application_Service_HistoryService();
$r = $historyService->getPlayedItemData($startsDT, $endsDT, $params, $instance); $r = $historyService->getPlayedItemData($startsDT, $endsDT, $params, $instance);
@ -144,12 +166,10 @@ class PlayouthistoryController extends Zend_Controller_Action
{ {
try { try {
$request = $this->getRequest(); $request = $this->getRequest();
$current_time = time(); $params = $request->getParams();
$starts_epoch = $request->getParam("start", $current_time - (60*60*24)); $instance = $request->getParam("instance_id", null);
$ends_epoch = $request->getParam("end", $current_time);
list($startsDT, $endsDT) = $this->getStartEnd();
$startsDT = DateTime::createFromFormat("U", $starts_epoch, new DateTimeZone("UTC"));
$endsDT = DateTime::createFromFormat("U", $ends_epoch, new DateTimeZone("UTC"));
$historyService = new Application_Service_HistoryService(); $historyService = new Application_Service_HistoryService();
$shows = $historyService->getShowList($startsDT, $endsDT); $shows = $historyService->getShowList($startsDT, $endsDT);

View File

@ -235,24 +235,61 @@ class ShowbuilderController extends Zend_Controller_Action
$this->view->dialog = $this->view->render('showbuilder/builderDialog.phtml'); $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() public function checkBuilderFeedAction()
{ {
$request = $this->getRequest(); $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));
$show_filter = intval($request->getParam("showFilter", 0)); $show_filter = intval($request->getParam("showFilter", 0));
$my_shows = intval($request->getParam("myShows", 0)); $my_shows = intval($request->getParam("myShows", 0));
$timestamp = intval($request->getParam("timestamp", -1)); $timestamp = intval($request->getParam("timestamp", -1));
$instances = $request->getParam("instances", array()); $instances = $request->getParam("instances", array());
$startsDT = DateTime::createFromFormat("U", $starts_epoch, new DateTimeZone("UTC")); list($startsDT, $endsDT) = $this->getStartEnd();
$endsDT = DateTime::createFromFormat("U", $ends_epoch, new DateTimeZone("UTC"));
$opts = array("myShows" => $my_shows, "showFilter" => $show_filter); $opts = array("myShows" => $my_shows, "showFilter" => $show_filter);
$showBuilder = new Application_Model_ShowBuilder($startsDT, $endsDT, $opts); $showBuilder = new Application_Model_ShowBuilder($startsDT, $endsDT, $opts);
//only send the schedule back if updates have been made. //only send the schedule back if updates have been made.
@ -263,18 +300,14 @@ class ShowbuilderController extends Zend_Controller_Action
public function builderFeedAction() public function builderFeedAction()
{ {
$request = $this->getRequest(); $current_time = time();
$current_time = time();
$request = $this->getRequest();
$starts_epoch = $request->getParam("start", $current_time);
//default ends is 24 hours after starts.
$ends_epoch = $request->getParam("end", $current_time + (60*60*24));
$show_filter = intval($request->getParam("showFilter", 0)); $show_filter = intval($request->getParam("showFilter", 0));
$show_instance_filter = intval($request->getParam("showInstanceFilter", 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")); list($startsDT, $endsDT) = $this->getStartEnd();
$endsDT = DateTime::createFromFormat("U", $ends_epoch, new DateTimeZone("UTC"));
$opts = array("myShows" => $my_shows, $opts = array("myShows" => $my_shows,
"showFilter" => $show_filter, "showFilter" => $show_filter,

View File

@ -590,15 +590,14 @@ class Application_Model_Scheduler
* to that show * to that show
*/ */
if ($linked) { if ($linked) {
$instance_sql = "SELECT * FROM cc_show_instances ". $instances = CcShowInstancesQuery::create()
"WHERE show_id = ".$ccShow["id"]; ->filterByDbShowId($ccShow["id"])
$instances = Application_Common_Database::prepareAndExecute( ->filterByDbStarts(gmdate("Y-m-d H:i:s"), Criteria::GREATER_THAN)
$instance_sql); ->find();
} else { } else {
$instance_sql = "SELECT * FROM cc_show_instances ". $instances = CcShowInstancesQuery::create()
"WHERE id = ".$schedule["instance"]; ->filterByDbId($schedule["instance"])
$instances = Application_Common_Database::prepareAndExecute( ->find();
$instance_sql);
} }
$excludePositions = array(); $excludePositions = array();
@ -606,7 +605,8 @@ class Application_Model_Scheduler
//reset //reset
$this->applyCrossfades = true; $this->applyCrossfades = true;
$instanceId = $instance["id"]; //$instanceId = $instance["id"];
$instanceId = $instance->getDbId();
if ($id !== 0) { if ($id !== 0) {
/* We use the selected cursor's position to find the same /* We use the selected cursor's position to find the same
* positions in every other linked instance * positions in every other linked instance
@ -632,7 +632,7 @@ class Application_Model_Scheduler
//show instance has no scheduled tracks //show instance has no scheduled tracks
if (empty($pos)) { if (empty($pos)) {
$pos = 0; $pos = 0;
$nextStartDT = new DateTime($instance["starts"], new DateTimeZone("UTC")); $nextStartDT = new DateTime($instance->getDbStarts(), new DateTimeZone("UTC"));
} else { } else {
$linkedItem_sql = "SELECT ends FROM cc_schedule ". $linkedItem_sql = "SELECT ends FROM cc_schedule ".
@ -658,7 +658,7 @@ class Application_Model_Scheduler
} }
//selected empty row to add after //selected empty row to add after
else { else {
$showStartDT = new DateTime($instance["starts"], new DateTimeZone("UTC")); $showStartDT = new DateTime($instance->getDbStarts(), new DateTimeZone("UTC"));
$nextStartDT = $this->findNextStartTime($showStartDT, $instanceId); $nextStartDT = $this->findNextStartTime($showStartDT, $instanceId);
//first item in show so start position counter at 0 //first item in show so start position counter at 0

View File

@ -20,6 +20,7 @@ class Application_Service_ShowService
private $localShowStartHour; private $localShowStartHour;
private $localShowStartMin; private $localShowStartMin;
private $origCcShowDay; private $origCcShowDay;
private $origShowRepeatStatus;
private $instanceIdsForScheduleUpdates; private $instanceIdsForScheduleUpdates;
public function __construct($showId=null, $showData=null, $isUpdate=false) public function __construct($showId=null, $showData=null, $isUpdate=false)
@ -158,8 +159,10 @@ class Application_Service_ShowService
{ {
if ($this->ccShow->isRepeating()) { if ($this->ccShow->isRepeating()) {
$this->origCcShowDay = clone $this->ccShow->getFirstRepeatingCcShowDay(); $this->origCcShowDay = clone $this->ccShow->getFirstRepeatingCcShowDay();
$this->origShowRepeatStatus = true;
} else { } else {
$this->origCcShowDay = clone $this->ccShow->getFirstCcShowDay(); $this->origCcShowDay = clone $this->ccShow->getFirstCcShowDay();
$this->origShowRepeatStatus = false;
} }
$this->oldShowTimezone = $this->origCcShowDay->getDbTimezone(); $this->oldShowTimezone = $this->origCcShowDay->getDbTimezone();
@ -183,6 +186,7 @@ class Application_Service_ShowService
if (!$currentUser->isAdminOrPM()) { if (!$currentUser->isAdminOrPM()) {
throw new Exception("Permission denied"); throw new Exception("Permission denied");
} }
//update ccShow //update ccShow
$this->setCcShow($showData); $this->setCcShow($showData);
@ -220,12 +224,15 @@ class Application_Service_ShowService
$this->delegateInstanceCreation($daysAdded); $this->delegateInstanceCreation($daysAdded);
if ($this->isUpdate) { if ($this->isUpdate) {
/* Set the show's start date to the start date of the first instance.
* We need to do this so we get the correct time diff for /* If the show is repeating and the start date changes we need
* updating show content. CC-5696 * to ignore that difference when re-calculating schedule start times.
* Otherwise it might calculate a difference of a week, for example.
*/ */
$showData["add_show_start_date"] = $this->ccShow->getFirstCcShowDay()->getDbFirstShow(); if ($this->ccShow->isRepeating() &&
$showData["add_show_start_time"] = $this->ccShow->getFirstCcShowDay()->getDbStartTime(); $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); $this->adjustSchedule($showData);
} }
@ -411,6 +418,13 @@ SQL;
':timestamp' => gmdate("Y-m-d H:i:s")), 'execute'); ':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 * TODO: This function is messy. Needs refactoring
* *
@ -432,8 +446,14 @@ SQL;
//CcShowDay object //CcShowDay object
if ($this->ccShow->isRepeating()) { if ($this->ccShow->isRepeating()) {
$currentShowDay = $this->ccShow->getFirstRepeatingCcShowDay(); $currentShowDay = $this->ccShow->getFirstRepeatingCcShowDay();
//all cc_show_days
$ccShowDays = $this->ccShow->getRepeatingCcShowDays();
} else { } else {
$currentShowDay = $this->ccShow->getFirstCcShowDay(); $currentShowDay = $this->ccShow->getFirstCcShowDay();
//all cc_show_days
$ccShowDays = $this->ccShow->getCcShowDayss();
} }
//new end date in the show's timezone (from the select box) //new end date in the show's timezone (from the select box)
@ -442,6 +462,11 @@ SQL;
//repeat option was toggled //repeat option was toggled
if ($showData['add_show_repeats'] != $currentShowDay->isRepeating()) { if ($showData['add_show_repeats'] != $currentShowDay->isRepeating()) {
$this->deleteAllRepeatInstances($currentShowDay, $showId); $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 //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 //as a new show day so the repeat instances get created properly
//in createWeeklyRepeatInstances() //in createWeeklyRepeatInstances()
@ -473,17 +498,13 @@ SQL;
//and the repeat type changed //and the repeat type changed
if ($currentRepeatType != -1 && $this->repeatType != $currentRepeatType) { if ($currentRepeatType != -1 && $this->repeatType != $currentRepeatType) {
$this->deleteAllInstances($showId); $this->deleteAllInstances($showId);
$this->deleteAllShowDays($showId);
// when repeating by day of the month (1st, 2nd, etc.) we do not store the repeat week days // when repeating by day of the month (1st, 2nd, etc.) we do not store the repeat week days
} elseif ($currentRepeatType != 2) { } elseif ($currentRepeatType != 2) {
//repeat type is the same, check if the days of the week are the same //repeat type is the same, check if the days of the week are the same
$repeatingDaysChanged = false; $repeatingDaysChanged = false;
if ($this->ccShow->isRepeating()) {
$ccShowDays = $this->ccShow->getRepeatingCcShowDays();
} else {
$ccShowDays = $this->ccShow->getCcShowDayss();
}
$showDays = array(); $showDays = array();
foreach ($ccShowDays as $day) { foreach ($ccShowDays as $day) {
$showDays[] = $day->getDbDay(); $showDays[] = $day->getDbDay();
@ -556,11 +577,14 @@ SQL;
private function preserveLinkedShowContent() 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. * matter which instance since content is the same in all.
*/ */
$ccShowInstance = $this->ccShow->getCcShowInstancess()->getFirst(); $ccShowInstance = $this->ccShow->getCcShowInstancess()->getFirst();
if (!$ccShowInstance) {
return;
}
$ccSchedules = CcScheduleQuery::create() $ccSchedules = CcScheduleQuery::create()
->filterByDbInstanceId($ccShowInstance->getDbId()) ->filterByDbInstanceId($ccShowInstance->getDbId())
->find(); ->find();
@ -1508,8 +1532,12 @@ SQL;
if ($this->isUpdate) { if ($this->isUpdate) {
$showDay = CcShowDaysQuery::create() $showDay = CcShowDaysQuery::create()
->filterByDbShowId($showId) ->filterByDbShowId($showId)
->filterByDbRepeatType($showData['add_show_repeat_type']) ->filterByDbRepeatType($this->origCcShowDay->getDbRepeatType())
->findOne(); ->findOne();
if (!$showDay) {
//repeat type changed so we have to create a new show_day rule
$showDay = new CcShowDays();
}
} else { } else {
$showDay = new CcShowDays(); $showDay = new CcShowDays();
} }
@ -1541,16 +1569,30 @@ SQL;
if (is_null($endDate) || $startDateTimeClone->getTimestamp() <= $endDateTime->getTimestamp()) { if (is_null($endDate) || $startDateTimeClone->getTimestamp() <= $endDateTime->getTimestamp()) {
if ($this->isUpdate) { 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() $showDay = CcShowDaysQuery::create()
->filterByDbShowId($showId) ->filterByDbShowId($showId)
->filterByDbRepeatType($this->repeatType) ->filterByDbRepeatType($this->origCcShowDay->getDbRepeatType())
->filterByDbDay($day) ->filterByDbDay($day)
->findOne(); ->findOne();
if (!$showDay) { if (!$showDay) {
//if no show day object was found it is because a new //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(); $showDay = new CcShowDays();
} }
if (isset($keepDay)) {
$day = $keepDay;
}
} else { } else {
$showDay = new CcShowDays(); $showDay = new CcShowDays();
} }

View File

@ -194,3 +194,7 @@
#history_content .ui-tabs .ui-tabs-panel { #history_content .ui-tabs .ui-tabs-panel {
padding-top: 10px; padding-top: 10px;
} }
div.his-timerange input.error {
background-color: rgba(255,0,0,0.2);
}

View File

@ -14,15 +14,17 @@ $(document).ready(function() {
getDataAndPlot(); getDataAndPlot();
listenerstat_content.find("#his_submit").click(function(){ listenerstat_content.find("#his_submit").click(function(){
startTimestamp = AIRTIME.utilities.fnGetTimestamp(dateStartId, timeStartId); var oRange = AIRTIME.utilities.fnGetScheduleRange(dateStartId, timeStartId, dateEndId, timeEndId);
endTimestamp = AIRTIME.utilities.fnGetTimestamp(dateEndId, timeEndId); var start = oRange.start;
getDataAndPlot(startTimestamp, endTimestamp); var end = oRange.end;
getDataAndPlot(start, end);
}); });
}); });
function getDataAndPlot(startTimestamp, endTimestamp){ function getDataAndPlot(startTimestamp, endTimestamp){
// get data // get data
$.get(baseUrl+'Listenerstat/get-data', {startTimestamp: startTimestamp, endTimestamp: endTimestamp}, function(data){ $.get(baseUrl+'Listenerstat/get-data', {start: startTimestamp, end: endTimestamp}, function(data){
out = new Object(); out = new Object();
$.each(data, function(mpName, v){ $.each(data, function(mpName, v){
plotData = new Object(); plotData = new Object();

View File

@ -60,6 +60,30 @@ var AIRTIME = (function(AIRTIME) {
oTableShow, oTableShow,
inShowsTab = false; inShowsTab = false;
function validateTimeRange() {
var oRange,
inputs = $('.his-timerange > input'),
start, end;
oRange = AIRTIME.utilities.fnGetScheduleRange(dateStartId, timeStartId, dateEndId, timeEndId);
start = oRange.start;
end = oRange.end;
if (end >= start) {
inputs.removeClass('error');
}
else {
inputs.addClass('error');
}
return {
start: start,
end: end,
isValid: end >= start
};
}
function getSelectedLogItems() { function getSelectedLogItems() {
var items = Object.keys(selectedLogItems); var items = Object.keys(selectedLogItems);
@ -401,13 +425,12 @@ var AIRTIME = (function(AIRTIME) {
return oTable; return oTable;
} }
function showSummaryList() { function showSummaryList(start, end) {
var url = baseUrl+"playouthistory/show-history-feed", var url = baseUrl+"playouthistory/show-history-feed",
oRange = AIRTIME.utilities.fnGetScheduleRange(dateStartId, timeStartId, dateEndId, timeEndId),
data = { data = {
format: "json", format: "json",
start: oRange.start, start: start,
end: oRange.end end: end
}; };
$.post(url, data, function(json) { $.post(url, data, function(json) {
@ -460,7 +483,9 @@ var AIRTIME = (function(AIRTIME) {
}, },
always: function() { always: function() {
inShowsTab = true; inShowsTab = true;
showSummaryList();
var info = getStartEnd();
showSummaryList(info.start, info.end);
emptySelectedLogItems(); emptySelectedLogItems();
} }
} }
@ -544,7 +569,8 @@ var AIRTIME = (function(AIRTIME) {
dayNamesMin: i18n_days_short, dayNamesMin: i18n_days_short,
onSelect: function(sDate, oDatePicker) { onSelect: function(sDate, oDatePicker) {
$(this).datepicker( "setDate", sDate ); $(this).datepicker( "setDate", sDate );
} },
onClose: validateTimeRange
}; };
oBaseTimePickerSettings = { oBaseTimePickerSettings = {
@ -554,13 +580,25 @@ var AIRTIME = (function(AIRTIME) {
showLeadingZero: false, showLeadingZero: false,
defaultTime: '0:00', defaultTime: '0:00',
hourText: $.i18n._("Hour"), hourText: $.i18n._("Hour"),
minuteText: $.i18n._("Minute") minuteText: $.i18n._("Minute"),
onClose: validateTimeRange
}; };
$historyContentDiv.find(dateStartId).datepicker(oBaseDatePickerSettings); $historyContentDiv.find(dateStartId)
$historyContentDiv.find(timeStartId).timepicker(oBaseTimePickerSettings); .datepicker(oBaseDatePickerSettings)
$historyContentDiv.find(dateEndId).datepicker(oBaseDatePickerSettings); .blur(validateTimeRange);
$historyContentDiv.find(timeEndId).timepicker(oBaseTimePickerSettings);
$historyContentDiv.find(timeStartId)
.timepicker(oBaseTimePickerSettings)
.blur(validateTimeRange);
$historyContentDiv.find(dateEndId)
.datepicker(oBaseDatePickerSettings)
.blur(validateTimeRange);
$historyContentDiv.find(timeEndId)
.timepicker(oBaseTimePickerSettings)
.blur(validateTimeRange);
$historyContentDiv.on("click", "#his_create", function(e) { $historyContentDiv.on("click", "#his_create", function(e) {
var url = baseUrl+"playouthistory/edit-list-item/format/json" ; var url = baseUrl+"playouthistory/edit-list-item/format/json" ;
@ -665,17 +703,16 @@ var AIRTIME = (function(AIRTIME) {
}); });
$('body').on("click", "#his_instance_retrieve", function(e) { $('body').on("click", "#his_instance_retrieve", function(e) {
var startPicker = $hisDialogEl.find('#his_item_starts_datetimepicker').data('datetimepicker'), var startPicker = $hisDialogEl.find('#his_item_starts'),
endPicker = $hisDialogEl.find('#his_item_ends_datetimepicker').data('datetimepicker'), endPicker = $hisDialogEl.find('#his_item_ends'),
url = baseUrl+"playouthistory/show-history-feed", url = baseUrl+"playouthistory/show-history-feed",
startDate = startPicker.getLocalDate(), startDate = startPicker.val(),
endDate = endPicker.getLocalDate(), endDate = endPicker.val(),
getEpochSeconds = AIRTIME.utilities.fnGetSecondsEpoch,
data; data;
data = { data = {
start: getEpochSeconds(startDate), start: startDate,
end: getEpochSeconds(endDate), end: endDate,
format: "json" format: "json"
}; };
@ -710,18 +747,23 @@ var AIRTIME = (function(AIRTIME) {
}); });
}); });
function getStartEnd() {
return AIRTIME.utilities.fnGetScheduleRange(dateStartId, timeStartId, dateEndId, timeEndId);
}
$historyContentDiv.find("#his_submit").click(function(ev){ $historyContentDiv.find("#his_submit").click(function(ev){
var fn, var fn,
oRange; info;
oRange = AIRTIME.utilities.fnGetScheduleRange(dateStartId, timeStartId, dateEndId, timeEndId); info = getStartEnd();
fn = fnServerData; fn = fnServerData;
fn.start = oRange.start; fn.start = info.start;
fn.end = oRange.end; fn.end = info.end;
if (inShowsTab) { if (inShowsTab) {
showSummaryList(); showSummaryList(info.start, info.end);
} }
else { else {
redrawTables(); redrawTables();

View File

@ -46,7 +46,8 @@ AIRTIME = (function(AIRTIME) {
showLeadingZero: false, showLeadingZero: false,
defaultTime: '0:00', defaultTime: '0:00',
hourText: $.i18n._("Hour"), hourText: $.i18n._("Hour"),
minuteText: $.i18n._("Minute") minuteText: $.i18n._("Minute"),
onClose: validateTimeRange
}; };
function setWidgetSize() { function setWidgetSize() {

View File

@ -35,75 +35,39 @@ var AIRTIME = (function(AIRTIME){
}; };
}; };
mod.fnGetSecondsEpoch = function(oDate) {
var iTime,
iUserOffset,
iClientOffset;
iTime = oDate.getTime(); //value is in millisec.
iTime = Math.round(iTime / 1000);
iUserOffset = userTimezoneOffset;
iClientOffset = oDate.getTimezoneOffset() * -60;//function returns minutes
//adjust for the fact the the Date object is in client time.
iTime = iTime + iClientOffset + iUserOffset;
return iTime;
};
/*
* Get the schedule range start in unix timestamp form (in seconds).
* defaults to NOW if nothing is selected.
*
* @param String sDatePickerId
*
* @param String sTimePickerId
*
* @return Number iTime
*/
mod.fnGetTimestamp = function(sDateId, sTimeId) {
var date,
time,
temp;
temp = $(sDateId).val();
if ( temp === "") {
return 0;
}
else {
date = temp;
}
time = $(sTimeId).val();
date = date.split("-");
time = time.split(":");
//0 based month in js.
oDate = new Date(date[0], date[1]-1, date[2], time[0], time[1]);
return mod.fnGetSecondsEpoch(oDate);
};
/* /*
* Returns an object containing a unix timestamp in seconds for the start/end range * Returns an object containing a unix timestamp in seconds for the start/end range
* *
* @return Object {"start", "end", "range"} * @return Object {"start", "end", "range"}
*/ */
mod.fnGetScheduleRange = function(dateStart, timeStart, dateEnd, timeEnd) { mod.fnGetScheduleRange = function(dateStartId, timeStartId, dateEndId, timeEndId) {
var iStart, var start,
iEnd, end,
iRange; time;
iStart = AIRTIME.utilities.fnGetTimestamp(dateStart, timeStart); start = $(dateStartId).val();
iEnd = AIRTIME.utilities.fnGetTimestamp(dateEnd, timeEnd); start = start === "" ? null : start;
iRange = iEnd - iStart; time = $(timeStartId).val();
time = time === "" ? "00:00" : time;
if (start) {
start = start + " " + time;
}
end = $(dateEndId).val();
end = end === "" ? null : end;
time = $(timeEndId).val();
time = time === "" ? "00:00" : time;
if (end) {
end = end + " " + time;
}
return { return {
start: iStart, start: start,
end: iEnd, end: end
range: iRange
}; };
}; };

View File

@ -611,7 +611,7 @@ class ShowServiceDbTest extends Zend_Test_PHPUnit_DatabaseTestCase
$data = ShowServiceData::getWeeklyRepeatNoEndNoRRData(); $data = ShowServiceData::getWeeklyRepeatNoEndNoRRData();
$data["add_show_start_date"] = "2016-01-29"; $data["add_show_start_date"] = "2016-01-29";
$data["add_show_day_check"] = array(5); $data["add_show_day_check"] = array(5, 6);
$data["add_show_linked"] = 1; $data["add_show_linked"] = 1;
$showService = new Application_Service_ShowService(null, $data); $showService = new Application_Service_ShowService(null, $data);
$showService->addUpdateShow($data); $showService->addUpdateShow($data);
@ -661,4 +661,69 @@ class ShowServiceDbTest extends Zend_Test_PHPUnit_DatabaseTestCase
$ds $ds
); );
} }
public function testChangeRepeatTypeFromWeeklyToNoRepeat()
{
TestHelper::loginUser();
//test change repeat type from weekly to no-repeat
$data = ShowServiceData::getWeeklyRepeatNoEndNoRRData();
$showService = new Application_Service_ShowService(null, $data);
$showService->addUpdateShow($data);
$data["add_show_repeats"] = 0;
$data["add_show_id"] = 1;
$showService = new Application_Service_ShowService(null, $data, true);
$showService->addUpdateShow($data);
$ds = new Zend_Test_PHPUnit_Db_DataSet_QueryDataSet(
$this->getConnection()
);
$ds->addTable('cc_show', 'select * from cc_show');
$ds->addTable('cc_show_days', 'select * from cc_show_days');
$ds->addTable('cc_show_instances', 'select id, starts, ends, show_id, record, rebroadcast, instance_id, modified_instance from cc_show_instances');
$ds->addTable('cc_show_rebroadcast', 'select * from cc_show_rebroadcast');
$ds->addTable('cc_show_hosts', 'select * from cc_show_hosts');
$this->assertDataSetsEqual(
$this->createXmlDataSet(dirname(__FILE__)."/datasets/test_createNoRepeatNoRRShow.xml"),
$ds
);
}
public function testChangeRepeatTypeFromWeeklyToBiWeekly()
{
TestHelper::loginUser();
//test change repeat type weekly to bi-weekly
$data = ShowServiceData::getWeeklyRepeatNoEndNoRRData();
$showService = new Application_Service_ShowService(null, $data);
$showService->addUpdateShow($data);
$data["add_show_id"] = 1;
$data["add_show_repeat_type"] = 1;
$showService = new Application_Service_ShowService(null, $data, true);
$showService->addUpdateShow($data);
$ds = new Zend_Test_PHPUnit_Db_DataSet_QueryDataSet(
$this->getConnection()
);
$ds->addTable('cc_show', 'select * from cc_show');
$ds->addTable('cc_show_days', 'select * from cc_show_days');
$ds->addTable('cc_show_instances', 'select id, starts, ends, show_id, record, rebroadcast, instance_id, modified_instance from cc_show_instances');
$ds->addTable('cc_show_rebroadcast', 'select * from cc_show_rebroadcast');
$ds->addTable('cc_show_hosts', 'select * from cc_show_hosts');
$this->assertDataSetsEqual(
$this->createXmlDataSet(dirname(__FILE__)."/datasets/test_weeklyToBiWeekly.xml"),
$ds
);
}
public function testChangeRepeatTypeFromMonthlyWeeklyToNoRepeat()
{
}
} }

View File

@ -0,0 +1,107 @@
<?xml version="1.0" ?>
<dataset>
<table name="cc_show">
<column>id</column>
<column>name</column>
<column>url</column>
<column>genre</column>
<column>description</column>
<column>color</column>
<column>background_color</column>
<column>live_stream_using_airtime_auth</column>
<column>live_stream_using_custom_auth</column>
<column>live_stream_user</column>
<column>live_stream_pass</column>
<column>linked</column>
<column>is_linkable</column>
<row>
<value>1</value>
<value>test show</value>
<null />
<null />
<null />
<value>ffffff</value>
<value>364492</value>
<value></value>
<value></value>
<null />
<null />
<value></value>
<value>1</value>
</row>
</table>
<table name="cc_show_days">
<column>id</column>
<column>first_show</column>
<column>last_show</column>
<column>start_time</column>
<column>timezone</column>
<column>duration</column>
<column>day</column>
<column>repeat_type</column>
<column>next_pop_date</column>
<column>show_id</column>
<column>record</column>
<row>
<value>2</value>
<value>2016-01-01</value>
<null />
<value>00:00:00</value>
<value>UTC</value>
<value>01:00</value>
<value>5</value>
<value>1</value>
<value>2016-02-12</value>
<value>1</value>
<value>0</value>
</row>
</table>
<table name="cc_show_instances">
<column>id</column>
<column>starts</column>
<column>ends</column>
<column>show_id</column>
<column>record</column>
<column>rebroadcast</column>
<column>instance_id</column>
<column>modified_instance</column>
<row>
<value>7</value>
<value>2016-01-01 00:00:00</value>
<value>2016-01-01 01:00:00</value>
<value>1</value>
<value>0</value>
<value>0</value>
<null />
<value></value>
</row>
<row>
<value>8</value>
<value>2016-01-15 00:00:00</value>
<value>2016-01-15 01:00:00</value>
<value>1</value>
<value>0</value>
<value>0</value>
<null />
<value></value>
</row>
<row>
<value>9</value>
<value>2016-01-29 00:00:00</value>
<value>2016-01-29 01:00:00</value>
<value>1</value>
<value>0</value>
<value>0</value>
<null />
<value></value>
</row>
</table>
<table name="cc_show_rebroadcast">
</table>
<table name="cc_show_hosts">
</table>
</dataset>