This commit is contained in:
Naomi 2013-07-31 17:39:45 -04:00
parent 7ca28fe81d
commit b33f33964a
2 changed files with 65 additions and 65 deletions

View file

@ -71,8 +71,8 @@ class PlayouthistoryController extends Zend_Controller_Action
//set datatables columns for display of data. //set datatables columns for display of data.
$historyService = new Application_Service_HistoryService(); $historyService = new Application_Service_HistoryService();
$columns = json_encode($historyService->getDatatablesPlayedItemColumns()); $columns = json_encode($historyService->getDatatablesPlayedItemColumns());
$script = "localStorage.setItem( 'datatables-historyitem-aoColumns', JSON.stringify($columns) );"; $script = "localStorage.setItem( 'datatables-historyitem-aoColumns', JSON.stringify($columns) );";
$this->view->headScript()->appendScript($script); $this->view->headScript()->appendScript($script);
} }

View file

@ -43,10 +43,10 @@ class Application_Service_HistoryService
//opts is from datatables. //opts is from datatables.
public function getPlayedItemData($startDT, $endDT, $opts) public function getPlayedItemData($startDT, $endDT, $opts)
{ {
$mainSqlQuery = ""; $mainSqlQuery = "";
$paramMap = array(); $paramMap = array();
$start = $startDT->format("Y-m-d H:i:s"); $start = $startDT->format("Y-m-d H:i:s");
$end = $endDT->format("Y-m-d H:i:s"); $end = $endDT->format("Y-m-d H:i:s");
$paramMap["starts"] = $start; $paramMap["starts"] = $start;
$paramMap["ends"] = $end; $paramMap["ends"] = $end;
@ -72,17 +72,17 @@ class Application_Service_HistoryService
} }
} }
$historyRange = "(". $historyRange = "(".
"SELECT history.starts, history.ends, history.id AS history_id". "SELECT history.starts, history.ends, history.id AS history_id".
" FROM cc_playout_history as history". " FROM cc_playout_history as history".
" WHERE history.starts >= :starts and history.starts < :ends". " WHERE history.starts >= :starts and history.starts < :ends".
") AS history_range"; ") AS history_range";
$manualMeta = "(". $manualMeta = "(".
"SELECT %KEY%.value AS %KEY%, %KEY%.history_id". "SELECT %KEY%.value AS %KEY%, %KEY%.history_id".
" FROM (". " FROM (".
" SELECT * from cc_playout_history_metadata AS phm WHERE phm.key = :meta_%KEY%". " SELECT * from cc_playout_history_metadata AS phm WHERE phm.key = :meta_%KEY%".
" ) AS %KEY%". " ) AS %KEY%".
" ) AS %KEY%_filter"; " ) AS %KEY%_filter";
$mainSelect = array("history_range.starts", "history_range.ends", "history_range.history_id"); $mainSelect = array("history_range.starts", "history_range.ends", "history_range.history_id");
@ -114,25 +114,25 @@ class Application_Service_HistoryService
$paramMap["meta_{$key}"] = $key; $paramMap["meta_{$key}"] = $key;
} }
//the files associated with scheduled playback in Airtime. //the files associated with scheduled playback in Airtime.
$historyFile = "(". $historyFile = "(".
"SELECT history.id AS history_id, history.file_id". "SELECT history.id AS history_id, history.file_id".
" FROM cc_playout_history AS history". " FROM cc_playout_history AS history".
" WHERE history.file_id IS NOT NULL". " WHERE history.file_id IS NOT NULL".
") AS history_file"; ") AS history_file";
$fileMd = "(". $fileMd = "(".
"SELECT %NON_NULL_FILE_SELECT%". "SELECT %NON_NULL_FILE_SELECT%".
" FROM cc_files AS file". " FROM cc_files AS file".
") AS file_md"; ") AS file_md";
$fileMd = str_replace("%NON_NULL_FILE_SELECT%", join(", ", $nonNullFileSelect), $fileMd); $fileMd = str_replace("%NON_NULL_FILE_SELECT%", join(", ", $nonNullFileSelect), $fileMd);
//null files are from manually added data (filling in webstream info etc) //null files are from manually added data (filling in webstream info etc)
$nullFile = "(". $nullFile = "(".
"SELECT history.id AS history_id". "SELECT history.id AS history_id".
" FROM cc_playout_history AS history". " FROM cc_playout_history AS history".
" WHERE history.file_id IS NULL". " WHERE history.file_id IS NULL".
") AS null_file"; ") AS null_file";
@ -157,10 +157,10 @@ class Application_Service_HistoryService
for ($i = 0, $len = count($fields_general); $i < $len; $i++) { for ($i = 0, $len = count($fields_general); $i < $len; $i++) {
$field = $fields_general[$i]; $field = $fields_general[$i];
$key = $field["name"]; $key = $field["name"];
$mdFilters[] = str_replace("%KEY%", $key, $manualMeta); $mdFilters[] = str_replace("%KEY%", $key, $manualMeta);
$paramMap["meta_{$key}"] = $key; $paramMap["meta_{$key}"] = $key;
$mainSelect[] = "{$key}_filter.{$key}"; $mainSelect[] = "{$key}_filter.{$key}";
} }
@ -175,17 +175,17 @@ class Application_Service_HistoryService
" LEFT JOIN ( {$fileSqlQuery} ) as file_info USING(history_id)"; " LEFT JOIN ( {$fileSqlQuery} ) as file_info USING(history_id)";
} }
foreach ($mdFilters as $filter) { foreach ($mdFilters as $filter) {
$mainSqlQuery.= $mainSqlQuery.=
" LEFT JOIN {$filter} USING(history_id)"; " LEFT JOIN {$filter} USING(history_id)";
} }
Logging::info($mainSqlQuery); Logging::info($mainSqlQuery);
$stmt = $this->con->prepare($mainSqlQuery); $stmt = $this->con->prepare($mainSqlQuery);
foreach ($paramMap as $param => $v) { foreach ($paramMap as $param => $v) {
$stmt->bindValue($param, $v); $stmt->bindValue($param, $v);
} }
$rows = array(); $rows = array();
@ -194,7 +194,7 @@ class Application_Service_HistoryService
} }
else { else {
$msg = implode(',', $stmt->errorInfo()); $msg = implode(',', $stmt->errorInfo());
Logging::info($msg); Logging::info($msg);
throw new Exception("Error: $msg"); throw new Exception("Error: $msg");
} }
@ -205,27 +205,27 @@ class Application_Service_HistoryService
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
//processing results. //processing results.
$timezoneUTC = new DateTimeZone("UTC"); $timezoneUTC = new DateTimeZone("UTC");
$timezoneLocal = new DateTimeZone($this->timezone); $timezoneLocal = new DateTimeZone($this->timezone);
//need to display the results in the station's timezone. //need to display the results in the station's timezone.
foreach ($rows as $index => &$result) { foreach ($rows as $index => &$result) {
$dateTime = new DateTime($result["starts"], $timezoneUTC); $dateTime = new DateTime($result["starts"], $timezoneUTC);
$dateTime->setTimezone($timezoneLocal); $dateTime->setTimezone($timezoneLocal);
$result["starts"] = $dateTime->format("Y-m-d H:i:s"); $result["starts"] = $dateTime->format("Y-m-d H:i:s");
$dateTime = new DateTime($result["ends"], $timezoneUTC); $dateTime = new DateTime($result["ends"], $timezoneUTC);
$dateTime->setTimezone($timezoneLocal); $dateTime->setTimezone($timezoneLocal);
$result["ends"] = $dateTime->format("Y-m-d H:i:s"); $result["ends"] = $dateTime->format("Y-m-d H:i:s");
} }
return array( return array(
"sEcho" => intval($opts["sEcho"]), "sEcho" => intval($opts["sEcho"]),
//"iTotalDisplayRecords" => intval($totalDisplayRows), //"iTotalDisplayRecords" => intval($totalDisplayRows),
"iTotalDisplayRecords" => intval($totalRows), "iTotalDisplayRecords" => intval($totalRows),
"iTotalRecords" => intval($totalRows), "iTotalRecords" => intval($totalRows),
"history" => $rows "history" => $rows
); );
} }
@ -720,7 +720,7 @@ class Application_Service_HistoryService
try { try {
//{"sTitle": $.i18n._("Start"), "mDataProp": "starts", "sClass": "his_starts"} //{"sTitle": $.i18n._("Start"), "mDataProp": "starts", "sClass": "his_starts"}
$template = $this->getConfiguredItemTemplate(); $template = $this->getConfiguredItemTemplate();
$columns = array(); $columns = array();
@ -736,10 +736,10 @@ class Application_Service_HistoryService
); );
} }
return $columns; return $columns;
} }
catch (Exception $e) { catch (Exception $e) {
throw $e; throw $e;
} }
} }