sintonia/airtime_mvc/application/controllers/PlayouthistoryController.php

270 lines
11 KiB
PHP
Raw Normal View History

<?php
class PlayouthistoryController extends Zend_Controller_Action
{
public function init()
{
$ajaxContext = $this->_helper->getHelper('AjaxContext');
$ajaxContext
->addActionContext('file-history-feed', 'json')
2013-07-18 07:31:20 +02:00
->addActionContext('item-history-feed', 'json')
->addActionContext('show-history-feed', 'json')
->addActionContext('edit-file-item', 'json')
2013-07-22 16:45:39 +02:00
->addActionContext('create-list-item', 'json')
2013-07-18 07:31:20 +02:00
->addActionContext('edit-list-item', 'json')
->addActionContext('delete-list-item', 'json')
->addActionContext('delete-list-items', 'json')
2013-07-23 00:11:44 +02:00
->addActionContext('update-list-item', 'json')
->addActionContext('update-file-item', 'json')
->initContext();
}
public function indexAction()
{
$CC_CONFIG = Config::getConfig();
$request = $this->getRequest();
$baseUrl = Application_Common_OsPath::getBaseDir();
//default time is the last 24 hours.
$now = time();
$from = $request->getParam("from", $now - (24*60*60));
$to = $request->getParam("to", $now);
$start = DateTime::createFromFormat("U", $from, new DateTimeZone("UTC"));
$start->setTimezone(new DateTimeZone(date_default_timezone_get()));
$end = DateTime::createFromFormat("U", $to, new DateTimeZone("UTC"));
$end->setTimezone(new DateTimeZone(date_default_timezone_get()));
$form = new Application_Form_DateRange();
$form->populate(array(
'his_date_start' => $start->format("Y-m-d"),
'his_time_start' => $start->format("H:i"),
'his_date_end' => $end->format("Y-m-d"),
'his_time_end' => $end->format("H:i")
));
$this->view->date_form = $form;
$this->view->headScript()->appendFile($baseUrl.'js/contextmenu/jquery.contextMenu.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
$this->view->headScript()->appendFile($baseUrl.'js/datatables/js/jquery.dataTables.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
$this->view->headScript()->appendFile($baseUrl.'js/datatables/plugin/dataTables.pluginAPI.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
$this->view->headScript()->appendFile($baseUrl.'js/datatables/plugin/dataTables.fnSetFilteringDelay.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
2013-08-13 00:18:33 +02:00
$this->view->headScript()->appendFile($baseUrl.'js/datatables/plugin/TableTools-2.1.5/js/ZeroClipboard.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
$this->view->headScript()->appendFile($baseUrl.'js/datatables/plugin/TableTools-2.1.5/js/TableTools.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
$offset = date("Z") * -1;
$this->view->headScript()->appendScript("var serverTimezoneOffset = {$offset}; //in seconds");
$this->view->headScript()->appendFile($baseUrl.'js/timepicker/jquery.ui.timepicker.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
2013-08-23 03:39:46 +02:00
$this->view->headScript()->appendFile($baseUrl.'js/bootstrap-datetime/bootstrap-datetimepicker.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
$this->view->headScript()->appendFile($baseUrl.'js/airtime/buttons/buttons.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
$this->view->headScript()->appendFile($baseUrl.'js/airtime/utilities/utilities.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
$this->view->headScript()->appendFile($baseUrl.'js/airtime/playouthistory/historytable.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
$this->view->headLink()->appendStylesheet($baseUrl.'css/bootstrap-datetimepicker.min.css?'.$CC_CONFIG['airtime_version']);
2013-08-13 00:18:33 +02:00
$this->view->headLink()->appendStylesheet($baseUrl.'js/datatables/plugin/TableTools-2.1.5/css/TableTools.css?'.$CC_CONFIG['airtime_version']);
$this->view->headLink()->appendStylesheet($baseUrl.'css/jquery.ui.timepicker.css?'.$CC_CONFIG['airtime_version']);
$this->view->headLink()->appendStylesheet($baseUrl.'css/playouthistory.css?'.$CC_CONFIG['airtime_version']);
$this->view->headLink()->appendStylesheet($baseUrl.'css/history_styles.css?'.$CC_CONFIG['airtime_version']);
$this->view->headLink()->appendStylesheet($baseUrl.'css/jquery.contextMenu.css?'.$CC_CONFIG['airtime_version']);
//set datatables columns for display of data.
$historyService = new Application_Service_HistoryService();
$columns = json_encode($historyService->getDatatablesLogSheetColumns());
$script = "localStorage.setItem( 'datatables-historyitem-aoColumns', JSON.stringify($columns) ); ";
2013-08-02 21:30:35 +02:00
$columns = json_encode($historyService->getDatatablesFileSummaryColumns());
$script.= "localStorage.setItem( 'datatables-historyfile-aoColumns', JSON.stringify($columns) );";
$this->view->headScript()->appendScript($script);
$user = Application_Model_User::getCurrentUser();
$this->view->userType = $user->getType();
}
public function fileHistoryFeedAction()
{
try {
$request = $this->getRequest();
$current_time = time();
$params = $request->getParams();
$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"));
$historyService = new Application_Service_HistoryService();
$r = $historyService->getFileSummaryData($startsDT, $endsDT, $params);
$this->view->sEcho = $r["sEcho"];
$this->view->iTotalDisplayRecords = $r["iTotalDisplayRecords"];
$this->view->iTotalRecords = $r["iTotalRecords"];
$this->view->history = $r["history"];
}
catch (Exception $e) {
Logging::info($e);
Logging::info($e->getMessage());
}
2013-07-18 07:31:20 +02:00
}
public function itemHistoryFeedAction()
{
try {
$request = $this->getRequest();
$current_time = time();
$params = $request->getParams();
$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"));
$historyService = new Application_Service_HistoryService();
$r = $historyService->getPlayedItemData($startsDT, $endsDT, $params);
$this->view->sEcho = $r["sEcho"];
$this->view->iTotalDisplayRecords = $r["iTotalDisplayRecords"];
$this->view->iTotalRecords = $r["iTotalRecords"];
$this->view->history = $r["history"];
}
catch (Exception $e) {
Logging::info($e);
Logging::info($e->getMessage());
}
}
public function showHistoryFeedAction()
{
try {
$request = $this->getRequest();
$current_time = 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"));
$historyService = new Application_Service_HistoryService();
$shows = $historyService->getShowList($startsDT, $endsDT);
$this->_helper->json->sendJson($shows);
}
catch (Exception $e) {
Logging::info($e);
Logging::info($e->getMessage());
}
}
2013-07-18 07:31:20 +02:00
public function editFileItemAction()
{
$file_id = $this->_getParam('id');
2013-07-18 07:31:20 +02:00
$historyService = new Application_Service_HistoryService();
$form = $historyService->makeHistoryFileForm($file_id);
2013-07-18 07:31:20 +02:00
$this->view->form = $form;
$this->view->dialog = $this->view->render('playouthistory/dialog.phtml');
2013-07-18 07:31:20 +02:00
unset($this->view->form);
}
2013-07-22 16:47:11 +02:00
public function createListItemAction()
{
try {
$request = $this->getRequest();
$params = $request->getPost();
Logging::info($params);
$historyService = new Application_Service_HistoryService();
$json = $historyService->createPlayedItem($params);
2013-08-23 21:53:18 +02:00
if (isset($json["form"])) {
$this->view->form = $json["form"];
$json["form"] = $this->view->render('playouthistory/dialog.phtml');
unset($this->view->form);
}
$this->_helper->json->sendJson($json);
}
2013-07-31 01:25:06 +02:00
catch (Exception $e) {
Logging::info($e);
Logging::info($e->getMessage());
}
2013-07-22 16:45:39 +02:00
}
2013-07-18 07:37:39 +02:00
public function editListItemAction()
{
$id = $this->_getParam('id', null);
Logging::info("Id is: $id");
$populate = isset($id) ? true : false;
2013-07-18 07:37:39 +02:00
$historyService = new Application_Service_HistoryService();
$form = $historyService->makeHistoryItemForm($id, $populate);
2013-07-18 07:37:39 +02:00
$this->view->form = $form;
$this->view->dialog = $this->view->render('playouthistory/dialog.phtml');
2013-07-18 07:37:39 +02:00
unset($this->view->form);
2013-07-18 07:31:20 +02:00
}
public function deleteListItemAction()
{
$history_id = $this->_getParam('id');
$historyService = new Application_Service_HistoryService();
$historyService->deletePlayedItem($history_id);
}
2013-08-20 23:23:48 +02:00
public function deleteListItemsAction()
{
$history_ids = $this->_getParam('ids');
2013-08-20 23:23:48 +02:00
$historyService = new Application_Service_HistoryService();
$historyService->deletePlayedItems($history_ids);
}
2013-07-23 00:11:44 +02:00
public function updateListItemAction()
{
try {
$request = $this->getRequest();
$params = $request->getPost();
Logging::info($params);
$historyService = new Application_Service_HistoryService();
$json = $historyService->editPlayedItem($params);
if (isset($json["form"])) {
2013-08-23 21:53:18 +02:00
$this->view->form = $json["form"];
$json["form"] = $this->view->render('playouthistory/dialog.phtml');
unset($this->view->form);
}
$this->_helper->json->sendJson($json);
}
catch (Exception $e) {
Logging::info($e);
Logging::info($e->getMessage());
}
2013-07-23 00:11:44 +02:00
}
2013-07-18 07:31:20 +02:00
public function updateFileItemAction()
{
2013-07-18 07:31:20 +02:00
$request = $this->getRequest();
$params = $request->getPost();
Logging::info($params);
$historyService = new Application_Service_HistoryService();
2013-07-18 07:31:20 +02:00
$json = $historyService->editPlayedFile($params);
$this->_helper->json->sendJson($json);
2013-07-18 07:31:20 +02:00
}
}