PageRenderTime 53ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/Settings/Controller/LanguagesController.php

https://github.com/kareypowell/croogo
PHP | 172 lines | 82 code | 18 blank | 72 comment | 18 complexity | 8a1578dbb939eafc0502e8786df7bd58 MD5 | raw file
  1. <?php
  2. App::uses('SettingsAppController', 'Settings.Controller');
  3. /**
  4. * Languages Controller
  5. *
  6. * @category Settings.Controller
  7. * @package Croogo.Settings
  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 LanguagesController extends SettingsAppController {
  14. /**
  15. * Controller name
  16. *
  17. * @var string
  18. * @access public
  19. */
  20. public $name = 'Languages';
  21. /**
  22. * Models used by the Controller
  23. *
  24. * @var array
  25. * @access public
  26. */
  27. public $uses = array('Settings.Language');
  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', 'Languages'));
  36. $this->Language->recursive = 0;
  37. $this->paginate['Language']['order'] = 'Language.weight ASC';
  38. $this->set('languages', $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 Language"));
  48. if (!empty($this->request->data)) {
  49. $this->Language->create();
  50. if ($this->Language->save($this->request->data)) {
  51. $this->Session->setFlash(__d('croogo', 'The Language has been saved'), 'default', array('class' => 'success'));
  52. return $this->redirect(array('action' => 'index'));
  53. } else {
  54. $this->Session->setFlash(__d('croogo', 'The Language could not be saved. Please, try again.'), 'default', array('class' => 'error'));
  55. }
  56. }
  57. }
  58. /**
  59. * Admin edit
  60. *
  61. * @param integer $id
  62. * @return void
  63. * @access public
  64. */
  65. public function admin_edit($id = null) {
  66. $this->set('title_for_layout', __d('croogo', "Edit Language"));
  67. if (!$id && empty($this->request->data)) {
  68. $this->Session->setFlash(__d('croogo', 'Invalid Language'), 'default', array('class' => 'error'));
  69. return $this->redirect(array('action' => 'index'));
  70. }
  71. if (!empty($this->request->data)) {
  72. if ($this->Language->save($this->request->data)) {
  73. $this->Session->setFlash(__d('croogo', 'The Language has been saved'), 'default', array('class' => 'success'));
  74. return $this->redirect(array('action' => 'index'));
  75. } else {
  76. $this->Session->setFlash(__d('croogo', 'The Language could not be saved. Please, try again.'), 'default', array('class' => 'error'));
  77. }
  78. }
  79. if (empty($this->request->data)) {
  80. $this->request->data = $this->Language->read(null, $id);
  81. }
  82. }
  83. /**
  84. * Admin delete
  85. *
  86. * @param integer $id
  87. * @return void
  88. * @access public
  89. */
  90. public function admin_delete($id = null) {
  91. if (!$id) {
  92. $this->Session->setFlash(__d('croogo', 'Invalid id for Language'), 'default', array('class' => 'error'));
  93. return $this->redirect(array('action' => 'index'));
  94. }
  95. if ($this->Language->delete($id)) {
  96. $this->Session->setFlash(__d('croogo', 'Language deleted'), 'default', array('class' => 'success'));
  97. return $this->redirect(array('action' => 'index'));
  98. }
  99. }
  100. /**
  101. * Admin moveup
  102. *
  103. * @param integer $id
  104. * @param integer $step
  105. * @return void
  106. * @access public
  107. */
  108. public function admin_moveup($id, $step = 1) {
  109. if ($this->Language->moveUp($id, $step)) {
  110. $this->Session->setFlash(__d('croogo', 'Moved up successfully'), 'default', array('class' => 'success'));
  111. } else {
  112. $this->Session->setFlash(__d('croogo', 'Could not move up'), 'default', array('class' => 'error'));
  113. }
  114. return $this->redirect(array('action' => 'index'));
  115. }
  116. /**
  117. * Admin movedown
  118. *
  119. * @param integer $id
  120. * @param integer $step
  121. * @return void
  122. * @access public
  123. */
  124. public function admin_movedown($id, $step = 1) {
  125. if ($this->Language->moveDown($id, $step)) {
  126. $this->Session->setFlash(__d('croogo', 'Moved down successfully'), 'default', array('class' => 'success'));
  127. } else {
  128. $this->Session->setFlash(__d('croogo', 'Could not move down'), 'default', array('class' => 'error'));
  129. }
  130. return $this->redirect(array('action' => 'index'));
  131. }
  132. /**
  133. * Admin select
  134. *
  135. * @param integer $id
  136. * @param string $modelAlias
  137. * @return void
  138. * @access public
  139. */
  140. public function admin_select($id = null, $modelAlias = null) {
  141. if ($id == null ||
  142. $modelAlias == null) {
  143. return $this->redirect(array('action' => 'index'));
  144. }
  145. $this->set('title_for_layout', __d('croogo', 'Select a language'));
  146. $languages = $this->Language->find('all', array(
  147. 'conditions' => array(
  148. 'Language.status' => 1,
  149. ),
  150. 'order' => 'Language.weight ASC',
  151. ));
  152. $this->set(compact('id', 'modelAlias', 'languages'));
  153. }
  154. }