PlayouthistorytemplateController.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. class PlayouthistorytemplateController extends Zend_Controller_Action
  3. {
  4. public function init()
  5. {
  6. $ajaxContext = $this->_helper->getHelper('AjaxContext');
  7. $ajaxContext
  8. ->addActionContext('create-template', 'json')
  9. ->addActionContext('update-template', 'json')
  10. ->addActionContext('delete-template', 'json')
  11. ->addActionContext('set-template-default', 'json')
  12. ->initContext();
  13. }
  14. public function indexAction()
  15. {
  16. $CC_CONFIG = Config::getConfig();
  17. $baseUrl = Application_Common_OsPath::getBaseDir();
  18. $this->view->headScript()->appendFile($baseUrl.'js/airtime/playouthistory/template.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
  19. $this->view->headLink()->appendStylesheet($baseUrl.'css/history_styles.css?'.$CC_CONFIG['airtime_version']);
  20. $historyService = new Application_Service_HistoryService();
  21. $this->view->template_list = $historyService->getListItemTemplates();
  22. $this->view->template_file = $historyService->getFileTemplates();
  23. $this->view->configured = $historyService->getConfiguredTemplateIds();
  24. }
  25. public function configureTemplateAction() {
  26. $CC_CONFIG = Config::getConfig();
  27. $baseUrl = Application_Common_OsPath::getBaseDir();
  28. $this->view->headScript()->appendFile($baseUrl.'js/airtime/playouthistory/configuretemplate.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
  29. $this->view->headLink()->appendStylesheet($baseUrl.'css/history_styles.css?'.$CC_CONFIG['airtime_version']);
  30. try {
  31. $templateId = $this->_getParam('id');
  32. $historyService = new Application_Service_HistoryService();
  33. $template = $historyService->loadTemplate($templateId);
  34. $templateType = $template["type"];
  35. $supportedTypes = $historyService->getSupportedTemplateTypes();
  36. if (!in_array($templateType, $supportedTypes)) {
  37. throw new Exception("Error: $templateType is not supported.");
  38. }
  39. $getMandatoryFields = "mandatory".ucfirst($templateType)."Fields";
  40. $mandatoryFields = $historyService->$getMandatoryFields();
  41. $this->view->template_id = $templateId;
  42. $this->view->template_name = $template["name"];
  43. $this->view->template_fields = $template["fields"];
  44. $this->view->template_type = $templateType;
  45. $this->view->fileMD = $historyService->getFileMetadataTypes();
  46. $this->view->fields = $historyService->getFieldTypes();
  47. $this->view->required_fields = $mandatoryFields;
  48. $this->view->configured = $historyService->getConfiguredTemplateIds();
  49. }
  50. catch (Exception $e) {
  51. Logging::info("Error?");
  52. Logging::info($e);
  53. Logging::info($e->getMessage());
  54. $this->_forward('index', 'playouthistorytemplate');
  55. }
  56. }
  57. public function createTemplateAction()
  58. {
  59. $templateType = $this->_getParam('type', null);
  60. $request = $this->getRequest();
  61. $params = $request->getPost();
  62. try {
  63. $historyService = new Application_Service_HistoryService();
  64. $supportedTypes = $historyService->getSupportedTemplateTypes();
  65. if (!in_array($templateType, $supportedTypes)) {
  66. throw new Exception("Error: $templateType is not supported.");
  67. }
  68. $id = $historyService->createTemplate($params);
  69. $this->view->url = $this->view->baseUrl("Playouthistorytemplate/configure-template/id/{$id}");
  70. }
  71. catch (Exception $e) {
  72. Logging::info($e);
  73. Logging::info($e->getMessage());
  74. $this->view->error = $e->getMessage();
  75. }
  76. }
  77. public function setTemplateDefaultAction()
  78. {
  79. $templateId = $this->_getParam('id', null);
  80. try {
  81. $historyService = new Application_Service_HistoryService();
  82. $historyService->setConfiguredTemplate($templateId);
  83. }
  84. catch (Exception $e) {
  85. Logging::info($e);
  86. Logging::info($e->getMessage());
  87. }
  88. }
  89. public function updateTemplateAction()
  90. {
  91. $templateId = $this->_getParam('id', null);
  92. $name = $this->_getParam('name', null);
  93. $fields = $this->_getParam('fields', array());
  94. try {
  95. $historyService = new Application_Service_HistoryService();
  96. $historyService->updateItemTemplate($templateId, $name, $fields);
  97. }
  98. catch (Exception $e) {
  99. Logging::info($e);
  100. Logging::info($e->getMessage());
  101. }
  102. }
  103. public function deleteTemplateAction()
  104. {
  105. $templateId = $this->_getParam('id');
  106. try {
  107. $historyService = new Application_Service_HistoryService();
  108. $historyService->deleteTemplate($templateId);
  109. }
  110. catch (Exception $e) {
  111. Logging::info($e);
  112. Logging::info($e->getMessage());
  113. }
  114. }
  115. }