/administrator/components/com_menus/controllers/items.php

https://bitbucket.org/eternaware/joomus · PHP · 154 lines · 84 code · 19 blank · 51 comment · 12 complexity · b9d9c449c37280d4e8f2d72d3bfeb3bf MD5 · raw file

  1. <?php
  2. /**
  3. * @package Joomla.Administrator
  4. * @subpackage com_menus
  5. *
  6. * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE.txt
  8. */
  9. defined('_JEXEC') or die;
  10. /**
  11. * The Menu Item Controller
  12. *
  13. * @package Joomla.Administrator
  14. * @subpackage com_menus
  15. * @since 1.6
  16. */
  17. class MenusControllerItems extends JControllerAdmin
  18. {
  19. public function __construct($config = array())
  20. {
  21. parent::__construct($config);
  22. $this->registerTask('unsetDefault', 'setDefault');
  23. }
  24. /**
  25. * Proxy for getModel
  26. * @since 1.6
  27. */
  28. public function getModel($name = 'Item', $prefix = 'MenusModel', $config = array())
  29. {
  30. return parent::getModel($name, $prefix, array('ignore_request' => true));
  31. }
  32. /**
  33. * Rebuild the nested set tree.
  34. *
  35. * @return bool False on failure or error, true on success.
  36. * @since 1.6
  37. */
  38. public function rebuild()
  39. {
  40. JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
  41. $this->setRedirect('index.php?option=com_menus&view=items');
  42. $model = $this->getModel();
  43. if ($model->rebuild()) {
  44. // Reorder succeeded.
  45. $this->setMessage(JText::_('COM_MENUS_ITEMS_REBUILD_SUCCESS'));
  46. return true;
  47. } else {
  48. // Rebuild failed.
  49. $this->setMessage(JText::sprintf('COM_MENUS_ITEMS_REBUILD_FAILED'));
  50. return false;
  51. }
  52. }
  53. public function saveorder()
  54. {
  55. JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
  56. // Get the arrays from the Request
  57. $order = $this->input->post->get('order', null, 'array');
  58. $originalOrder = explode(',', $this->input->getString('original_order_values'));
  59. // Make sure something has changed
  60. if (!($order === $originalOrder))
  61. {
  62. parent::saveorder();
  63. }
  64. else
  65. {
  66. // Nothing to reorder
  67. $this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_list, false));
  68. return true;
  69. }
  70. }
  71. /**
  72. * Method to set the home property for a list of items
  73. *
  74. * @since 1.6
  75. */
  76. public function setDefault()
  77. {
  78. // Check for request forgeries
  79. JSession::checkToken('request') or die(JText::_('JINVALID_TOKEN'));
  80. // Get items to publish from the request.
  81. $cid = $this->input->get('cid', array(), 'array');
  82. $data = array('setDefault' => 1, 'unsetDefault' => 0);
  83. $task = $this->getTask();
  84. $value = JArrayHelper::getValue($data, $task, 0, 'int');
  85. if (empty($cid)) {
  86. JError::raiseWarning(500, JText::_($this->text_prefix.'_NO_ITEM_SELECTED'));
  87. } else {
  88. // Get the model.
  89. $model = $this->getModel();
  90. // Make sure the item ids are integers
  91. JArrayHelper::toInteger($cid);
  92. // Publish the items.
  93. if (!$model->setHome($cid, $value)) {
  94. JError::raiseWarning(500, $model->getError());
  95. } else {
  96. if ($value == 1) {
  97. $ntext = 'COM_MENUS_ITEMS_SET_HOME';
  98. }
  99. else {
  100. $ntext = 'COM_MENUS_ITEMS_UNSET_HOME';
  101. }
  102. $this->setMessage(JText::plural($ntext, count($cid)));
  103. }
  104. }
  105. $this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_list, false));
  106. }
  107. /**
  108. * Method to save the submitted ordering values for records via AJAX.
  109. *
  110. * @return void
  111. *
  112. * @since 3.0
  113. */
  114. public function saveOrderAjax()
  115. {
  116. JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
  117. // Get the arrays from the Request
  118. $pks = $this->input->post->get('cid', null, 'array');
  119. $order = $this->input->post->get('order', null, 'array');
  120. $originalOrder = explode(',', $this->input->getString('original_order_values'));
  121. // Make sure something has changed
  122. if (!($order === $originalOrder)) {
  123. // Get the model
  124. $model = $this->getModel();
  125. // Save the ordering
  126. $return = $model->saveorder($pks, $order);
  127. if ($return)
  128. {
  129. echo "1";
  130. }
  131. }
  132. // Close the application
  133. JFactory::getApplication()->close();
  134. }
  135. }