/application/controllers/PlantController.php

https://github.com/karthikprashanth/mayalabs · PHP · 236 lines · 208 code · 26 blank · 2 comment · 28 complexity · e1c8061e8e03d7956ed8d1b003dc3501 MD5 · raw file

  1. <?php
  2. class PlantController extends Zend_Controller_Action {
  3. public function init() {
  4. }
  5. public function indexAction() {
  6. try {
  7. $up = new Model_DbTable_Userprofile();
  8. $up = $up->getUser(Zend_Auth::getInstance()->getStorage()->read()->id);
  9. $pid = $up['plantId'];
  10. $this->_redirect("/plant/view?id=$pid");
  11. } catch (Exception $e) {
  12. echo $e;
  13. }
  14. }
  15. public function addAction() {
  16. try {
  17. $this->view->headTitle('Add Plant', 'PREPEND');
  18. $form = new Form_PlantForm();
  19. $form->setMode("add");
  20. $form->showForm();
  21. $form->partPlant3->submit->setLabel('Add');
  22. //JQuery Form Enable
  23. ZendX_JQuery::enableForm($form);
  24. $this->view->form = $form;
  25. if ($this->getRequest()->isPost()) {
  26. $formData = $this->getRequest()->getPost();
  27. if ($form->isValid($formData)) {
  28. $userp = new Model_DbTable_Plant();
  29. $content = $form->getValues();
  30. $content = array_merge($content['partPlant1'], $content['partPlant2'], $content['partPlant3']);
  31. $grplant = $userp->fetchAll();
  32. $corp = false;
  33. foreach ($grplant as $g) {
  34. if ($g['corporateName'] == $content['corporateName']) {
  35. $corp = true;
  36. }
  37. }
  38. if ($corp) {
  39. $grplant = $userp->fetchAll("corporateName = '" . $content['corporateName'] . "'");
  40. foreach ($grplant as $c) {
  41. if ($c['plantName'] == $content['plantName']) {
  42. $this->view->message = "Plant name already exists";
  43. return;
  44. }
  45. }
  46. }
  47. $plantid = $userp->add($content);
  48. $myuser = Zend_Auth::getInstance()->getStorage()->read()->id;
  49. Zend_Registry::set('id', $myuser);
  50. $this->_redirect('plant/view?id=' . $plantid);
  51. } else {
  52. $form->populate($formData);
  53. }
  54. }
  55. } catch (Exception $e) {
  56. echo $e;
  57. }
  58. }
  59. public function viewAction() {
  60. try {
  61. $role = Zend_Registry::get('role');
  62. $id = $this->_getParam('id');
  63. $PView = new Model_DbTable_Plant();
  64. $PData = $PView->getPlant($id);
  65. $this->view->id = $id;
  66. $this->view->headTitle("View Plant " . $GTData['corporateName'], 'PREPEND');
  67. foreach($PData as $key=>$value)
  68. {
  69. if((is_int($value) && $value == 0) || $value == "")
  70. {
  71. $PData[$key] = '-';
  72. }
  73. }
  74. $this->view->plantData = $PData;
  75. } catch (Exception $e) {
  76. echo $e;
  77. }
  78. }
  79. public function editAction() {
  80. $this->view->headTitle('Edit Plant', 'PREPEND');
  81. try {
  82. $form = new Form_PlantForm();
  83. $form->setMode("edit");
  84. $form->showForm();
  85. //JQuery Form Enable
  86. ZendX_JQuery::enableForm($form);
  87. $form->partPlant3->submit->setLabel('Save');
  88. $form->partPlant3->submit->setAttrib('class', 'user-save');
  89. $this->view->form = $form;
  90. $this->view->plantId = $this->_getParam('id', 0);
  91. if ($this->getRequest()->isPost()) {
  92. $formData = $this->getRequest()->getPost();
  93. if ($form->isValid($formData)) {
  94. $GT = new Model_DbTable_Plant();
  95. $plantDet = $GT->getPlant($this->_getParam('id', 0));
  96. $plantId = $this->_getParam('id', 0);
  97. $this->view->plantId = $plantId;
  98. $content = array_merge($form->partPlant1->getValues(), $form->partPlant2->getValues(), $form->partPlant3->getValues());
  99. if (count(array_diff($content, $plantDet)) > 0) {
  100. $nf = new Model_DbTable_Notification();
  101. $nf->add($plantId, 'plant', 0);
  102. $GT->updatePlant($plantId, $content);
  103. }
  104. if ($this->getRequest()->getPost("modeselect") == "redirect") {
  105. $this->_redirect('plant/view?id=' . $plantId);
  106. }
  107. if ($this->getRequest()->getPost("modeselect") == "stay1") {
  108. $this->_redirect('plant/edit?id=' . $plantId . '#tabContainer-frag-1');
  109. }
  110. if ($this->getRequest()->getPost("modeselect") == "stay2") {
  111. $this->_redirect('plant/edit?id=' . $plantId . '#tabContainer-frag-2');
  112. }
  113. if ($this->getRequest()->getPost("modeselect") == "stay3") {
  114. $this->_redirect('plant/edit?id=' . $plantId . '#tabContainer-frag-3');
  115. }
  116. } else {
  117. $form->populate($formData);
  118. }
  119. } else {
  120. $plantId = $this->_getParam('id', 0);
  121. $PlantVal = new Model_DbTable_Plant();
  122. $form->populate($PlantVal->getPlant($plantId));
  123. }
  124. } catch (exception $e) {
  125. echo $e;
  126. }
  127. }
  128. public function listAction() {
  129. try {
  130. $role = Zend_Registry::get('role');
  131. $this->view->headTitle('List Plants', 'PREPEND');
  132. $resultSet = new Model_DbTable_Plant();
  133. $resultSet = $resultSet->listPlants();
  134. $up = new Model_DbTable_Userprofile();
  135. $up = $up->getUser(Zend_Auth::getInstance()->getStorage()->read()->id);
  136. $pid = $up['plantId'];
  137. $Pdata = new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($resultSet));
  138. $Pdata->setItemCountPerPage(5)
  139. ->setCurrentPageNumber($this->_getParam('page', 1));
  140. $this->view->Pdata = $Pdata;
  141. $this->view->pid = $pid;
  142. } catch (Exception $e) {
  143. echo $e;
  144. }
  145. }
  146. public function adminAction() {
  147. try {
  148. $resultSet = new Model_DbTable_Plant();
  149. $resultSet = $resultSet->listPlants();
  150. $plants = new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($resultSet));
  151. $plants->setItemCountPerPage(5)
  152. ->setCurrentPageNumber($this->_getParam('page', 1));
  153. $this->view->plants = $plants;
  154. } catch (Exception $exc) {
  155. echo $exc;
  156. }
  157. }
  158. public function editvalidateAction() {
  159. try {
  160. $this->_helper->viewRenderer->setNoRender();
  161. $this->_helper->getHelper('layout')->disableLayout();
  162. $form = new Form_PlantForm();
  163. $formData = $this->getRequest()->getPost();
  164. $form->isValid($formData);
  165. $json = $form->getMessages();
  166. echo Zend_Json::encode($json);
  167. } catch (Exception $e) {
  168. echo $e;
  169. }
  170. }
  171. public function addvalidateAction() {
  172. try {
  173. $this->_helper->viewRenderer->setNoRender();
  174. $this->_helper->getHelper('layout')->disableLayout();
  175. $form = new Form_PlantForm();
  176. $formData = $this->getRequest()->getPost();
  177. $form->isValid($formData);
  178. $json = $form->partPlant1->getMessages();
  179. $json = array_merge($json, $form->partPlant2->getMessages());
  180. $json = array_merge($json, $form->partPlant3->getMessages());
  181. echo Zend_Json::encode($json);
  182. } catch (Exception $e) {
  183. echo $e;
  184. }
  185. }
  186. public function clistAction() {
  187. $pmodel = new Model_DbTable_Plant();
  188. $pdet = $pmodel->getPlantList();
  189. $this->view->pdet = $pdet;
  190. }
  191. public function resultsAction() {
  192. $this->_helper->getHelper('layout')->disableLayout();
  193. $term = $this->_getParam('term');
  194. $ll = $this->_getParam('ll');
  195. $ul = $this->_getParam('ul');
  196. $pmodel = new Model_DbTable_Plant();
  197. $results = $pmodel->getSearchResults($term);
  198. $this->view->term = $term;
  199. if ($term == NULL) {
  200. $select = $pmodel->select()->order('plantName');
  201. $results = $pmodel->getAllPlants();
  202. }
  203. $this->view->results = $results;
  204. $this->view->resultcount = $pmodel->getCount();
  205. $umodel = new Model_DbTable_Userprofile();
  206. $this->view->usermodel = $umodel;
  207. $this->view->ll = $ll;
  208. $this->view->ul = $ul;
  209. }
  210. }