From 429cdeeffbb181cb88567147014769d309f721ce Mon Sep 17 00:00:00 2001 From: Naomi Date: Wed, 28 Aug 2013 19:37:46 -0400 Subject: [PATCH] filtering by a host's show so they can edit their own playout history. --- airtime_mvc/application/configs/constants.php | 6 +- .../controllers/PlayouthistoryController.php | 39 +-- .../PlayouthistorytemplateController.php | 252 +++++++++--------- .../application/services/HistoryService.php | 40 ++- .../views/scripts/playouthistory/index.phtml | 4 +- .../js/airtime/playouthistory/historytable.js | 33 ++- 6 files changed, 218 insertions(+), 156 deletions(-) diff --git a/airtime_mvc/application/configs/constants.php b/airtime_mvc/application/configs/constants.php index 4b4d9634a..34f8cab41 100644 --- a/airtime_mvc/application/configs/constants.php +++ b/airtime_mvc/application/configs/constants.php @@ -39,9 +39,9 @@ define('UI_MDATA_VALUE_FORMAT_FILE' , 'File'); define('UI_MDATA_VALUE_FORMAT_STREAM' , 'live stream'); //User types -define('UTYPE_HOST' , 'H'); -define('UTYPE_ADMIN' , 'A'); -define('UTYPE_GUEST' , 'G'); +define('UTYPE_HOST' , 'H'); +define('UTYPE_ADMIN' , 'A'); +define('UTYPE_GUEST' , 'G'); define('UTYPE_PROGRAM_MANAGER' , 'P'); //Constants for playout history template fields diff --git a/airtime_mvc/application/controllers/PlayouthistoryController.php b/airtime_mvc/application/controllers/PlayouthistoryController.php index 29997e17e..89a2e2f4a 100644 --- a/airtime_mvc/application/controllers/PlayouthistoryController.php +++ b/airtime_mvc/application/controllers/PlayouthistoryController.php @@ -138,25 +138,26 @@ class PlayouthistoryController extends Zend_Controller_Action } } - public function showHistoryFeedAction() - { - 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")); - - $historyService = new Application_Service_HistoryService(); - $r = $historyService->getShowList($startsDT, $endsDT); - - } - catch (Exception $e) { - Logging::info($e); - Logging::info($e->getMessage()); - } + public function showHistoryFeedAction() + { + 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")); + + $historyService = new Application_Service_HistoryService(); + $shows = $historyService->getShowList($startsDT, $endsDT); + + $this->_helper->json->sendJson($shows); + } + catch (Exception $e) { + Logging::info($e); + Logging::info($e->getMessage()); + } } public function editFileItemAction() diff --git a/airtime_mvc/application/controllers/PlayouthistorytemplateController.php b/airtime_mvc/application/controllers/PlayouthistorytemplateController.php index 00f4cbedc..c6651d8eb 100644 --- a/airtime_mvc/application/controllers/PlayouthistorytemplateController.php +++ b/airtime_mvc/application/controllers/PlayouthistorytemplateController.php @@ -13,131 +13,131 @@ class PlayouthistorytemplateController extends Zend_Controller_Action ->initContext(); } - public function indexAction() - { - $CC_CONFIG = Config::getConfig(); - $baseUrl = Application_Common_OsPath::getBaseDir(); - - $this->view->headScript()->appendFile($baseUrl.'js/airtime/playouthistory/template.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); - $this->view->headLink()->appendStylesheet($baseUrl.'css/history_styles.css?'.$CC_CONFIG['airtime_version']); - - $historyService = new Application_Service_HistoryService(); - $this->view->template_list = $historyService->getListItemTemplates(); - $this->view->template_file = $historyService->getFileTemplates(); - $this->view->configured = $historyService->getConfiguredTemplateIds(); - } - - public function configureTemplateAction() { - - $CC_CONFIG = Config::getConfig(); - $baseUrl = Application_Common_OsPath::getBaseDir(); - - $this->view->headScript()->appendFile($baseUrl.'js/airtime/playouthistory/configuretemplate.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); - $this->view->headLink()->appendStylesheet($baseUrl.'css/history_styles.css?'.$CC_CONFIG['airtime_version']); - - try { - - $templateId = $this->_getParam('id'); - - $historyService = new Application_Service_HistoryService(); - $template = $historyService->loadTemplate($templateId); - - $templateType = $template["type"]; - $supportedTypes = $historyService->getSupportedTemplateTypes(); - - if (!in_array($templateType, $supportedTypes)) { - throw new Exception("Error: $templateType is not supported."); - } - - $getMandatoryFields = "mandatory".ucfirst($templateType)."Fields"; - $mandatoryFields = $historyService->$getMandatoryFields(); - - $this->view->template_id = $templateId; - $this->view->template_name = $template["name"]; - $this->view->template_fields = $template["fields"]; - $this->view->template_type = $templateType; - $this->view->fileMD = $historyService->getFileMetadataTypes(); - $this->view->fields = $historyService->getFieldTypes(); - $this->view->required_fields = $mandatoryFields; - $this->view->configured = $historyService->getConfiguredTemplateIds(); - } - catch (Exception $e) { - Logging::info("Error?"); - Logging::info($e); - Logging::info($e->getMessage()); - - $this->_forward('index', 'playouthistorytemplate'); - } - } - - public function createTemplateAction() - { - $templateType = $this->_getParam('type', null); - - $request = $this->getRequest(); - $params = $request->getPost(); - - try { - $historyService = new Application_Service_HistoryService(); - $supportedTypes = $historyService->getSupportedTemplateTypes(); - - if (!in_array($templateType, $supportedTypes)) { - throw new Exception("Error: $templateType is not supported."); - } - - $id = $historyService->createTemplate($params); - - $this->view->url = $this->view->baseUrl("Playouthistorytemplate/configure-template/id/{$id}"); - } - catch (Exception $e) { - Logging::info($e); - Logging::info($e->getMessage()); - - $this->view->error = $e->getMessage(); - } - } - - public function setTemplateDefaultAction() - { - $templateId = $this->_getParam('id', null); - - try { - $historyService = new Application_Service_HistoryService(); - $historyService->setConfiguredTemplate($templateId); - } - catch (Exception $e) { - Logging::info($e); - Logging::info($e->getMessage()); - } - } - - public function updateTemplateAction() - { - $templateId = $this->_getParam('id', null); - $name = $this->_getParam('name', null); - $fields = $this->_getParam('fields', array()); - - try { - $historyService = new Application_Service_HistoryService(); - $historyService->updateItemTemplate($templateId, $name, $fields); - } - catch (Exception $e) { - Logging::info($e); - Logging::info($e->getMessage()); - } - } - - public function deleteTemplateAction() - { - $templateId = $this->_getParam('id'); - - try { - $historyService = new Application_Service_HistoryService(); - $historyService->deleteTemplate($templateId); - } - catch (Exception $e) { - Logging::info($e); - Logging::info($e->getMessage()); - } + public function indexAction() + { + $CC_CONFIG = Config::getConfig(); + $baseUrl = Application_Common_OsPath::getBaseDir(); + + $this->view->headScript()->appendFile($baseUrl.'js/airtime/playouthistory/template.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); + $this->view->headLink()->appendStylesheet($baseUrl.'css/history_styles.css?'.$CC_CONFIG['airtime_version']); + + $historyService = new Application_Service_HistoryService(); + $this->view->template_list = $historyService->getListItemTemplates(); + $this->view->template_file = $historyService->getFileTemplates(); + $this->view->configured = $historyService->getConfiguredTemplateIds(); + } + + public function configureTemplateAction() { + + $CC_CONFIG = Config::getConfig(); + $baseUrl = Application_Common_OsPath::getBaseDir(); + + $this->view->headScript()->appendFile($baseUrl.'js/airtime/playouthistory/configuretemplate.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); + $this->view->headLink()->appendStylesheet($baseUrl.'css/history_styles.css?'.$CC_CONFIG['airtime_version']); + + try { + + $templateId = $this->_getParam('id'); + + $historyService = new Application_Service_HistoryService(); + $template = $historyService->loadTemplate($templateId); + + $templateType = $template["type"]; + $supportedTypes = $historyService->getSupportedTemplateTypes(); + + if (!in_array($templateType, $supportedTypes)) { + throw new Exception("Error: $templateType is not supported."); + } + + $getMandatoryFields = "mandatory".ucfirst($templateType)."Fields"; + $mandatoryFields = $historyService->$getMandatoryFields(); + + $this->view->template_id = $templateId; + $this->view->template_name = $template["name"]; + $this->view->template_fields = $template["fields"]; + $this->view->template_type = $templateType; + $this->view->fileMD = $historyService->getFileMetadataTypes(); + $this->view->fields = $historyService->getFieldTypes(); + $this->view->required_fields = $mandatoryFields; + $this->view->configured = $historyService->getConfiguredTemplateIds(); + } + catch (Exception $e) { + Logging::info("Error?"); + Logging::info($e); + Logging::info($e->getMessage()); + + $this->_forward('index', 'playouthistorytemplate'); + } + } + + public function createTemplateAction() + { + $templateType = $this->_getParam('type', null); + + $request = $this->getRequest(); + $params = $request->getPost(); + + try { + $historyService = new Application_Service_HistoryService(); + $supportedTypes = $historyService->getSupportedTemplateTypes(); + + if (!in_array($templateType, $supportedTypes)) { + throw new Exception("Error: $templateType is not supported."); + } + + $id = $historyService->createTemplate($params); + + $this->view->url = $this->view->baseUrl("Playouthistorytemplate/configure-template/id/{$id}"); + } + catch (Exception $e) { + Logging::info($e); + Logging::info($e->getMessage()); + + $this->view->error = $e->getMessage(); + } + } + + public function setTemplateDefaultAction() + { + $templateId = $this->_getParam('id', null); + + try { + $historyService = new Application_Service_HistoryService(); + $historyService->setConfiguredTemplate($templateId); + } + catch (Exception $e) { + Logging::info($e); + Logging::info($e->getMessage()); + } + } + + public function updateTemplateAction() + { + $templateId = $this->_getParam('id', null); + $name = $this->_getParam('name', null); + $fields = $this->_getParam('fields', array()); + + try { + $historyService = new Application_Service_HistoryService(); + $historyService->updateItemTemplate($templateId, $name, $fields); + } + catch (Exception $e) { + Logging::info($e); + Logging::info($e->getMessage()); + } + } + + public function deleteTemplateAction() + { + $templateId = $this->_getParam('id'); + + try { + $historyService = new Application_Service_HistoryService(); + $historyService->deleteTemplate($templateId); + } + catch (Exception $e) { + Logging::info($e); + Logging::info($e->getMessage()); + } } } \ No newline at end of file diff --git a/airtime_mvc/application/services/HistoryService.php b/airtime_mvc/application/services/HistoryService.php index ea8aef958..848fa0510 100644 --- a/airtime_mvc/application/services/HistoryService.php +++ b/airtime_mvc/application/services/HistoryService.php @@ -426,15 +426,51 @@ class Application_Service_HistoryService public function getShowList($startDT, $endDT) { $user = Application_Model_User::getCurrentUser(); - $shows = Application_Model_Show::getShows($startDT, $endDT); - Loggin::info($shows); + Logging::info($startDT->format("Y-m-d H:i:s")); + Logging::info($endDT->format("Y-m-d H:i:s")); + Logging::info($shows); + //need to filter the list to only their shows if ($user->isHost()) { + $showIds = array(); + + foreach ($shows as $show) { + $showIds[] = $show["show_id"]; + } + + $showIds = array_unique($showIds); + Logging::info($showIds); + + $hostRecords = CcShowHostsQuery::create() + ->filterByDbHost($user->getId()) + ->filterByDbShow($showIds) + ->find($this->con); + + $filteredShowIds = array(); + + foreach($hostRecords as $record) { + $filteredShowIds[] = $record->getDbShow(); + } + + Logging::info($filteredShowIds); + + $filteredShows = array(); + + foreach($shows as $show) { + if (in_array($show["show_id"], $filteredShowIds)) { + $filteredShows[] = $show; + } + } } + else { + $filteredShows = $shows; + } + + return $filteredShows; } public function insertPlayedItem($schedId) { diff --git a/airtime_mvc/application/views/scripts/playouthistory/index.phtml b/airtime_mvc/application/views/scripts/playouthistory/index.phtml index 0a27df62f..67436947f 100644 --- a/airtime_mvc/application/views/scripts/playouthistory/index.phtml +++ b/airtime_mvc/application/views/scripts/playouthistory/index.phtml @@ -18,7 +18,9 @@
- Show Summary +
diff --git a/airtime_mvc/public/js/airtime/playouthistory/historytable.js b/airtime_mvc/public/js/airtime/playouthistory/historytable.js index 8a25cc7a3..0ad480c1f 100644 --- a/airtime_mvc/public/js/airtime/playouthistory/historytable.js +++ b/airtime_mvc/public/js/airtime/playouthistory/historytable.js @@ -50,6 +50,11 @@ var AIRTIME = (function(AIRTIME) { var selectedLogItems = {}; + var dateStartId = "#his_date_start", + timeStartId = "#his_time_start", + dateEndId = "#his_date_end", + timeEndId = "#his_time_end"; + function getSelectedLogItems() { var items = Object.keys(selectedLogItems); @@ -303,16 +308,26 @@ var AIRTIME = (function(AIRTIME) { return oTable; } + function showSummaryList() { + var url = baseUrl+"playouthistory/show-history-feed", + oRange = AIRTIME.utilities.fnGetScheduleRange(dateStartId, timeStartId, dateEndId, timeEndId), + data = { + format: "json", + start: oRange.start, + end: oRange.end + }; + + $.post(url, data, function() { + var x; + }); + } + mod.onReady = function() { var oBaseDatePickerSettings, oBaseTimePickerSettings, oTableAgg, oTableItem, - dateStartId = "#his_date_start", - timeStartId = "#his_time_start", - dateEndId = "#his_date_end", - timeEndId = "#his_time_end", $hisDialogEl, tabsInit = [ @@ -327,6 +342,12 @@ var AIRTIME = (function(AIRTIME) { initialize: function() { oTableAgg = aggregateHistoryTable(); } + }, + { + initialized: false, + initialize: function() { + showSummaryList(); + } } ]; @@ -514,7 +535,9 @@ var AIRTIME = (function(AIRTIME) { $historyContentDiv.find("#his-tabs").tabs({ show: function( event, ui ) { - var tab = tabsInit[ui.index]; + var href = $(ui.tab).attr("href"); + var index = href.split('-').pop(); + var tab = tabsInit[index-1]; if (!tab.initialized) { tab.initialize();