/Taxonomy/Controller/VocabulariesController.php

https://github.com/kareypowell/croogo · PHP · 158 lines · 76 code · 18 blank · 64 comment · 16 complexity · 60c4db132eed2d75a9a40bacdc152b9c MD5 · raw file

  1. <?php
  2. App::uses('TaxonomyAppController', 'Taxonomy.Controller');
  3. /**
  4. * Vocabularies Controller
  5. *
  6. * @category Taxonomy.Controller
  7. * @package Croogo
  8. * @version 1.0
  9. * @author Fahad Ibnay Heylaal <contact@fahad19.com>
  10. * @license http://www.opensource.org/licenses/mit-license.php The MIT License
  11. * @link http://www.croogo.org
  12. */
  13. class VocabulariesController extends TaxonomyAppController {
  14. /**
  15. * Controller name
  16. *
  17. * @var string
  18. * @access public
  19. */
  20. public $name = 'Vocabularies';
  21. /**
  22. * Models used by the Controller
  23. *
  24. * @var array
  25. * @access public
  26. */
  27. public $uses = array('Taxonomy.Vocabulary');
  28. /**
  29. * Admin index
  30. *
  31. * @return void
  32. * @access public
  33. */
  34. public function admin_index() {
  35. $this->set('title_for_layout', __d('croogo', 'Vocabularies'));
  36. $this->Vocabulary->recursive = 0;
  37. $this->paginate['Vocabulary']['order'] = 'Vocabulary.weight ASC';
  38. $this->set('vocabularies', $this->paginate());
  39. }
  40. /**
  41. * Admin add
  42. *
  43. * @return void
  44. * @access public
  45. */
  46. public function admin_add() {
  47. $this->set('title_for_layout', __d('croogo', 'Add Vocabulary'));
  48. if (!empty($this->request->data)) {
  49. $this->Vocabulary->create();
  50. if ($this->Vocabulary->save($this->request->data)) {
  51. $this->Session->setFlash(__d('croogo', 'The Vocabulary has been saved'), 'default', array('class' => 'success'));
  52. return $this->redirect(array('action' => 'index'));
  53. } else {
  54. $this->Session->setFlash(__d('croogo', 'The Vocabulary could not be saved. Please, try again.'), 'default', array('class' => 'error'));
  55. }
  56. }
  57. $types = $this->Vocabulary->Type->pluginTypes();
  58. $this->set(compact('types'));
  59. }
  60. /**
  61. * Admin edit
  62. *
  63. * @param integer $id
  64. * @return void
  65. * @access public
  66. */
  67. public function admin_edit($id = null) {
  68. $this->set('title_for_layout', __d('croogo', 'Edit Vocabulary'));
  69. if (!$id && empty($this->request->data)) {
  70. $this->Session->setFlash(__d('croogo', 'Invalid Vocabulary'), 'default', array('class' => 'error'));
  71. return $this->redirect(array('action' => 'index'));
  72. }
  73. if (!empty($this->request->data)) {
  74. if ($this->Vocabulary->save($this->request->data)) {
  75. $this->Session->setFlash(__d('croogo', 'The Vocabulary has been saved'), 'default', array('class' => 'success'));
  76. return $this->Croogo->redirect(array('action' => 'edit', $this->Vocabulary->id));
  77. } else {
  78. $this->Session->setFlash(__d('croogo', 'The Vocabulary could not be saved. Please, try again.'), 'default', array('class' => 'error'));
  79. }
  80. }
  81. if (empty($this->request->data)) {
  82. $this->request->data = $this->Vocabulary->read(null, $id);
  83. }
  84. $plugin = null;
  85. if (isset($this->request->data['Vocabulary']['plugin'])) {
  86. $plugin = $this->request->data['Vocabulary']['plugin'];
  87. }
  88. $types = $this->Vocabulary->Type->pluginTypes($plugin);
  89. $this->set(compact('types'));
  90. }
  91. /**
  92. * Admin delete
  93. *
  94. * @param integer $id
  95. * @return void
  96. * @access public
  97. */
  98. public function admin_delete($id = null) {
  99. if (!$id) {
  100. $this->Session->setFlash(__d('croogo', 'Invalid id for Vocabulary'), 'default', array('class' => 'error'));
  101. return $this->redirect(array('action' => 'index'));
  102. }
  103. if ($this->Vocabulary->delete($id)) {
  104. $this->Session->setFlash(__d('croogo', 'Vocabulary deleted'), 'default', array('class' => 'success'));
  105. return $this->redirect(array('action' => 'index'));
  106. }
  107. }
  108. /**
  109. * Admin moveup
  110. *
  111. * @param integer $id
  112. * @param integer $step
  113. * @return void
  114. * @access public
  115. */
  116. public function admin_moveup($id, $step = 1) {
  117. if ($this->Vocabulary->moveUp($id, $step)) {
  118. $this->Session->setFlash(__d('croogo', 'Moved up successfully'), 'default', array('class' => 'success'));
  119. } else {
  120. $this->Session->setFlash(__d('croogo', 'Could not move up'), 'default', array('class' => 'error'));
  121. }
  122. return $this->redirect(array('action' => 'index'));
  123. }
  124. /**
  125. * Admin moveup
  126. *
  127. * @param integer $id
  128. * @param integer $step
  129. * @return void
  130. * @access public
  131. */
  132. public function admin_movedown($id, $step = 1) {
  133. if ($this->Vocabulary->moveDown($id, $step)) {
  134. $this->Session->setFlash(__d('croogo', 'Moved down successfully'), 'default', array('class' => 'success'));
  135. } else {
  136. $this->Session->setFlash(__d('croogo', 'Could not move down'), 'default', array('class' => 'error'));
  137. }
  138. return $this->redirect(array('action' => 'index'));
  139. }
  140. }