/app/Controller/ProgramsController.php

https://bitbucket.org/projectangelfaces/project-angel-faces · PHP · 254 lines · 159 code · 11 blank · 84 comment · 20 complexity · 76b21d2b27068f38c8d1012d1f8e2cfc MD5 · raw file

  1. <?php
  2. App::uses('AppController', 'Controller');
  3. /**
  4. * Programs Controller
  5. *
  6. * PHP 5
  7. *
  8. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  9. * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
  10. *
  11. * PAF : Rapid Development Framework for Project Angel Faces. (http://projectangelfaces.org)
  12. * Copyright 2013, Project Angel Faces. (http://projectangelfaces.org)
  13. *
  14. *
  15. * @copyright Copyright 2013, Project Angel Faces. (http://projectangelfaces.org)
  16. * @link http://projectangelfaces.org Project Angel Faces
  17. * @package App.Controllers
  18. * @since PAF v 1.0
  19. *
  20. *
  21. * @property Program $Program
  22. */
  23. class ProgramsController extends AppController
  24. {
  25. /**
  26. * index method
  27. *
  28. * @return void
  29. */
  30. public function index()
  31. {
  32. $this->Program->recursive = 0;
  33. $this->set('programs', $this->paginate());
  34. }
  35. /**
  36. * view method
  37. *
  38. * @throws NotFoundException
  39. * @param string $id
  40. * @return void
  41. */
  42. public function view($id = null)
  43. {
  44. $this->Program->id = $id;
  45. if (!$this->Program->exists())
  46. {
  47. throw new NotFoundException(__('Invalid program'));
  48. }
  49. $this->set('program', $this->Program->read(null, $id));
  50. }
  51. /**
  52. * add method
  53. *
  54. * @return void
  55. */
  56. public function add()
  57. {
  58. if ($this->request->is('post'))
  59. {
  60. $this->Program->create();
  61. if ($this->Program->save($this->request->data))
  62. {
  63. $this->Session->setFlash(__('The program has been saved'));
  64. $this->redirect(array('action' => 'index'));
  65. }
  66. else
  67. {
  68. $this->Session->setFlash(__('The program could not be saved. Please, try again.'));
  69. }
  70. }
  71. $profiles = $this->Program->Profile->find('list');
  72. $this->set(compact('profiles'));
  73. }
  74. /**
  75. * edit method
  76. *
  77. * @throws NotFoundException
  78. * @param string $id
  79. * @return void
  80. */
  81. public function edit($id = null)
  82. {
  83. $this->Program->id = $id;
  84. if (!$this->Program->exists())
  85. {
  86. throw new NotFoundException(__('Invalid program'));
  87. }
  88. if ($this->request->is('post') || $this->request->is('put'))
  89. {
  90. if ($this->Program->save($this->request->data))
  91. {
  92. $this->Session->setFlash(__('The program has been saved'));
  93. $this->redirect(array('action' => 'index'));
  94. }
  95. else
  96. {
  97. $this->Session->setFlash(__('The program could not be saved. Please, try again.'));
  98. }
  99. }
  100. else
  101. {
  102. $this->request->data = $this->Program->read(null, $id);
  103. }
  104. $profiles = $this->Program->Profile->find('list');
  105. $this->set(compact('profiles'));
  106. }
  107. /**
  108. * delete method
  109. *
  110. * @throws MethodNotAllowedException
  111. * @throws NotFoundException
  112. * @param string $id
  113. * @return void
  114. */
  115. public function delete($id = null)
  116. {
  117. if (!$this->request->is('post'))
  118. {
  119. throw new MethodNotAllowedException();
  120. }
  121. $this->Program->id = $id;
  122. if (!$this->Program->exists())
  123. {
  124. throw new NotFoundException(__('Invalid program'));
  125. }
  126. if ($this->Program->delete())
  127. {
  128. $this->Session->setFlash(__('Program deleted'));
  129. $this->redirect(array('action' => 'index'));
  130. }
  131. $this->Session->setFlash(__('Program was not deleted'));
  132. $this->redirect(array('action' => 'index'));
  133. }
  134. /**
  135. * admin_index method
  136. *
  137. * @return void
  138. */
  139. public function admin_index()
  140. {
  141. $this->Program->recursive = 0;
  142. $this->set('programs', $this->paginate());
  143. }
  144. /**
  145. * admin_view method
  146. *
  147. * @throws NotFoundException
  148. * @param string $id
  149. * @return void
  150. */
  151. public function admin_view($id = null)
  152. {
  153. $this->Program->id = $id;
  154. if (!$this->Program->exists())
  155. {
  156. throw new NotFoundException(__('Invalid program'));
  157. }
  158. $this->set('program', $this->Program->read(null, $id));
  159. }
  160. /**
  161. * admin_add method
  162. *
  163. * @return void
  164. */
  165. public function admin_add()
  166. {
  167. if ($this->request->is('post'))
  168. {
  169. $this->Program->create();
  170. if ($this->Program->save($this->request->data))
  171. {
  172. $this->Session->setFlash(__('The program has been saved'));
  173. $this->redirect(array('action' => 'index'));
  174. }
  175. else
  176. {
  177. $this->Session->setFlash(__('The program could not be saved. Please, try again.'));
  178. }
  179. }
  180. $profiles = $this->Program->Profile->find('list');
  181. $this->set(compact('profiles'));
  182. }
  183. /**
  184. * admin_edit method
  185. *
  186. * @throws NotFoundException
  187. * @param string $id
  188. * @return void
  189. */
  190. public function admin_edit($id = null)
  191. {
  192. $this->Program->id = $id;
  193. if (!$this->Program->exists())
  194. {
  195. throw new NotFoundException(__('Invalid program'));
  196. }
  197. if ($this->request->is('post') || $this->request->is('put'))
  198. {
  199. if ($this->Program->save($this->request->data))
  200. {
  201. $this->Session->setFlash(__('The program has been saved'));
  202. $this->redirect(array('action' => 'index'));
  203. }
  204. else
  205. {
  206. $this->Session->setFlash(__('The program could not be saved. Please, try again.'));
  207. }
  208. }
  209. else
  210. {
  211. $this->request->data = $this->Program->read(null, $id);
  212. }
  213. $profiles = $this->Program->Profile->find('list');
  214. $this->set(compact('profiles'));
  215. }
  216. /**
  217. * admin_delete method
  218. *
  219. * @throws MethodNotAllowedException
  220. * @throws NotFoundException
  221. * @param string $id
  222. * @return void
  223. */
  224. public function admin_delete($id = null)
  225. {
  226. if (!$this->request->is('post'))
  227. {
  228. throw new MethodNotAllowedException();
  229. }
  230. $this->Program->id = $id;
  231. if (!$this->Program->exists())
  232. {
  233. throw new NotFoundException(__('Invalid program'));
  234. }
  235. if ($this->Program->delete())
  236. {
  237. $this->Session->setFlash(__('Program deleted'));
  238. $this->redirect(array('action' => 'index'));
  239. }
  240. $this->Session->setFlash(__('Program was not deleted'));
  241. $this->redirect(array('action' => 'index'));
  242. }
  243. }