From ebc68b980c55c617f711fa30f467418effa08b78 Mon Sep 17 00:00:00 2001 From: drigato Date: Wed, 5 Mar 2014 13:12:27 -0500 Subject: [PATCH 01/15] CC-5718: Show content can get scheduled in instances that are in the past Disabled scheduled content into instances that have already played out Removed setting the show's start date to the first repeating instance's start date because we already fixed that in CC-5697 --- airtime_mvc/application/models/Scheduler.php | 15 ++++++++------- airtime_mvc/application/services/ShowService.php | 5 +++-- .../application/models/unit/ScheduleUnitTest.php | 4 ++-- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/airtime_mvc/application/models/Scheduler.php b/airtime_mvc/application/models/Scheduler.php index 4af3efd5c..7923889fb 100644 --- a/airtime_mvc/application/models/Scheduler.php +++ b/airtime_mvc/application/models/Scheduler.php @@ -590,10 +590,10 @@ 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"]; @@ -606,7 +606,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 +633,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 +659,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 diff --git a/airtime_mvc/application/services/ShowService.php b/airtime_mvc/application/services/ShowService.php index 5fdaf4f19..e3bec88bf 100644 --- a/airtime_mvc/application/services/ShowService.php +++ b/airtime_mvc/application/services/ShowService.php @@ -183,6 +183,7 @@ class Application_Service_ShowService if (!$currentUser->isAdminOrPM()) { throw new Exception("Permission denied"); } + //update ccShow $this->setCcShow($showData); @@ -224,8 +225,8 @@ class Application_Service_ShowService * We need to do this so we get the correct time diff for * updating show content. CC-5696 */ - $showData["add_show_start_date"] = $this->ccShow->getFirstCcShowDay()->getDbFirstShow(); - $showData["add_show_start_time"] = $this->ccShow->getFirstCcShowDay()->getDbStartTime(); + //$showData["add_show_start_date"] = $this->ccShow->getFirstCcShowDay()->getDbFirstShow(); + //$showData["add_show_start_time"] = $this->ccShow->getFirstCcShowDay()->getDbStartTime(); $this->adjustSchedule($showData); } diff --git a/airtime_mvc/tests/application/models/unit/ScheduleUnitTest.php b/airtime_mvc/tests/application/models/unit/ScheduleUnitTest.php index 63bc8b283..d645b545e 100644 --- a/airtime_mvc/tests/application/models/unit/ScheduleUnitTest.php +++ b/airtime_mvc/tests/application/models/unit/ScheduleUnitTest.php @@ -22,7 +22,7 @@ class ScheduleUnitTest extends Zend_Test_PHPUnit_ControllerTestCase //PHPUnit_Fr } - public function testIsFileScheduledInTheFuture() + /*public function testIsFileScheduledInTheFuture() { TestHelper::loginUser(); $CC_CONFIG = Config::getConfig(); @@ -92,6 +92,6 @@ class ScheduleUnitTest extends Zend_Test_PHPUnit_ControllerTestCase //PHPUnit_Fr //Test the function we actually want to test. :-) $this->assertEquals($scheduleModel->IsFileScheduledInTheFuture($fileId), true); - } + }*/ } From 426b75b63570c31b0edaf5f01c75a31c9984fc3e Mon Sep 17 00:00:00 2001 From: drigato Date: Wed, 5 Mar 2014 14:37:07 -0500 Subject: [PATCH 02/15] CC-5724: Changing start date of a repeating show will update content incorrectly --- airtime_mvc/application/services/ShowService.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/airtime_mvc/application/services/ShowService.php b/airtime_mvc/application/services/ShowService.php index e3bec88bf..d03820a53 100644 --- a/airtime_mvc/application/services/ShowService.php +++ b/airtime_mvc/application/services/ShowService.php @@ -221,12 +221,15 @@ class Application_Service_ShowService $this->delegateInstanceCreation($daysAdded); 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 - * updating show content. CC-5696 + + /* 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. */ - //$showData["add_show_start_date"] = $this->ccShow->getFirstCcShowDay()->getDbFirstShow(); - //$showData["add_show_start_time"] = $this->ccShow->getFirstCcShowDay()->getDbStartTime(); + 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); } From bcda9ea5e6857faaae768b963446be6fc5cbcc27 Mon Sep 17 00:00:00 2001 From: drigato Date: Wed, 5 Mar 2014 14:50:35 -0500 Subject: [PATCH 03/15] Broke unit test for adding content to single show --- airtime_mvc/application/models/Scheduler.php | 7 +++---- .../tests/application/models/unit/ScheduleUnitTest.php | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/airtime_mvc/application/models/Scheduler.php b/airtime_mvc/application/models/Scheduler.php index 7923889fb..85e8f6f24 100644 --- a/airtime_mvc/application/models/Scheduler.php +++ b/airtime_mvc/application/models/Scheduler.php @@ -595,10 +595,9 @@ class Application_Model_Scheduler ->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(); diff --git a/airtime_mvc/tests/application/models/unit/ScheduleUnitTest.php b/airtime_mvc/tests/application/models/unit/ScheduleUnitTest.php index d645b545e..63bc8b283 100644 --- a/airtime_mvc/tests/application/models/unit/ScheduleUnitTest.php +++ b/airtime_mvc/tests/application/models/unit/ScheduleUnitTest.php @@ -22,7 +22,7 @@ class ScheduleUnitTest extends Zend_Test_PHPUnit_ControllerTestCase //PHPUnit_Fr } - /*public function testIsFileScheduledInTheFuture() + public function testIsFileScheduledInTheFuture() { TestHelper::loginUser(); $CC_CONFIG = Config::getConfig(); @@ -92,6 +92,6 @@ class ScheduleUnitTest extends Zend_Test_PHPUnit_ControllerTestCase //PHPUnit_Fr //Test the function we actually want to test. :-) $this->assertEquals($scheduleModel->IsFileScheduledInTheFuture($fileId), true); - }*/ + } } From 51b5cc205237e719e4d75176f3b12e178bc1d774 Mon Sep 17 00:00:00 2001 From: drigato Date: Thu, 6 Mar 2014 10:54:40 -0500 Subject: [PATCH 04/15] CC-5725: Changing a show's repeat type removes first instance from repeating series --- airtime_mvc/application/services/ShowService.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/airtime_mvc/application/services/ShowService.php b/airtime_mvc/application/services/ShowService.php index d03820a53..379a3f526 100644 --- a/airtime_mvc/application/services/ShowService.php +++ b/airtime_mvc/application/services/ShowService.php @@ -1547,8 +1547,8 @@ SQL; if ($this->isUpdate) { $showDay = CcShowDaysQuery::create() ->filterByDbShowId($showId) - ->filterByDbRepeatType($this->repeatType) - ->filterByDbDay($day) + ->filterByDbRepeatType($this->origCcShowDay->getDbRepeatType()) + ->filterByDbDay($this->origCcShowDay->getDbDay()) ->findOne(); if (!$showDay) { //if no show day object was found it is because a new From 35fd639c1c8c2740738e9b142de159b1b4591c75 Mon Sep 17 00:00:00 2001 From: drigato Date: Thu, 6 Mar 2014 11:18:13 -0500 Subject: [PATCH 05/15] CC-5725: Changing a show's repeat type removes first instance from repeating series --- .../application/services/ShowService.php | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/airtime_mvc/application/services/ShowService.php b/airtime_mvc/application/services/ShowService.php index 379a3f526..e004e07bf 100644 --- a/airtime_mvc/application/services/ShowService.php +++ b/airtime_mvc/application/services/ShowService.php @@ -1545,15 +1545,23 @@ SQL; if (is_null($endDate) || $startDateTimeClone->getTimestamp() <= $endDateTime->getTimestamp()) { if ($this->isUpdate) { - $showDay = CcShowDaysQuery::create() - ->filterByDbShowId($showId) - ->filterByDbRepeatType($this->origCcShowDay->getDbRepeatType()) - ->filterByDbDay($this->origCcShowDay->getDbDay()) - ->findOne(); - if (!$showDay) { - //if no show day object was found it is because a new - //repeating day of the week was added - $showDay = new CcShowDays(); + if ($this->repeatType >= 0) { + $showDay = CcShowDaysQuery::create() + ->filterByDbShowId($showId) + ->filterByDbRepeatType($this->repeatType) + ->filterByDbDay($day) + ->findOne(); + if (!$showDay) { + //if no show day object was found it is because a new + //repeating day of the week was added + $showDay = new CcShowDays(); + } + } else { + $showDay = CcShowDaysQuery::create() + ->filterByDbShowId($showId) + ->filterByDbRepeatType($this->origCcShowDay->getDbRepeatType()) + ->filterByDbDay($this->origCcShowDay->getDbDay()) + ->findOne(); } } else { $showDay = new CcShowDays(); From 6b91d2daf89ee2312db4ad19b298bd91464d34e7 Mon Sep 17 00:00:00 2001 From: drigato Date: Fri, 7 Mar 2014 14:52:32 -0500 Subject: [PATCH 06/15] CC-5725: Changing a show's repeat type removes first instance from repeating series --- .../application/services/ShowService.php | 64 +++++++++++-------- 1 file changed, 39 insertions(+), 25 deletions(-) diff --git a/airtime_mvc/application/services/ShowService.php b/airtime_mvc/application/services/ShowService.php index e004e07bf..f0c547ff5 100644 --- a/airtime_mvc/application/services/ShowService.php +++ b/airtime_mvc/application/services/ShowService.php @@ -415,6 +415,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 * @@ -436,8 +443,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) @@ -446,6 +459,7 @@ SQL; //repeat option was toggled if ($showData['add_show_repeats'] != $currentShowDay->isRepeating()) { $this->deleteAllRepeatInstances($currentShowDay, $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() @@ -477,17 +491,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(); @@ -560,11 +570,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(); @@ -1512,8 +1525,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(); } @@ -1545,23 +1562,20 @@ SQL; if (is_null($endDate) || $startDateTimeClone->getTimestamp() <= $endDateTime->getTimestamp()) { if ($this->isUpdate) { - if ($this->repeatType >= 0) { - $showDay = CcShowDaysQuery::create() - ->filterByDbShowId($showId) - ->filterByDbRepeatType($this->repeatType) - ->filterByDbDay($day) - ->findOne(); - if (!$showDay) { - //if no show day object was found it is because a new - //repeating day of the week was added - $showDay = new CcShowDays(); - } - } else { - $showDay = CcShowDaysQuery::create() - ->filterByDbShowId($showId) - ->filterByDbRepeatType($this->origCcShowDay->getDbRepeatType()) - ->filterByDbDay($this->origCcShowDay->getDbDay()) - ->findOne(); + if ($this->origCcShowDay->getDbRepeatType() == 2 || + $this->origCcShowDay->getDbRepeatType() == 3) { + $day = null; + } + $showDay = CcShowDaysQuery::create() + ->filterByDbShowId($showId) + ->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 OR the repeat + //type has changed + $showDay = new CcShowDays(); } } else { $showDay = new CcShowDays(); From 03bb0e1df93439f9be57ec298b89d458c514328b Mon Sep 17 00:00:00 2001 From: drigato Date: Fri, 7 Mar 2014 15:59:57 -0500 Subject: [PATCH 07/15] CC-5725 Changing a show's repeat type removes first instance from repeating seriesCC-5726: Write database test cases for CC-5725 --- .../services/database/ShowServiceDbTest.php | 65 +++++++++++ .../datasets/test_weeklyToBiWeekly.xml | 107 ++++++++++++++++++ 2 files changed, 172 insertions(+) create mode 100644 airtime_mvc/tests/application/services/database/datasets/test_weeklyToBiWeekly.xml diff --git a/airtime_mvc/tests/application/services/database/ShowServiceDbTest.php b/airtime_mvc/tests/application/services/database/ShowServiceDbTest.php index 576ac7ca1..0531bbbe0 100644 --- a/airtime_mvc/tests/application/services/database/ShowServiceDbTest.php +++ b/airtime_mvc/tests/application/services/database/ShowServiceDbTest.php @@ -661,4 +661,69 @@ class ShowServiceDbTest extends Zend_Test_PHPUnit_DatabaseTestCase $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() + { + + } } diff --git a/airtime_mvc/tests/application/services/database/datasets/test_weeklyToBiWeekly.xml b/airtime_mvc/tests/application/services/database/datasets/test_weeklyToBiWeekly.xml new file mode 100644 index 000000000..9e65db067 --- /dev/null +++ b/airtime_mvc/tests/application/services/database/datasets/test_weeklyToBiWeekly.xml @@ -0,0 +1,107 @@ + + + + id + name + url + genre + description + color + background_color + live_stream_using_airtime_auth + live_stream_using_custom_auth + live_stream_user + live_stream_pass + linked + is_linkable + + 1 + test show + + + + ffffff + 364492 + + + + + + 1 + +
+ + + id + first_show + last_show + start_time + timezone + duration + day + repeat_type + next_pop_date + show_id + record + + 2 + 2016-01-01 + + 00:00:00 + UTC + 01:00 + 5 + 1 + 2016-02-12 + 1 + 0 + +
+ + + id + starts + ends + show_id + record + rebroadcast + instance_id + modified_instance + + 7 + 2016-01-01 00:00:00 + 2016-01-01 01:00:00 + 1 + 0 + 0 + + + + + 8 + 2016-01-15 00:00:00 + 2016-01-15 01:00:00 + 1 + 0 + 0 + + + + + 9 + 2016-01-29 00:00:00 + 2016-01-29 01:00:00 + 1 + 0 + 0 + + + +
+ + +
+ + +
+
\ No newline at end of file From 78d34a6d169b0252b5711d4e7f06a17fb9a43530 Mon Sep 17 00:00:00 2001 From: drigato Date: Mon, 10 Mar 2014 17:31:24 -0400 Subject: [PATCH 08/15] Fixed broken test --- .../tests/application/services/database/ShowServiceDbTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/airtime_mvc/tests/application/services/database/ShowServiceDbTest.php b/airtime_mvc/tests/application/services/database/ShowServiceDbTest.php index 0531bbbe0..0cb424778 100644 --- a/airtime_mvc/tests/application/services/database/ShowServiceDbTest.php +++ b/airtime_mvc/tests/application/services/database/ShowServiceDbTest.php @@ -611,7 +611,7 @@ class ShowServiceDbTest extends Zend_Test_PHPUnit_DatabaseTestCase $data = ShowServiceData::getWeeklyRepeatNoEndNoRRData(); $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; $showService = new Application_Service_ShowService(null, $data); $showService->addUpdateShow($data); From 8ad866c2a258b0bd4b98dd99de540e651cb93fef Mon Sep 17 00:00:00 2001 From: drigato Date: Mon, 10 Mar 2014 17:32:54 -0400 Subject: [PATCH 09/15] Fixed changing the start date on a non-repeating show --- airtime_mvc/application/services/ShowService.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/airtime_mvc/application/services/ShowService.php b/airtime_mvc/application/services/ShowService.php index f0c547ff5..de134f2fa 100644 --- a/airtime_mvc/application/services/ShowService.php +++ b/airtime_mvc/application/services/ShowService.php @@ -20,6 +20,7 @@ class Application_Service_ShowService private $localShowStartHour; private $localShowStartMin; private $origCcShowDay; + private $origShowRepeatStatus; private $instanceIdsForScheduleUpdates; public function __construct($showId=null, $showData=null, $isUpdate=false) @@ -158,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(); @@ -1565,6 +1568,10 @@ SQL; 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) @@ -1577,6 +1584,10 @@ SQL; //type has changed $showDay = new CcShowDays(); } + + if (isset($keepDay)) { + $day = $keepDay; + } } else { $showDay = new CcShowDays(); } From 5f3199b4bb197cf8177fca8456e85c0abc6d3aa9 Mon Sep 17 00:00:00 2001 From: Naomi Date: Mon, 10 Mar 2014 17:39:17 -0400 Subject: [PATCH 10/15] CC-5727 : History search range using incorrect timezone offset --- .../controllers/PlayouthistoryController.php | 84 +++++++++++++------ .../js/airtime/playouthistory/historytable.js | 52 +++++++++--- 2 files changed, 99 insertions(+), 37 deletions(-) diff --git a/airtime_mvc/application/controllers/PlayouthistoryController.php b/airtime_mvc/application/controllers/PlayouthistoryController.php index cbd15517f..a2352f4b7 100644 --- a/airtime_mvc/application/controllers/PlayouthistoryController.php +++ b/airtime_mvc/application/controllers/PlayouthistoryController.php @@ -82,20 +82,58 @@ class PlayouthistoryController extends Zend_Controller_Action $user = Application_Model_User::getCurrentUser(); $this->view->userType = $user->getType(); } + + 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 fileHistoryFeedAction() { 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 +152,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 +176,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); diff --git a/airtime_mvc/public/js/airtime/playouthistory/historytable.js b/airtime_mvc/public/js/airtime/playouthistory/historytable.js index 056de9a30..b5a43e38c 100644 --- a/airtime_mvc/public/js/airtime/playouthistory/historytable.js +++ b/airtime_mvc/public/js/airtime/playouthistory/historytable.js @@ -401,13 +401,12 @@ var AIRTIME = (function(AIRTIME) { return oTable; } - function showSummaryList() { + function showSummaryList(start, end) { var url = baseUrl+"playouthistory/show-history-feed", - oRange = AIRTIME.utilities.fnGetScheduleRange(dateStartId, timeStartId, dateEndId, timeEndId), data = { format: "json", - start: oRange.start, - end: oRange.end + start: start, + end: end }; $.post(url, data, function(json) { @@ -460,7 +459,9 @@ var AIRTIME = (function(AIRTIME) { }, always: function() { inShowsTab = true; - showSummaryList(); + + var info = getStartEnd(); + showSummaryList(info.start, info.end); emptySelectedLogItems(); } } @@ -710,18 +711,49 @@ var AIRTIME = (function(AIRTIME) { }); }); + function getStartEnd() { + var start, + end, + time; + + start = $(dateStartId).val(); + start = start === "" ? null : start; + + 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 { + start: start, + end: end + }; + } + $historyContentDiv.find("#his_submit").click(function(ev){ var fn, - oRange; + info; - oRange = AIRTIME.utilities.fnGetScheduleRange(dateStartId, timeStartId, dateEndId, timeEndId); + info = getStartEnd(); fn = fnServerData; - fn.start = oRange.start; - fn.end = oRange.end; + fn.start = info.start; + fn.end = info.end; if (inShowsTab) { - showSummaryList(); + showSummaryList(info.start, info.end); } else { redrawTables(); From 14c670aa2035949d17587aaface0b8e50df705f0 Mon Sep 17 00:00:00 2001 From: drigato Date: Mon, 10 Mar 2014 17:41:57 -0400 Subject: [PATCH 11/15] CC-5728: Problem when removing repeat option and changing start date --- airtime_mvc/application/services/ShowService.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/airtime_mvc/application/services/ShowService.php b/airtime_mvc/application/services/ShowService.php index de134f2fa..e71ecc568 100644 --- a/airtime_mvc/application/services/ShowService.php +++ b/airtime_mvc/application/services/ShowService.php @@ -463,6 +463,10 @@ SQL; 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() @@ -1573,6 +1577,7 @@ SQL; $keepDay = $day; $day = $this->origCcShowDay->getDbDay(); } + $showDay = CcShowDaysQuery::create() ->filterByDbShowId($showId) ->filterByDbRepeatType($this->origCcShowDay->getDbRepeatType()) From 8d2926aeeda2dcd70e0ccfccfcfa191792326d18 Mon Sep 17 00:00:00 2001 From: Naomi Date: Mon, 10 Mar 2014 18:33:07 -0400 Subject: [PATCH 12/15] CC-5727 : History search range using incorrect timezone offset (also Nowplaying) sending the timestamp string back for nowplaying as well. added error class to history page if end is < start. --- .../controllers/ShowbuilderController.php | 75 +++++++++++++----- airtime_mvc/public/css/history_styles.css | 4 + .../js/airtime/playouthistory/historytable.js | 79 +++++++++++-------- .../js/airtime/showbuilder/main_builder.js | 3 +- .../public/js/airtime/utilities/utilities.js | 34 +++++--- 5 files changed, 129 insertions(+), 66 deletions(-) diff --git a/airtime_mvc/application/controllers/ShowbuilderController.php b/airtime_mvc/application/controllers/ShowbuilderController.php index dd1a19e13..c7de2cdc6 100644 --- a/airtime_mvc/application/controllers/ShowbuilderController.php +++ b/airtime_mvc/application/controllers/ShowbuilderController.php @@ -235,24 +235,61 @@ class ShowbuilderController extends Zend_Controller_Action $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, diff --git a/airtime_mvc/public/css/history_styles.css b/airtime_mvc/public/css/history_styles.css index fb44d4677..2d0c70d58 100644 --- a/airtime_mvc/public/css/history_styles.css +++ b/airtime_mvc/public/css/history_styles.css @@ -194,3 +194,7 @@ #history_content .ui-tabs .ui-tabs-panel { padding-top: 10px; } + +div.his-timerange input.error { + background-color: rgba(255,0,0,0.2); +} diff --git a/airtime_mvc/public/js/airtime/playouthistory/historytable.js b/airtime_mvc/public/js/airtime/playouthistory/historytable.js index b5a43e38c..854b0dfc4 100644 --- a/airtime_mvc/public/js/airtime/playouthistory/historytable.js +++ b/airtime_mvc/public/js/airtime/playouthistory/historytable.js @@ -60,6 +60,30 @@ var AIRTIME = (function(AIRTIME) { oTableShow, 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() { var items = Object.keys(selectedLogItems); @@ -545,7 +569,8 @@ var AIRTIME = (function(AIRTIME) { dayNamesMin: i18n_days_short, onSelect: function(sDate, oDatePicker) { $(this).datepicker( "setDate", sDate ); - } + }, + onClose: validateTimeRange }; oBaseTimePickerSettings = { @@ -555,13 +580,25 @@ var AIRTIME = (function(AIRTIME) { showLeadingZero: false, defaultTime: '0:00', hourText: $.i18n._("Hour"), - minuteText: $.i18n._("Minute") + minuteText: $.i18n._("Minute"), + onClose: validateTimeRange }; - $historyContentDiv.find(dateStartId).datepicker(oBaseDatePickerSettings); - $historyContentDiv.find(timeStartId).timepicker(oBaseTimePickerSettings); - $historyContentDiv.find(dateEndId).datepicker(oBaseDatePickerSettings); - $historyContentDiv.find(timeEndId).timepicker(oBaseTimePickerSettings); + $historyContentDiv.find(dateStartId) + .datepicker(oBaseDatePickerSettings) + .blur(validateTimeRange); + + $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) { var url = baseUrl+"playouthistory/edit-list-item/format/json" ; @@ -711,35 +748,9 @@ var AIRTIME = (function(AIRTIME) { }); }); - function getStartEnd() { - var start, - end, - time; + function getStartEnd() { - start = $(dateStartId).val(); - start = start === "" ? null : start; - - 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 { - start: start, - end: end - }; + return AIRTIME.utilities.fnGetScheduleRange(dateStartId, timeStartId, dateEndId, timeEndId); } $historyContentDiv.find("#his_submit").click(function(ev){ diff --git a/airtime_mvc/public/js/airtime/showbuilder/main_builder.js b/airtime_mvc/public/js/airtime/showbuilder/main_builder.js index f59d0f32a..625464bb0 100644 --- a/airtime_mvc/public/js/airtime/showbuilder/main_builder.js +++ b/airtime_mvc/public/js/airtime/showbuilder/main_builder.js @@ -46,7 +46,8 @@ AIRTIME = (function(AIRTIME) { showLeadingZero: false, defaultTime: '0:00', hourText: $.i18n._("Hour"), - minuteText: $.i18n._("Minute") + minuteText: $.i18n._("Minute"), + onClose: validateTimeRange }; function setWidgetSize() { diff --git a/airtime_mvc/public/js/airtime/utilities/utilities.js b/airtime_mvc/public/js/airtime/utilities/utilities.js index 148f81fb1..4084e0e3b 100644 --- a/airtime_mvc/public/js/airtime/utilities/utilities.js +++ b/airtime_mvc/public/js/airtime/utilities/utilities.js @@ -90,20 +90,34 @@ var AIRTIME = (function(AIRTIME){ * * @return Object {"start", "end", "range"} */ - mod.fnGetScheduleRange = function(dateStart, timeStart, dateEnd, timeEnd) { - var iStart, - iEnd, - iRange; + mod.fnGetScheduleRange = function(dateStartId, timeStartId, dateEndId, timeEndId) { + var start, + end, + time; - iStart = AIRTIME.utilities.fnGetTimestamp(dateStart, timeStart); - iEnd = AIRTIME.utilities.fnGetTimestamp(dateEnd, timeEnd); + start = $(dateStartId).val(); + 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 { - start: iStart, - end: iEnd, - range: iRange + start: start, + end: end }; }; From cd55ed5ee49d3f5d4544339c79c80d0c546d7850 Mon Sep 17 00:00:00 2001 From: Naomi Date: Mon, 10 Mar 2014 18:48:40 -0400 Subject: [PATCH 13/15] CC-5727 : History search range using incorrect timezone offset fixing show fetching times. --- .../js/airtime/playouthistory/historytable.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/airtime_mvc/public/js/airtime/playouthistory/historytable.js b/airtime_mvc/public/js/airtime/playouthistory/historytable.js index 854b0dfc4..bb1547e65 100644 --- a/airtime_mvc/public/js/airtime/playouthistory/historytable.js +++ b/airtime_mvc/public/js/airtime/playouthistory/historytable.js @@ -703,17 +703,16 @@ var AIRTIME = (function(AIRTIME) { }); $('body').on("click", "#his_instance_retrieve", function(e) { - var startPicker = $hisDialogEl.find('#his_item_starts_datetimepicker').data('datetimepicker'), - endPicker = $hisDialogEl.find('#his_item_ends_datetimepicker').data('datetimepicker'), + var startPicker = $hisDialogEl.find('#his_item_starts'), + endPicker = $hisDialogEl.find('#his_item_ends'), url = baseUrl+"playouthistory/show-history-feed", - startDate = startPicker.getLocalDate(), - endDate = endPicker.getLocalDate(), - getEpochSeconds = AIRTIME.utilities.fnGetSecondsEpoch, + startDate = startPicker.val(), + endDate = endPicker.val(), data; data = { - start: getEpochSeconds(startDate), - end: getEpochSeconds(endDate), + start: startDate, + end: endDate, format: "json" }; From f8935a312fbe962b7a108e210af2917223f64d1f Mon Sep 17 00:00:00 2001 From: Naomi Date: Tue, 11 Mar 2014 13:24:22 -0400 Subject: [PATCH 14/15] CC-5727 : History search range using incorrect timezone offset (also Nowplaying & Listener Stats) fixing listener stat search --- .../controllers/ListenerstatController.php | 80 ++++++++---- .../controllers/PlayouthistoryController.php | 116 ++++++++---------- .../js/airtime/listenerstat/listenerstat.js | 10 +- 3 files changed, 112 insertions(+), 94 deletions(-) diff --git a/airtime_mvc/application/controllers/ListenerstatController.php b/airtime_mvc/application/controllers/ListenerstatController.php index 178aec631..5f5250b9c 100644 --- a/airtime_mvc/application/controllers/ListenerstatController.php +++ b/airtime_mvc/application/controllers/ListenerstatController.php @@ -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); } diff --git a/airtime_mvc/application/controllers/PlayouthistoryController.php b/airtime_mvc/application/controllers/PlayouthistoryController.php index a2352f4b7..077cce0b2 100644 --- a/airtime_mvc/application/controllers/PlayouthistoryController.php +++ b/airtime_mvc/application/controllers/PlayouthistoryController.php @@ -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; @@ -82,49 +115,6 @@ class PlayouthistoryController extends Zend_Controller_Action $user = Application_Model_User::getCurrentUser(); $this->view->userType = $user->getType(); } - - 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 fileHistoryFeedAction() { diff --git a/airtime_mvc/public/js/airtime/listenerstat/listenerstat.js b/airtime_mvc/public/js/airtime/listenerstat/listenerstat.js index bebfd1471..3c1cfc9df 100644 --- a/airtime_mvc/public/js/airtime/listenerstat/listenerstat.js +++ b/airtime_mvc/public/js/airtime/listenerstat/listenerstat.js @@ -14,15 +14,17 @@ $(document).ready(function() { getDataAndPlot(); listenerstat_content.find("#his_submit").click(function(){ - startTimestamp = AIRTIME.utilities.fnGetTimestamp(dateStartId, timeStartId); - endTimestamp = AIRTIME.utilities.fnGetTimestamp(dateEndId, timeEndId); - getDataAndPlot(startTimestamp, endTimestamp); + var oRange = AIRTIME.utilities.fnGetScheduleRange(dateStartId, timeStartId, dateEndId, timeEndId); + var start = oRange.start; + var end = oRange.end; + + getDataAndPlot(start, end); }); }); function getDataAndPlot(startTimestamp, endTimestamp){ // 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(); $.each(data, function(mpName, v){ plotData = new Object(); From 7078180da0e59121616b866aacccc4be4a447ec9 Mon Sep 17 00:00:00 2001 From: Naomi Date: Tue, 11 Mar 2014 13:26:05 -0400 Subject: [PATCH 15/15] CC-5727 : History search range using incorrect timezone offset (also Nowplaying & Listener Stats) removing flawed functions. --- .../public/js/airtime/utilities/utilities.js | 50 ------------------- 1 file changed, 50 deletions(-) diff --git a/airtime_mvc/public/js/airtime/utilities/utilities.js b/airtime_mvc/public/js/airtime/utilities/utilities.js index 4084e0e3b..bddba5b7d 100644 --- a/airtime_mvc/public/js/airtime/utilities/utilities.js +++ b/airtime_mvc/public/js/airtime/utilities/utilities.js @@ -35,56 +35,6 @@ 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 *