From 007a7ee7efc3341647a208f76e356402ff54f441 Mon Sep 17 00:00:00 2001 From: Naomi Date: Tue, 20 Aug 2013 17:23:15 -0400 Subject: [PATCH] casting non mandatory types from "", to avoid database query problems. --- .../controllers/PlayouthistoryController.php | 9 ++ .../application/services/HistoryService.php | 41 +++++- .../js/airtime/playouthistory/historytable.js | 135 +++++++----------- 3 files changed, 100 insertions(+), 85 deletions(-) diff --git a/airtime_mvc/application/controllers/PlayouthistoryController.php b/airtime_mvc/application/controllers/PlayouthistoryController.php index 6427b9acc..e331db127 100644 --- a/airtime_mvc/application/controllers/PlayouthistoryController.php +++ b/airtime_mvc/application/controllers/PlayouthistoryController.php @@ -12,6 +12,7 @@ class PlayouthistoryController extends Zend_Controller_Action ->addActionContext('create-list-item', 'json') ->addActionContext('edit-list-item', 'json') ->addActionContext('delete-list-item', 'json') + ->addActionContext('delete-list-items', 'json') ->addActionContext('update-list-item', 'json') ->addActionContext('update-file-item', 'json') ->addActionContext('create-template', 'json') @@ -192,6 +193,14 @@ class PlayouthistoryController extends Zend_Controller_Action $historyService = new Application_Service_HistoryService(); $historyService->deletePlayedItem($history_id); } + + public function deleteListItemsAction() + { + $history_ids = $this->_getParam('ids'); + + $historyService = new Application_Service_HistoryService(); + $historyService->deletePlayedItems($history_ids); + } public function updateListItemAction() { diff --git a/airtime_mvc/application/services/HistoryService.php b/airtime_mvc/application/services/HistoryService.php index c55a2c5df..3eb3ca6a8 100644 --- a/airtime_mvc/application/services/HistoryService.php +++ b/airtime_mvc/application/services/HistoryService.php @@ -638,6 +638,7 @@ class Application_Service_HistoryService $metadata = array(); $fields = $template["fields"]; $required = $this->mandatoryItemFields(); + $phpCasts = $this->getPhpCasts(); for ($i = 0, $len = count($fields); $i < $len; $i++) { @@ -650,14 +651,14 @@ class Application_Service_HistoryService } $isFileMd = $field["isFileMd"]; - $entry = $templateValues[$prefix.$key]; + $entry = $phpCasts[$field["type"]]($templateValues[$prefix.$key]); if ($isFileMd && isset($file)) { - Logging::info("adding metadata associated to a file for {$key}"); + Logging::info("adding metadata associated to a file for {$key} = {$entry}"); $md[$key] = $entry; } else { - Logging::info("adding metadata for {$key}"); + Logging::info("adding metadata for {$key} = {$entry}"); $metadata[$key] = $entry; } } @@ -824,6 +825,25 @@ class Application_Service_HistoryService throw $e; } } + + /* id is an id in cc_playout_history */ + public function deletePlayedItems($ids) { + + $this->con->beginTransaction(); + + try { + + $records = CcPlayoutHistoryQuery::create()->findPks($ids, $this->con); + $records->delete($this->con); + + $this->con->commit(); + } + catch (Exception $e) { + $this->con->rollback(); + Logging::info($e); + throw $e; + } + } //---------------- Following code is for History Templates --------------------------// @@ -842,6 +862,21 @@ class Application_Service_HistoryService return $fields; } + + private function getPhpCasts() { + + $fields = array( + TEMPLATE_DATE => "strval", + TEMPLATE_TIME => "strval", + TEMPLATE_DATETIME => "strval", + TEMPLATE_STRING => "strval", + TEMPLATE_BOOLEAN => "intval", //boolval only exists in php 5.5+ wtf? + TEMPLATE_INT => "intval", + TEMPLATE_FLOAT => "floatval", + ); + + return $fields; + } private function getSqlTypes() { diff --git a/airtime_mvc/public/js/airtime/playouthistory/historytable.js b/airtime_mvc/public/js/airtime/playouthistory/historytable.js index ea209976e..86daa7abe 100644 --- a/airtime_mvc/public/js/airtime/playouthistory/historytable.js +++ b/airtime_mvc/public/js/airtime/playouthistory/historytable.js @@ -39,6 +39,26 @@ var AIRTIME = (function(AIRTIME) { var sDom = 'l<"dt-process-rel"r><"H"T><"dataTables_scrolling"t><"F"ip>'; + var selectedLogItems = {}; + + function getSelectedLogItems() { + var items = Object.keys(selectedLogItems); + + return items; + } + + function addSelectedLogItem(id) { + selectedLogItems[id] = ""; + } + + function removeSelectedLogItem(id) { + delete selectedLogItems[id]; + } + + function emptySelectedLogItems() { + selectedLogItems = {}; + } + function getFileName(ext){ var filename = $("#his_date_start").val()+"_"+$("#his_time_start").val()+"m--"+$("#his_date_end").val()+"_"+$("#his_time_end").val()+"m"; filename = filename.replace(/:/g,"h"); @@ -249,6 +269,11 @@ var AIRTIME = (function(AIRTIME) { $historyContentDiv = $("#history_content"); + function redrawTables() { + oTableAgg.fnDraw(); + oTableItem.fnDraw(); + } + function removeHistoryDialog() { $hisDialogEl.dialog("destroy"); $hisDialogEl.remove(); @@ -315,54 +340,6 @@ var AIRTIME = (function(AIRTIME) { $historyContentDiv.find(dateEndId).datepicker(oBaseDatePickerSettings); $historyContentDiv.find(timeEndId).timepicker(oBaseTimePickerSettings); - // 'open' an information row when a row is clicked on - //for create/edit/delete - function openRow(oTable, tr) { - var links = ['url-edit', 'url-delete'], - i, len, - attr, - name, - $link, - $div; - - $div = $("
"); - - for (i = 0, len = links.length; i < len; i++) { - - attr = links[i]; - - if (tr.hasAttribute(attr)) { - name = attr.split("-")[1]; - - $link = $("", { - "href": tr.getAttribute(attr), - "text": $.i18n._(name), - "class": "his_"+name - }); - - $div.append($link); - } - } - - if (oTable.fnIsOpen(tr)) { - oTable.fnClose(tr); - } - else { - oTable.fnOpen(tr, $div, "his_update"); - } - } - - /* - $historyContentDiv.on("click", "#history_table_list tr", function(ev) { - openRow(oTableItem, this); - }); - - - $historyContentDiv.on("click", "#history_table_aggregate tr", function(ev) { - openRow(oTableAgg, this); - }); - */ - $("#his_create").click(function(e) { var url = baseUrl+"playouthistory/edit-list-item/format/json" ; @@ -374,35 +351,6 @@ var AIRTIME = (function(AIRTIME) { }, "json"); }); - - $historyContentDiv.on("click", "a.his_edit", function(e) { - var url = e.target.href; - - e.preventDefault(); - - $.get(url, function(json) { - - makeHistoryDialog(json.dialog); - - }, "json"); - }); - - $historyContentDiv.on("click", "a.his_delete", function(e) { - var url = e.target.href, - doDelete; - - e.preventDefault(); - - doDelete = confirm($.i18n._("Delete this history record?")); - - if (doDelete) { - $.post(url, function(json) { - oTableAgg.fnDraw(); - oTableItem.fnDraw(); - - }, "json"); - } - }); $('body').on("click", ".his_file_cancel, .his_item_cancel", function(e) { removeHistoryDialog(); @@ -425,7 +373,7 @@ var AIRTIME = (function(AIRTIME) { } else { removeHistoryDialog(); - oTableAgg.fnDraw(); + redrawTables(); } }, "json"); @@ -453,12 +401,26 @@ var AIRTIME = (function(AIRTIME) { } else { removeHistoryDialog(); - oTableItem.fnDraw(); + redrawTables(); } }, "json"); - }); + }); + + + $historyContentDiv.on("click", ".his_checkbox input", function(e) { + var checked = e.currentTarget.checked, + $tr = $(e.currentTarget).parents("tr"), + id = $tr.data("his-id"); + + if (checked) { + addSelectedLogItem(id); + } + else { + removeSelectedLogItem(id); + } + }); $historyContentDiv.find("#his_submit").click(function(ev){ var fn, @@ -470,8 +432,16 @@ var AIRTIME = (function(AIRTIME) { fn.start = oRange.start; fn.end = oRange.end; - oTableAgg.fnDraw(); - oTableItem.fnDraw(); + redrawTables(); + }); + + $historyContentDiv.find("#his_trash").click(function(ev){ + var items = getSelectedLogItems(), + url = baseUrl+"playouthistory/delete-list-items"; + + $.post(url, {ids: items, format: "json"}, function(){ + redrawTables(); + }); }); $historyContentDiv.find("#his-tabs").tabs(); @@ -518,6 +488,7 @@ var AIRTIME = (function(AIRTIME) { if (c) { $.post(deleteUrl, {format: "json"}, function(json) { oTableItem.fnDraw(); + oTableAgg.fnDraw(); }); } };