From 53b8eb27245a179201189c8c2d24c5abbfb65da8 Mon Sep 17 00:00:00 2001 From: Naomi Aro Date: Thu, 8 Mar 2012 18:30:56 +0100 Subject: [PATCH] CC-733 : export broadcast logs exporting stats based on czech law --- airtime_mvc/application/configs/ACL.php | 2 + .../application/configs/navigation.php | 9 +- .../controllers/PlayouthistoryController.php | 60 ++++++++++++ .../layouts/scripts/playouthistory.phtml | 27 +++++ airtime_mvc/application/models/Datatables.php | 98 +++++++++++++++++++ .../application/models/PlayoutHistory.php | 60 ++++++++++++ airtime_mvc/application/models/Show.php | 4 +- .../views/scripts/playouthistory/index.phtml | 1 + .../js/airtime/playouthistory/historytable.js | 73 ++++++++++++++ 9 files changed, 331 insertions(+), 3 deletions(-) create mode 100644 airtime_mvc/application/controllers/PlayouthistoryController.php create mode 100644 airtime_mvc/application/layouts/scripts/playouthistory.phtml create mode 100644 airtime_mvc/application/models/Datatables.php create mode 100644 airtime_mvc/application/models/PlayoutHistory.php create mode 100644 airtime_mvc/application/views/scripts/playouthistory/index.phtml create mode 100644 airtime_mvc/public/js/airtime/playouthistory/historytable.js diff --git a/airtime_mvc/application/configs/ACL.php b/airtime_mvc/application/configs/ACL.php index f0bb211c8..d2ce2e23a 100644 --- a/airtime_mvc/application/configs/ACL.php +++ b/airtime_mvc/application/configs/ACL.php @@ -26,6 +26,7 @@ $ccAcl->add(new Zend_Acl_Resource('library')) ->add(new Zend_Acl_Resource('recorder')) ->add(new Zend_Acl_Resource('showbuilder')) ->add(new Zend_Acl_Resource('auth')) + ->add(new Zend_Acl_Resource('playouthistory')) ->add(new Zend_Acl_Resource('usersettings')); /** Creating permissions */ @@ -44,6 +45,7 @@ $ccAcl->allow('G', 'index') ->allow('H', 'search') ->allow('H', 'playlist') ->allow('H', 'showbuilder') + ->allow('A', 'playouthistory') ->allow('A', 'user') ->allow('A', 'systemstatus') ->allow('A', 'preference'); diff --git a/airtime_mvc/application/configs/navigation.php b/airtime_mvc/application/configs/navigation.php index 400a8b509..46aef0654 100644 --- a/airtime_mvc/application/configs/navigation.php +++ b/airtime_mvc/application/configs/navigation.php @@ -85,7 +85,14 @@ $pages = array( 'controller' => 'systemstatus', 'action' => 'index', 'resource' => 'systemstatus' - ) + ), + array( + 'label' => 'Playout History', + 'module' => 'default', + 'controller' => 'playouthistory', + 'action' => 'index', + 'resource' => 'playouthistory' + ) ) ), array( diff --git a/airtime_mvc/application/controllers/PlayouthistoryController.php b/airtime_mvc/application/controllers/PlayouthistoryController.php new file mode 100644 index 000000000..6d6b64d6d --- /dev/null +++ b/airtime_mvc/application/controllers/PlayouthistoryController.php @@ -0,0 +1,60 @@ +_helper->getHelper('AjaxContext'); + $ajaxContext + ->addActionContext('playout-history-feed', 'json') + ->initContext(); + } + + public function indexAction() + { + global $CC_CONFIG; + + $this->_helper->layout->setLayout('playouthistory'); + + $request = $this->getRequest(); + $baseUrl = $request->getBaseUrl(); + + $this->view->headScript()->appendFile($baseUrl.'/js/contextmenu/jquery.contextMenu.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); + $this->view->headScript()->appendFile($baseUrl.'/js/datatables/js/jquery.dataTables.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); + $this->view->headScript()->appendFile($baseUrl.'/js/datatables/plugin/dataTables.pluginAPI.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); + $this->view->headScript()->appendFile($baseUrl.'/js/datatables/plugin/dataTables.fnSetFilteringDelay.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); + $this->view->headScript()->appendFile($baseUrl.'/js/datatables/plugin/dataTables.TableTools.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); + + $this->view->headScript()->appendFile($baseUrl.'/js/airtime/buttons/buttons.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); + $this->view->headScript()->appendFile($baseUrl.'/js/airtime/utilities/utilities.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); + $this->view->headScript()->appendFile($baseUrl.'/js/airtime/playouthistory/historytable.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); + + $this->view->headLink()->appendStylesheet($baseUrl.'/css/TableTools.css?'.$CC_CONFIG['airtime_version']); + } + + public function playoutHistoryFeedAction() + { + $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")); + + Logging::log("history starts {$startsDT->format("Y-m-d H:i:s")}"); + Logging::log("history ends {$endsDT->format("Y-m-d H:i:s")}"); + + $history = new Application_Model_PlayoutHistory($startsDT, $endsDT, $params); + + $r = $history->getItems(); + + $this->view->sEcho = $r["sEcho"]; + $this->view->iTotalDisplayRecords = $r["iTotalDisplayRecords"]; + $this->view->iTotalRecords = $r["iTotalRecords"]; + $this->view->history = $r["history"]; + } +} \ No newline at end of file diff --git a/airtime_mvc/application/layouts/scripts/playouthistory.phtml b/airtime_mvc/application/layouts/scripts/playouthistory.phtml new file mode 100644 index 000000000..210bbeaa8 --- /dev/null +++ b/airtime_mvc/application/layouts/scripts/playouthistory.phtml @@ -0,0 +1,27 @@ +doctype() ?> + + + + headTitle() ?> + headScript() ?> + headLink() ?> + google_analytics)?$this->google_analytics:"" ?> + + + +
+ + versionNotify() ?> + partial('partialviews/header.phtml', array("user" => $this->loggedInAs(), "is_trial"=>$this->isTrial(), "trial_remain"=> $this->trialRemaining())) ?> + +navigation()->menu()->setPartial($partial); ?> + +navigation()->menu() ?> +
+ +
+
layout()->content ?>
+
+ + \ No newline at end of file diff --git a/airtime_mvc/application/models/Datatables.php b/airtime_mvc/application/models/Datatables.php new file mode 100644 index 000000000..9ded1695c --- /dev/null +++ b/airtime_mvc/application/models/Datatables.php @@ -0,0 +1,98 @@ + 0) { + $where = join(" AND ", $where); + $sql = $selectorCount." FROM ".$fromTable." WHERE ".$where; + $sqlTotalDisplayRows = $sql; + + $sql = $selectorRows." FROM ".$fromTable." WHERE ".$where." ORDER BY ".$orderby." OFFSET ".$data["iDisplayStart"]." LIMIT ".$data["iDisplayLength"]; + } + else { + $sql = $selectorRows." FROM ".$fromTable." ORDER BY ".$orderby." OFFSET ".$data["iDisplayStart"]." LIMIT ".$data["iDisplayLength"]; + } + + try { + $r = $con->query($sqlTotalRows); + Logging::log($sqlTotalRows); + $totalRows = $r->fetchColumn(0); + + if (isset($sqlTotalDisplayRows)) { + $r = $con->query($sqlTotalDisplayRows); + Logging::log($sqlTotalDisplayRows); + $totalDisplayRows = $r->fetchColumn(0); + } + else { + $totalDisplayRows = $totalRows; + } + + $r = $con->query($sql); + $r->setFetchMode(PDO::FETCH_ASSOC); + $results = $r->fetchAll(); + } + catch (Exception $e) { + Logging::log($e->getMessage()); + } + + //display sql executed in airtime log for testing + Logging::log($sql); + + return array( + "sEcho" => intval($data["sEcho"]), + "iTotalDisplayRecords" => intval($totalDisplayRows), + "iTotalRecords" => intval($totalRows), + $dataProp => $results + ); + } +} \ No newline at end of file diff --git a/airtime_mvc/application/models/PlayoutHistory.php b/airtime_mvc/application/models/PlayoutHistory.php new file mode 100644 index 000000000..9084e05d6 --- /dev/null +++ b/airtime_mvc/application/models/PlayoutHistory.php @@ -0,0 +1,60 @@ +con = Propel::getConnection(CcSchedulePeer::DATABASE_NAME); + $this->startDT = $p_startDT; + $this->endDT = $p_endDT; + $this->timezone = date_default_timezone_get(); + $this->epoch_now = time(); + $this->opts = $p_opts; + } + + public function getItems() { + + $select = array( + "file.track_title as title", + "file.artist_name as artist", + "playout.played", + "playout.file_id", + "file.composer", + "file.copyright", + "file.length" + ); + + $start = $this->startDT->format("Y-m-d H:i:s"); + $end = $this->endDT->format("Y-m-d H:i:s"); + + $historyTable = "( + select count(schedule.file_id) as played, schedule.file_id as file_id + from cc_schedule as schedule + where schedule.starts >= '{$start}' and schedule.starts < '{$end}' + group by schedule.file_id + ) + AS playout left join cc_files as file on (file.id = playout.file_id)"; + + $results = Application_Model_Datatables::findEntries($this->con, $select, $historyTable, $this->opts, "history"); + + foreach ($results["history"] as &$row) { + $formatter = new LengthFormatter($row['length']); + $row['length'] = $formatter->format(); + } + + return $results; + } +} \ No newline at end of file diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php index e29aa71cb..4e63c6876 100644 --- a/airtime_mvc/application/models/Show.php +++ b/airtime_mvc/application/models/Show.php @@ -1480,8 +1480,8 @@ class Application_Model_Show { $sql = $sql." AND ({$exclude})"; } - Logging::log("getShows"); - Logging::log($sql); + //Logging::log("getShows"); + //Logging::log($sql); return $CC_DBC->GetAll($sql); } diff --git a/airtime_mvc/application/views/scripts/playouthistory/index.phtml b/airtime_mvc/application/views/scripts/playouthistory/index.phtml new file mode 100644 index 000000000..6aa7f8268 --- /dev/null +++ b/airtime_mvc/application/views/scripts/playouthistory/index.phtml @@ -0,0 +1 @@ +
\ No newline at end of file diff --git a/airtime_mvc/public/js/airtime/playouthistory/historytable.js b/airtime_mvc/public/js/airtime/playouthistory/historytable.js new file mode 100644 index 000000000..cfa69fec7 --- /dev/null +++ b/airtime_mvc/public/js/airtime/playouthistory/historytable.js @@ -0,0 +1,73 @@ +var AIRTIME = (function(AIRTIME) { + var mod; + + if (AIRTIME.history === undefined) { + AIRTIME.history = {}; + } + mod = AIRTIME.history; + + mod.historyTable = function() { + var oTable, + historyContentDiv = $("#history_content"), + historyTableDiv = historyContentDiv.find("#history_table"); + tableHeight = historyContentDiv.height() - 140; + + oTable = historyTableDiv.dataTable( { + + "aoColumns": [ + {"sTitle": "Title", "mDataProp": "title", "sClass": "his_title"}, /* Title */ + {"sTitle": "Artist", "mDataProp": "artist", "sClass": "his_artist"}, /* Creator */ + {"sTitle": "Played", "mDataProp": "played", "sClass": "his_artist"}, /* times played */ + {"sTitle": "Length", "mDataProp": "length", "sClass": "his_length"}, /* Length */ + {"sTitle": "Composer", "mDataProp": "composer", "sClass": "his_composer"}, /* Composer */ + {"sTitle": "Copyright", "mDataProp": "copyright", "sClass": "his_copyright"} /* Copyright */ + ], + + "bProcessing": true, + "bServerSide": true, + "sAjaxSource": "/Playouthistory/playout-history-feed", + "sAjaxDataProp": "history", + + "fnServerData": function ( sSource, aoData, fnCallback ) { + + aoData.push( { name: "format", value: "json"} ); + + $.ajax( { + "dataType": 'json', + "type": "GET", + "url": sSource, + "data": aoData, + "success": fnCallback + } ); + }, + + "oLanguage": { + "sSearch": "" + }, + + "sPaginationType": "full_numbers", + "bJQueryUI": true, + "bAutoWidth": false, + + "sDom": 'lfr<"H"><"dataTables_scrolling"t><"F"ip>', + }); + }; + +return AIRTIME; + +}(AIRTIME || {})); + +$(document).ready(function(){ + + var viewport = AIRTIME.utilities.findViewportDimensions(), + history_content = $("#history_content"), + widgetHeight = viewport.height - 185, + screenWidth = Math.floor(viewport.width - 110); + + history_content + .height(widgetHeight) + .width(screenWidth); + + AIRTIME.history.historyTable(); + +}); \ No newline at end of file