From e63518f2dadceda9e3965d2d072d3fefd9e93d36 Mon Sep 17 00:00:00 2001 From: Naomi Date: Wed, 3 Jul 2013 16:00:48 -0400 Subject: [PATCH] IM-733 Create Development timetable for Airtime Development IM-777 Database structure for new History Feature moving original functionality into the service. --- .../controllers/PlayouthistoryController.php | 10 +-- .../application/models/PlayoutHistory.php | 83 ------------------- .../application/services/HistoryService.php | 59 ++++++++++++- 3 files changed, 61 insertions(+), 91 deletions(-) delete mode 100644 airtime_mvc/application/models/PlayoutHistory.php diff --git a/airtime_mvc/application/controllers/PlayouthistoryController.php b/airtime_mvc/application/controllers/PlayouthistoryController.php index 3269fcd46..bd4fe2950 100644 --- a/airtime_mvc/application/controllers/PlayouthistoryController.php +++ b/airtime_mvc/application/controllers/PlayouthistoryController.php @@ -70,13 +70,9 @@ class PlayouthistoryController extends Zend_Controller_Action $startsDT = DateTime::createFromFormat("U", $starts_epoch, new DateTimeZone("UTC")); $endsDT = DateTime::createFromFormat("U", $ends_epoch, new DateTimeZone("UTC")); - Logging::info("history starts {$startsDT->format("Y-m-d H:i:s")}"); - Logging::info("history ends {$endsDT->format("Y-m-d H:i:s")}"); - - $history = new Application_Model_PlayoutHistory($startsDT, $endsDT, $params); - - $r = $history->getItems(); - + $historyService = new Application_Service_HistoryService(); + $r = $historyService->getItems($startsDT, $endsDT, $params); + $this->view->sEcho = $r["sEcho"]; $this->view->iTotalDisplayRecords = $r["iTotalDisplayRecords"]; $this->view->iTotalRecords = $r["iTotalRecords"]; diff --git a/airtime_mvc/application/models/PlayoutHistory.php b/airtime_mvc/application/models/PlayoutHistory.php deleted file mode 100644 index 7da1ff2c2..000000000 --- a/airtime_mvc/application/models/PlayoutHistory.php +++ /dev/null @@ -1,83 +0,0 @@ - "artist_name", - "title" => "track_title", - "played" => "played", - "length" => "length", - "composer" => "composer", - "copyright" => "copyright", - ); - - public function __construct($p_startDT, $p_endDT, $p_opts) - { - $this->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; - } - - /* - * map front end mDataProp labels to proper column names for searching etc. - */ - private function translateColumns() - { - for ($i = 0; $i < $this->opts["iColumns"]; $i++) { - - $this->opts["mDataProp_{$i}"] = $this->mDataPropMap[$this->opts["mDataProp_{$i}"]]; - } - } - - public function getItems() - { - $this->translateColumns(); - - $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}' - and schedule.playout_status > 0 and schedule.media_item_played != FALSE and schedule.broadcasted = 1 - 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; - } -} diff --git a/airtime_mvc/application/services/HistoryService.php b/airtime_mvc/application/services/HistoryService.php index 77158fbd2..d336f2f00 100644 --- a/airtime_mvc/application/services/HistoryService.php +++ b/airtime_mvc/application/services/HistoryService.php @@ -1,14 +1,71 @@ "artist_name", + "title" => "track_title", + "played" => "played", + "length" => "length", + "composer" => "composer", + "copyright" => "copyright", + ); + public function __construct() { $this->con = isset($con) ? $con : Propel::getConnection(CcPlayoutHistoryPeer::DATABASE_NAME); - $this->timezone = date_default_timezone_get(); + $this->timezone = date_default_timezone_get(); + } + + /* + * map front end mDataProp labels to proper column names for searching etc. + */ + private function translateColumns($opts) + { + for ($i = 0; $i < $opts["iColumns"]; $i++) { + + $opts["mDataProp_{$i}"] = $this->mDataPropMap[$opts["mDataProp_{$i}"]]; + } + } + + public function getItems($startDT, $endDT, $opts) + { + $this->translateColumns($opts); + + $select = array( + "file.track_title as title", + "file.artist_name as artist", + "playout.played", + "playout.file_id", + "file.composer", + "file.copyright", + "file.length" + ); + + $start = $startDT->format("Y-m-d H:i:s"); + $end = $endDT->format("Y-m-d H:i:s"); + + $historyTable = "( + select count(history.file_id) as played, history.file_id as file_id + from cc_playout_history as history + where history.starts >= '{$start}' and history.starts < '{$end}' + group by history.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, $opts, "history"); + + foreach ($results["history"] as &$row) { + $formatter = new LengthFormatter($row['length']); + $row['length'] = $formatter->format(); + } + + return $results; } public function insertPlayedItem($schedId) {