can update an existing history item entry. Form is pre-populated.
This commit is contained in:
parent
590837a357
commit
31c604d09c
3 changed files with 139 additions and 57 deletions
|
@ -81,47 +81,59 @@ class PlayouthistoryController extends Zend_Controller_Action
|
||||||
|
|
||||||
public function aggregateHistoryFeedAction()
|
public function aggregateHistoryFeedAction()
|
||||||
{
|
{
|
||||||
$request = $this->getRequest();
|
try {
|
||||||
$current_time = time();
|
$request = $this->getRequest();
|
||||||
|
$current_time = time();
|
||||||
$params = $request->getParams();
|
|
||||||
|
$params = $request->getParams();
|
||||||
$starts_epoch = $request->getParam("start", $current_time - (60*60*24));
|
|
||||||
$ends_epoch = $request->getParam("end", $current_time);
|
$starts_epoch = $request->getParam("start", $current_time - (60*60*24));
|
||||||
|
$ends_epoch = $request->getParam("end", $current_time);
|
||||||
$startsDT = DateTime::createFromFormat("U", $starts_epoch, new DateTimeZone("UTC"));
|
|
||||||
$endsDT = DateTime::createFromFormat("U", $ends_epoch, new DateTimeZone("UTC"));
|
$startsDT = DateTime::createFromFormat("U", $starts_epoch, new DateTimeZone("UTC"));
|
||||||
|
$endsDT = DateTime::createFromFormat("U", $ends_epoch, new DateTimeZone("UTC"));
|
||||||
$historyService = new Application_Service_HistoryService();
|
|
||||||
$r = $historyService->getFileSummaryData($startsDT, $endsDT, $params);
|
$historyService = new Application_Service_HistoryService();
|
||||||
|
$r = $historyService->getFileSummaryData($startsDT, $endsDT, $params);
|
||||||
$this->view->sEcho = $r["sEcho"];
|
|
||||||
$this->view->iTotalDisplayRecords = $r["iTotalDisplayRecords"];
|
$this->view->sEcho = $r["sEcho"];
|
||||||
$this->view->iTotalRecords = $r["iTotalRecords"];
|
$this->view->iTotalDisplayRecords = $r["iTotalDisplayRecords"];
|
||||||
$this->view->history = $r["history"];
|
$this->view->iTotalRecords = $r["iTotalRecords"];
|
||||||
|
$this->view->history = $r["history"];
|
||||||
|
}
|
||||||
|
catch (Exception $e) {
|
||||||
|
Logging::info($e);
|
||||||
|
Logging::info($e->getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function itemHistoryFeedAction()
|
public function itemHistoryFeedAction()
|
||||||
{
|
{
|
||||||
$request = $this->getRequest();
|
try {
|
||||||
$current_time = time();
|
$request = $this->getRequest();
|
||||||
|
$current_time = time();
|
||||||
$params = $request->getParams();
|
|
||||||
|
$params = $request->getParams();
|
||||||
$starts_epoch = $request->getParam("start", $current_time - (60*60*24));
|
|
||||||
$ends_epoch = $request->getParam("end", $current_time);
|
$starts_epoch = $request->getParam("start", $current_time - (60*60*24));
|
||||||
|
$ends_epoch = $request->getParam("end", $current_time);
|
||||||
$startsDT = DateTime::createFromFormat("U", $starts_epoch, new DateTimeZone("UTC"));
|
|
||||||
$endsDT = DateTime::createFromFormat("U", $ends_epoch, new DateTimeZone("UTC"));
|
$startsDT = DateTime::createFromFormat("U", $starts_epoch, new DateTimeZone("UTC"));
|
||||||
|
$endsDT = DateTime::createFromFormat("U", $ends_epoch, new DateTimeZone("UTC"));
|
||||||
$historyService = new Application_Service_HistoryService();
|
|
||||||
//$r = $historyService->getListView($startsDT, $endsDT, $params);
|
$historyService = new Application_Service_HistoryService();
|
||||||
$r = $historyService->getPlayedItemData($startsDT, $endsDT, $params);
|
//$r = $historyService->getListView($startsDT, $endsDT, $params);
|
||||||
|
$r = $historyService->getPlayedItemData($startsDT, $endsDT, $params);
|
||||||
$this->view->sEcho = $r["sEcho"];
|
|
||||||
$this->view->iTotalDisplayRecords = $r["iTotalDisplayRecords"];
|
$this->view->sEcho = $r["sEcho"];
|
||||||
$this->view->iTotalRecords = $r["iTotalRecords"];
|
$this->view->iTotalDisplayRecords = $r["iTotalDisplayRecords"];
|
||||||
$this->view->history = $r["history"];
|
$this->view->iTotalRecords = $r["iTotalRecords"];
|
||||||
|
$this->view->history = $r["history"];
|
||||||
|
}
|
||||||
|
catch (Exception $e) {
|
||||||
|
Logging::info($e);
|
||||||
|
Logging::info($e->getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function editAggregateItemAction()
|
public function editAggregateItemAction()
|
||||||
|
@ -155,10 +167,10 @@ class PlayouthistoryController extends Zend_Controller_Action
|
||||||
|
|
||||||
public function editListItemAction()
|
public function editListItemAction()
|
||||||
{
|
{
|
||||||
$history_id = $this->_getParam('id', null);
|
$id = $this->_getParam('id', null);
|
||||||
|
|
||||||
$historyService = new Application_Service_HistoryService();
|
$historyService = new Application_Service_HistoryService();
|
||||||
$form = $historyService->makeHistoryItemForm($history_id);
|
$form = $historyService->makeHistoryItemForm($id, true);
|
||||||
|
|
||||||
$this->view->form = $form;
|
$this->view->form = $form;
|
||||||
$this->view->dialog = $this->view->render('playouthistory/dialog.phtml');
|
$this->view->dialog = $this->view->render('playouthistory/dialog.phtml');
|
||||||
|
|
|
@ -158,7 +158,7 @@ class Application_Form_EditHistoryItem extends Zend_Form
|
||||||
'class' => 'btn his_item_save',
|
'class' => 'btn his_item_save',
|
||||||
'label' => _('Save'),
|
'label' => _('Save'),
|
||||||
'decorators' => array(
|
'decorators' => array(
|
||||||
'ViewHelper'
|
'ViewHelper'
|
||||||
)
|
)
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -168,7 +168,7 @@ class Application_Form_EditHistoryItem extends Zend_Form
|
||||||
'class' => 'btn his_item_cancel',
|
'class' => 'btn his_item_cancel',
|
||||||
'label' => _('Cancel'),
|
'label' => _('Cancel'),
|
||||||
'decorators' => array(
|
'decorators' => array(
|
||||||
'ViewHelper'
|
'ViewHelper'
|
||||||
)
|
)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@ -236,6 +236,10 @@ class Application_Form_EditHistoryItem extends Zend_Form
|
||||||
|
|
||||||
$el->setDecorators(array('ViewHelper'));
|
$el->setDecorators(array('ViewHelper'));
|
||||||
$templateSubForm->addElement($el);
|
$templateSubForm->addElement($el);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function fillFields() {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -178,11 +178,9 @@ class Application_Service_HistoryService
|
||||||
|
|
||||||
if ($stmt->execute()) {
|
if ($stmt->execute()) {
|
||||||
$totalRows = $stmt->rowCount();
|
$totalRows = $stmt->rowCount();
|
||||||
Logging::info("Total Rows {$totalRows}");
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$msg = implode(',', $stmt->errorInfo());
|
$msg = implode(',', $stmt->errorInfo());
|
||||||
Logging::info($msg);
|
|
||||||
throw new Exception("Error: $msg");
|
throw new Exception("Error: $msg");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,7 +245,6 @@ class Application_Service_HistoryService
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$msg = implode(',', $stmt->errorInfo());
|
$msg = implode(',', $stmt->errorInfo());
|
||||||
Logging::info($msg);
|
|
||||||
throw new Exception("Error: $msg");
|
throw new Exception("Error: $msg");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -332,11 +329,9 @@ class Application_Service_HistoryService
|
||||||
|
|
||||||
if ($stmt->execute()) {
|
if ($stmt->execute()) {
|
||||||
$totalRows = $stmt->rowCount();
|
$totalRows = $stmt->rowCount();
|
||||||
Logging::info("Total Rows {$totalRows}");
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$msg = implode(',', $stmt->errorInfo());
|
$msg = implode(',', $stmt->errorInfo());
|
||||||
Logging::info($msg);
|
|
||||||
throw new Exception("Error: $msg");
|
throw new Exception("Error: $msg");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -385,7 +380,6 @@ class Application_Service_HistoryService
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$msg = implode(',', $stmt->errorInfo());
|
$msg = implode(',', $stmt->errorInfo());
|
||||||
Logging::info($msg);
|
|
||||||
throw new Exception("Error: $msg");
|
throw new Exception("Error: $msg");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -450,7 +444,7 @@ class Application_Service_HistoryService
|
||||||
}
|
}
|
||||||
|
|
||||||
/* id is an id in cc_playout_history */
|
/* id is an id in cc_playout_history */
|
||||||
public function makeHistoryItemForm($id) {
|
public function makeHistoryItemForm($id, $populate=false) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$form = new Application_Form_EditHistoryItem();
|
$form = new Application_Form_EditHistoryItem();
|
||||||
|
@ -458,6 +452,58 @@ class Application_Service_HistoryService
|
||||||
$required = $this->mandatoryItemFields();
|
$required = $this->mandatoryItemFields();
|
||||||
$form->createFromTemplate($template["fields"], $required);
|
$form->createFromTemplate($template["fields"], $required);
|
||||||
|
|
||||||
|
if ($populate) {
|
||||||
|
$formValues = array();
|
||||||
|
|
||||||
|
$historyRecord = CcPlayoutHistoryQuery::create()->findPk($id, $this->con);
|
||||||
|
$file = $historyRecord->getCcFiles();
|
||||||
|
|
||||||
|
if (isset($file)) {
|
||||||
|
$f = Application_Model_StoredFile::createWithFile($file, $this->con);
|
||||||
|
$filemd = $f->getDbColMetadata();
|
||||||
|
}
|
||||||
|
$metadata = array();
|
||||||
|
$mds = $historyRecord->getCcPlayoutHistoryMetaDatas();
|
||||||
|
foreach ($mds as $md) {
|
||||||
|
$metadata[$md->getDbKey()] = $md->getDbValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
$prefix = Application_Form_EditHistoryItem::ID_PREFIX;
|
||||||
|
$formValues["{$prefix}id"] = $id;
|
||||||
|
|
||||||
|
foreach($template["fields"] as $index => $field) {
|
||||||
|
|
||||||
|
$key = $field["name"];
|
||||||
|
|
||||||
|
if (in_array($key, $required)) {
|
||||||
|
|
||||||
|
$method = "getDb".ucfirst($key);
|
||||||
|
$value = $historyRecord->$method();
|
||||||
|
}
|
||||||
|
else if (isset($filemd) && $field["isFileMd"]) {
|
||||||
|
|
||||||
|
$value = $filemd[$key];
|
||||||
|
}
|
||||||
|
else if (isset($metadata[$key])) {
|
||||||
|
$value = $metadata[$key];
|
||||||
|
}
|
||||||
|
|
||||||
|
//need to convert to the station's local time first.
|
||||||
|
if ($field["type"] == TEMPLATE_DATETIME) {
|
||||||
|
$timezoneUTC = new DateTimeZone("UTC");
|
||||||
|
$timezoneLocal = new DateTimeZone($this->timezone);
|
||||||
|
|
||||||
|
$dateTime = new DateTime($value, $timezoneUTC);
|
||||||
|
$dateTime->setTimezone($timezoneLocal);
|
||||||
|
$value = $dateTime->format("Y-m-d H:i:s");
|
||||||
|
}
|
||||||
|
|
||||||
|
$formValues["$prefix{$key}"] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
$form->populate($formValues);
|
||||||
|
}
|
||||||
|
|
||||||
return $form;
|
return $form;
|
||||||
}
|
}
|
||||||
catch (Exception $e) {
|
catch (Exception $e) {
|
||||||
|
@ -491,15 +537,21 @@ class Application_Service_HistoryService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function populateTemplateItem($values) {
|
public function populateTemplateItem($values, $id=null) {
|
||||||
|
|
||||||
$this->con->beginTransaction();
|
$this->con->beginTransaction();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$template = $this->getConfiguredItemTemplate();
|
$template = $this->getConfiguredItemTemplate();
|
||||||
$prefix = Application_Form_EditHistoryItem::ID_PREFIX;
|
$prefix = Application_Form_EditHistoryItem::ID_PREFIX;
|
||||||
$historyRecord = new CcPlayoutHistory();
|
|
||||||
|
if (isset($id)) {
|
||||||
|
$historyRecord = CcPlayoutHistoryQuery::create()->findPk($id, $this->con);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$historyRecord = new CcPlayoutHistory();
|
||||||
|
}
|
||||||
|
|
||||||
$timezoneUTC = new DateTimeZone("UTC");
|
$timezoneUTC = new DateTimeZone("UTC");
|
||||||
$timezoneLocal = new DateTimeZone($this->timezone);
|
$timezoneLocal = new DateTimeZone($this->timezone);
|
||||||
|
|
||||||
|
@ -548,13 +600,24 @@ class Application_Service_HistoryService
|
||||||
$f->setDbColMetadata($md);
|
$f->setDbColMetadata($md);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Use this array to update existing values.
|
||||||
|
$mds = $historyRecord->getCcPlayoutHistoryMetaDatas();
|
||||||
|
foreach ($mds as $md) {
|
||||||
|
$prevmd[$md->getDbKey()] = $md;
|
||||||
|
}
|
||||||
foreach ($metadata as $key => $val) {
|
foreach ($metadata as $key => $val) {
|
||||||
|
|
||||||
$meta = new CcPlayoutHistoryMetaData();
|
if (isset($prevmd[$key])) {
|
||||||
$meta->setDbKey($key);
|
$meta = $prevmd[$key];
|
||||||
$meta->setDbValue($val);
|
$meta->setDbValue($val);
|
||||||
|
}
|
||||||
$historyRecord->addCcPlayoutHistoryMetaData($meta);
|
else {
|
||||||
|
$meta = new CcPlayoutHistoryMetaData();
|
||||||
|
$meta->setDbKey($key);
|
||||||
|
$meta->setDbValue($val);
|
||||||
|
|
||||||
|
$historyRecord->addCcPlayoutHistoryMetaData($meta);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$historyRecord->save($this->con);
|
$historyRecord->save($this->con);
|
||||||
|
@ -607,6 +670,8 @@ class Application_Service_HistoryService
|
||||||
|
|
||||||
Logging::info("edited list item");
|
Logging::info("edited list item");
|
||||||
Logging::info($values);
|
Logging::info($values);
|
||||||
|
|
||||||
|
$this->populateTemplateItem($values, $id);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Logging::info("edited list item NOT VALID");
|
Logging::info("edited list item NOT VALID");
|
||||||
|
@ -811,6 +876,7 @@ class Application_Service_HistoryService
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = array();
|
$data = array();
|
||||||
|
$data["id"] = $template->getDbId();
|
||||||
$data["name"] = $template->getDbName();
|
$data["name"] = $template->getDbName();
|
||||||
$data["fields"] = $fields;
|
$data["fields"] = $fields;
|
||||||
$data["type"] = $template->getDbType();
|
$data["type"] = $template->getDbType();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue