PageRenderTime 43ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/application/modules/debug/controllers/CrontabController.php

https://code.google.com/p/zfcore/
PHP | 217 lines | 129 code | 16 blank | 72 comment | 9 complexity | 7d1af5e6860e820cd23edf8e14d8454f MD5 | raw file
  1. <?php
  2. /**
  3. * CrontabController for debug module
  4. *
  5. * @category Application
  6. * @package Debug
  7. * @subpackage Crontab
  8. *
  9. * @author Anna Pavlova <pavlova.anna@nixsolutions.com>
  10. */
  11. class Debug_CrontabController extends Core_Controller_Action_Crud
  12. {
  13. /**
  14. * _prepareHeader
  15. *
  16. * @return Debug_CrontabController
  17. */
  18. protected function _prepareHeader()
  19. {
  20. $this->_addCreateButton();
  21. return $this;
  22. }
  23. /**
  24. * _prepareGrid
  25. *
  26. * @return Debug_CrontabController
  27. */
  28. protected function _prepareGrid()
  29. {
  30. $this->_addAllTableColumns();
  31. $this->_addEditColumn();
  32. $this->_addDeleteColumn();
  33. return $this;
  34. }
  35. /**
  36. * get source
  37. *
  38. * @return Core_Grid_Adapter_AdapterInterface
  39. */
  40. protected function _getSource()
  41. {
  42. $manager = new Debug_Model_Crontab_Manager();
  43. return new Core_Grid_Adapter_Array($manager->createGritArray());
  44. }
  45. /**
  46. * get table
  47. *
  48. * @return void
  49. */
  50. protected function _getTable()
  51. {
  52. }
  53. /**
  54. * add all columns to grid
  55. *
  56. * @return void
  57. */
  58. public function _addAllTableColumns()
  59. {
  60. $this->_grid->setColumn(
  61. 'minute', array(
  62. 'name' => 'Minute',
  63. 'type' => Core_Grid::TYPE_DATA,
  64. 'index' => 'minute'
  65. )
  66. )->setColumn(
  67. 'hour',
  68. array(
  69. 'name' => 'Hour',
  70. 'type' => Core_Grid::TYPE_DATA,
  71. 'index' => 'hour'
  72. )
  73. )->setColumn(
  74. 'dayOfMonth',
  75. array(
  76. 'name' => 'Day of month',
  77. 'type' => Core_Grid::TYPE_DATA,
  78. 'index' => 'dayOfMonth'
  79. )
  80. )->setColumn(
  81. 'month',
  82. array(
  83. 'name' => 'Month',
  84. 'type' => Core_Grid::TYPE_DATA,
  85. 'index' => 'month'
  86. )
  87. )->setColumn(
  88. 'dayOfWeek',
  89. array(
  90. 'name' => 'Day of week',
  91. 'type' => Core_Grid::TYPE_DATA,
  92. 'index' => 'dayOfWeek'
  93. )
  94. )->setColumn(
  95. 'command',
  96. array(
  97. 'name' => 'Command',
  98. 'type' => Core_Grid::TYPE_DATA,
  99. 'index' => 'command'
  100. )
  101. );
  102. }
  103. /**
  104. * _getCreateForm
  105. *
  106. * return create form for scaffolding
  107. *
  108. * @return Zend_Form
  109. */
  110. protected function _getCreateForm()
  111. {
  112. return new Debug_Model_Crontab_Form_Create();
  113. }
  114. /**
  115. * _getEditForm
  116. *
  117. * return edit form for scaffolding
  118. *
  119. * @return Zend_Form
  120. */
  121. protected function _getEditForm()
  122. {
  123. return new Debug_Model_Crontab_Form_Edit();
  124. }
  125. /**
  126. * createAction
  127. *
  128. * create page instance
  129. *
  130. * @return void
  131. */
  132. public function createAction()
  133. {
  134. $this->_changeViewScriptPathSpec();
  135. $manager = new Debug_Model_Crontab_Manager();
  136. $form = $this->_getCreateForm()->setAction($this->view->url());
  137. if ($this->_request->isPost() &&
  138. $form->isValid($this->_getAllParams())) {
  139. if ($manager->save($form->getValues())) {
  140. $this->_flashMessenger->addMessage('Successfully!');
  141. } else {
  142. $this->_flashMessenger->addMessage('Failed! Please check settings of crontab manager.');
  143. }
  144. $this->_helper->redirector('index');
  145. } elseif ($this->_request->isPost()) {
  146. // show errors
  147. $errors = $form->getErrors();
  148. foreach ($errors as $fn => $error) {
  149. if (empty($error)) continue;
  150. $el = $form->getElement($fn);
  151. $dec = $el->getDecorator('HtmlTag');
  152. $cls = $dec->getOption('class');
  153. $dec->setOption('class', $cls .' error');
  154. }
  155. }
  156. $this->view->form = $form;
  157. }
  158. /**
  159. * editAction
  160. *
  161. * edit page instance
  162. *
  163. * @return void
  164. */
  165. public function editAction()
  166. {
  167. if (!$id = $this->_getParam('id')) {
  168. throw new Zend_Controller_Action_Exception('Bad Request');
  169. }
  170. $manager = new Debug_Model_Crontab_Manager();
  171. $form = $this->_getEditForm()->setAction($this->view->url());
  172. if ($this->_request->isPost() &&
  173. $form->isValid($this->_getAllParams())) {
  174. // valid
  175. if ($manager->save($form->getValues(), $id)) {
  176. $this->_flashMessenger->addMessage('Successfully!');
  177. } else {
  178. $this->_flashMessenger->addMessage('Failed!');
  179. }
  180. $this->_helper->redirector('index');
  181. }
  182. // check if there is data in form
  183. $form->setDefaults($manager->getLineById($id));
  184. $this->view->form = $form;
  185. }
  186. /**
  187. * deleteAction
  188. *
  189. * delete variable from Session
  190. *
  191. * @return json
  192. */
  193. public function deleteAction()
  194. {
  195. if (!$id = $this->_getParam('id')) {
  196. throw new Zend_Controller_Action_Exception('Bad Request');
  197. }
  198. $manager = new Debug_Model_Crontab_Manager();
  199. $this->_helper->json($manager->delete($id));
  200. }
  201. }