casting non mandatory types from "", to avoid database query problems.

This commit is contained in:
Naomi 2013-08-20 17:23:15 -04:00
parent 2e572c652c
commit 007a7ee7ef
3 changed files with 100 additions and 85 deletions

View file

@ -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')
@ -193,6 +194,14 @@ class PlayouthistoryController extends Zend_Controller_Action
$historyService->deletePlayedItem($history_id);
}
public function deleteListItemsAction()
{
$history_ids = $this->_getParam('ids');
$historyService = new Application_Service_HistoryService();
$historyService->deletePlayedItems($history_ids);
}
public function updateListItemAction()
{
try {

View file

@ -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;
}
}
@ -825,6 +826,25 @@ class Application_Service_HistoryService
}
}
/* 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 --------------------------//
@ -843,6 +863,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() {
$fields = array(

View file

@ -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 = $("<div/>");
for (i = 0, len = links.length; i < len; i++) {
attr = links[i];
if (tr.hasAttribute(attr)) {
name = attr.split("-")[1];
$link = $("<a/>", {
"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" ;
@ -375,35 +352,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,13 +401,27 @@ 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,
oRange;
@ -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();
});
}
};