can configure the file summary template as well now.

This commit is contained in:
Naomi 2013-08-02 16:15:32 -04:00
parent 774027c9bd
commit e047c2f71d
2 changed files with 119 additions and 19 deletions

View File

@ -257,6 +257,9 @@ class PlayouthistoryController extends Zend_Controller_Action
{ {
$templateType = $this->_getParam('type', null); $templateType = $this->_getParam('type', null);
$request = $this->getRequest();
$params = $request->getPost();
try { try {
$historyService = new Application_Service_HistoryService(); $historyService = new Application_Service_HistoryService();
$supportedTypes = $historyService->getSupportedTemplateTypes(); $supportedTypes = $historyService->getSupportedTemplateTypes();

View File

@ -169,6 +169,7 @@ class Application_Service_HistoryService
" LEFT JOIN {$filter} USING(history_id)"; " LEFT JOIN {$filter} USING(history_id)";
} }
//----------------------------------------------------------------------
//need to count the total rows to tell Datatables. //need to count the total rows to tell Datatables.
$stmt = $this->con->prepare($mainSqlQuery); $stmt = $this->con->prepare($mainSqlQuery);
foreach ($paramMap as $param => $v) { foreach ($paramMap as $param => $v) {
@ -222,6 +223,9 @@ class Application_Service_HistoryService
" ORDER BY {$orders}"; " ORDER BY {$orders}";
} }
//---------------------------------------------------------------
//using Datatables parameters to add limits/offsets
$displayLength = intval($opts["iDisplayLength"]); $displayLength = intval($opts["iDisplayLength"]);
//limit the results returned. //limit the results returned.
if ($displayLength !== -1) { if ($displayLength !== -1) {
@ -277,35 +281,128 @@ class Application_Service_HistoryService
public function getFileSummaryData($startDT, $endDT, $opts) public function getFileSummaryData($startDT, $endDT, $opts)
{ {
$select = array ( $select = array (
"file.track_title", "summary.played",
"file.artist_name", "summary.file_id",
"playout.played", "summary.".MDATA_KEY_TITLE,
"playout.file_id", "summary.".MDATA_KEY_CREATOR
"file.composer",
"file.copyright",
"file.length"
); );
$mainSqlQuery = "";
$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");
$historyTable = "( $paramMap["starts"] = $start;
select count(history.file_id) as played, history.file_id as file_id $paramMap["ends"] = $end;
from cc_playout_history as history
where history.starts >= '{$start}' and history.starts < '{$end}' $template = $this->getConfiguredFileTemplate();
and history.file_id is not NULL $fields = $template["fields"];
group by history.file_id $required = $this->mandatoryFileFields();
foreach ($fields as $index=>$field) {
$key = $field["name"];
if (in_array($field["name"], $required)) {
continue;
}
$select[] = "summary.{$key}";
}
$fileSummaryTable = "((
SELECT COUNT(history.file_id) as played, history.file_id as file_id
FROM cc_playout_history AS history
WHERE history.starts >= :starts AND history.starts < :ends
AND history.file_id IS NOT NULL
GROUP BY history.file_id
) AS playout ) AS playout
left join cc_files as file on (file.id = playout.file_id)"; LEFT JOIN cc_files AS file ON (file.id = playout.file_id)) AS summary";
$results = Application_Model_Datatables::findEntries($this->con, $select, $historyTable, $opts, "history"); $mainSqlQuery.=
"SELECT ".join(", ", $select).
" FROM {$fileSummaryTable}";
foreach ($results["history"] as &$row) { //-------------------------------------------------------------------------
//need to count the total rows to tell Datatables.
$stmt = $this->con->prepare($mainSqlQuery);
foreach ($paramMap as $param => $v) {
$stmt->bindValue($param, $v);
}
if ($stmt->execute()) {
$totalRows = $stmt->rowCount();
Logging::info("Total Rows {$totalRows}");
}
else {
$msg = implode(',', $stmt->errorInfo());
Logging::info($msg);
throw new Exception("Error: $msg");
}
//------------------------------------------------------------------------
//Using Datatables parameters to sort the data.
$numOrderColumns = $opts["iSortingCols"];
$orderBys = array();
for ($i = 0; $i < $numOrderColumns; $i++) {
$colNum = $opts["iSortCol_".$i];
$key = $opts["mDataProp_".$colNum];
$sortDir = $opts["sSortDir_".$i];
$orderBys[] = "summary.{$key} {$sortDir}";
}
if ($numOrderColumns > 0) {
$orders = join(", ", $orderBys);
$mainSqlQuery.=
" ORDER BY {$orders}";
}
//------------------------------------------------------------
//using datatables params to add limits/offsets
$displayLength = intval($opts["iDisplayLength"]);
if ($displayLength !== -1) {
$mainSqlQuery.=
" OFFSET :offset LIMIT :limit";
$paramMap["offset"] = $opts["iDisplayStart"];
$paramMap["limit"] = $displayLength;
}
$stmt = $this->con->prepare($mainSqlQuery);
foreach ($paramMap as $param => $v) {
$stmt->bindValue($param, $v);
}
$rows = array();
if ($stmt->execute()) {
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
else {
$msg = implode(',', $stmt->errorInfo());
Logging::info($msg);
throw new Exception("Error: $msg");
}
//-----------------------------------------------------------------
//processing the results
foreach ($rows as &$row) {
$formatter = new LengthFormatter($row['length']); $formatter = new LengthFormatter($row['length']);
$row['length'] = $formatter->format(); $row['length'] = $formatter->format();
} }
return $results; return array(
"sEcho" => intval($opts["sEcho"]),
//"iTotalDisplayRecords" => intval($totalDisplayRows),
"iTotalDisplayRecords" => intval($totalRows),
"iTotalRecords" => intval($totalRows),
"history" => $rows
);
} }
public function insertPlayedItem($schedId) { public function insertPlayedItem($schedId) {