PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/app/plugins/javan/controllers/groups_controller.php

https://github.com/ata/steak
PHP | 68 lines | 60 code | 7 blank | 1 comment | 12 complexity | 3323ee70315769fd8b288d6ab863ab28 MD5 | raw file
  1. <?php
  2. class GroupsController extends JavanAppController {
  3. var $name = 'Groups';
  4. var $helpers = array('Html', 'Form');
  5. function index() {
  6. $this->Group->recursive = 0;
  7. $this->set('groups', $this->paginate());
  8. }
  9. function view($id = null) {
  10. if (!$id) {
  11. $this->Session->setFlash(__('Invalid Group.', true));
  12. $this->redirect(array('action'=>'index'));
  13. }
  14. $this->set('group', $this->Group->read(null, $id));
  15. }
  16. function add() {
  17. if (!empty($this->data)) {
  18. $this->Group->create();
  19. if ($this->Group->save($this->data)) {
  20. $this->Session->setFlash(__('The Group has been saved', true));
  21. $this->redirect(array('action'=>'index'));
  22. } else {
  23. $this->Session->setFlash(__('The Group could not be saved. Please, try again.', true));
  24. }
  25. }
  26. $links = $this->Group->Link->find('list');
  27. $parents = $this->Group->Parent->find('list');
  28. $this->set(compact('links', 'parents'));
  29. }
  30. function edit($id = null) {
  31. if (!$id && empty($this->data)) {
  32. $this->Session->setFlash(__('Invalid Group', true));
  33. $this->redirect(array('action'=>'index'));
  34. }
  35. if (!empty($this->data)) {
  36. if ($this->Group->save($this->data)) {
  37. $this->Session->setFlash(__('The Group has been saved', true));
  38. //$this->redirect(array('action'=>'index'));
  39. } else {
  40. $this->Session->setFlash(__('The Group could not be saved. Please, try again.', true));
  41. }
  42. }
  43. if (empty($this->data)) {
  44. $this->data = $this->Group->read(null, $id);
  45. }
  46. $links = $this->Group->Link->find('list');
  47. $parents = $this->Group->Parent->find('list');
  48. $this->set(compact('links','parents'));
  49. }
  50. function delete($id = null) {
  51. if (!$id) {
  52. $this->Session->setFlash(__('Invalid id for Group', true));
  53. $this->redirect(array('action'=>'index'));
  54. }
  55. if ($this->Group->del($id)) {
  56. $this->Session->setFlash(__('Group deleted', true));
  57. $this->redirect(array('action'=>'index'));
  58. }
  59. }
  60. }
  61. ?>