icefusion

ControlerAjax

Oct 31st, 2012
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.61 KB | None | 0 0
  1. <?php
  2.  
  3. class Admin_PavilhaoController extends Zend_Controller_Action {
  4.  
  5. private $messages;
  6. private $obrigatorios;
  7. private $nomeFront;
  8. private $form;
  9. private $editData;
  10.  
  11. public function init() {
  12. if (!Zend_Auth::getInstance()->hasIdentity()) {
  13. return $this->redirect('/admin/auth');
  14. }
  15. $this->messages = new Icefusion_View_Helper_General_Message();
  16. $this->obrigatorios = array('name', 'url', 'status');
  17. $this->nomeFront = array('name' => 'Nome', 'url' => 'Url', 'status' => 'Status');
  18. $this->form = new Icefusion_View_Helper_Admin_Forms_Pavilhao();
  19. $url = new Icefusion_View_Helper_General_FullUrl();
  20. $this->view->cadastrar = $url->FullUrl('admin/pavilhao/add');
  21. $this->editData = new Zend_Session_Namespace('adm');
  22. }
  23.  
  24. public function indexAction() {
  25. $this->redirect('admin/pavilhao/list');
  26. }
  27.  
  28. public function addAction() {
  29. $this->view->form = $this->form->getFormCadastro($this->editData->data);
  30. unset($this->editData->data);
  31. $this->view->message = $this->messages->adminMessageSession->message;
  32. unset($this->messages->adminMessageSession->message);
  33. }
  34.  
  35. public function listAction() {
  36. if ($this->_request->isPost()) {
  37. $data = $this->_request->getPost();
  38. $actionUrl = explode('/', $data['gridAction_id']);
  39. $action = end($actionUrl);
  40. switch ($action) {
  41. case 'edit':
  42. $this->edit($data, $data['gridAction_id']);
  43. break;
  44. case 'delete':
  45. $this->delete($data, $data['gridAction_id']);
  46. break;
  47. }
  48. } else {
  49. $report = new Icefusion_View_Helper_Admin_Reports_Pavilhao();
  50. $this->view->report = $report->getReportTable();
  51. }
  52. }
  53.  
  54. public function importAction() {
  55. $this->view->formExp = $this->form->getFormExportar();
  56. }
  57.  
  58. public function exportAction() {
  59.  
  60. }
  61.  
  62. public function saveAction() {
  63. $form = new Icefusion_View_Helper_Admin_Forms_Pavilhao();
  64. if ($this->_request->isPost()) {
  65. $data = $this->_request->getPost();
  66. $invalido = $form->isValidated($data, $this->obrigatorios);
  67. if (!isset($invalido) || count($invalido) == 0) {
  68. unset($data['submit']);
  69. $data['update'] = date("Y-m-d");
  70. $pavilhao = new Application_Model_DbTable_Pavilhoes();
  71. if ($data['id'] == '') {
  72. unset($data['id']);
  73. $pavilhao->insert($data);
  74. unset($this->messages->adminMessageSession->message);
  75. $this->view->message = "";
  76. $this->messages->successSave();
  77. $this->redirect("admin/pavilhao/add");
  78. } else {
  79. $where = 'id = ' . $data['id'];
  80. $pavilhao->update($data, $where);
  81. unset($this->messages->adminMessageSession->message);
  82. $this->view->message = "";
  83. $this->messages->successEdit();
  84. $this->redirect("admin/pavilhao/add");
  85. }
  86. } else {
  87. unset($this->messages->adminMessageSession->message);
  88. $this->view->message = "";
  89. $this->messages->errorSave($invalido, $this->nomeFront);
  90. $this->_redirect("admin/pavilhao/add");
  91. }
  92. }
  93. }
  94.  
  95. public function getAddressAction() {
  96. $retorno->number = 25;
  97. $retorno->region = "teste";
  98. $this->_helper->json($retorno);
  99. }
  100.  
  101. private function edit($data, $retorno) {
  102. $ids = explode(',', $data['postMassIdsid']);
  103. if (count($ids) == 1) {
  104. $model = new Application_Model_Pavilhoes();
  105. $data = $model->getDataById($ids[0]);
  106. $this->editData->data = $data;
  107. $this->_redirect('admin/pavilhao/add');
  108. } else {
  109. $this->_redirect($retorno);
  110. }
  111. }
  112.  
  113. private function delete($data, $retorno) {
  114. $ids = explode(',', $data['postMassIdsid']);
  115. $categoria = new Application_Model_DbTable_Pavilhoes();
  116. foreach ($ids as $id) {
  117. try {
  118. $where = 'id = ' . $id;
  119. $categoria->delete($where);
  120. } catch (Exception $e) {
  121. print_r($e);
  122. die;
  123. }
  124. }
  125. $this->_redirect($retorno);
  126. }
  127.  
  128. }
Advertisement
Add Comment
Please, Sign In to add comment