/administrator/components/com_categories/controllers/categories.php

https://bitbucket.org/kraymitchell/fcd · PHP · 85 lines · 37 code · 10 blank · 38 comment · 4 complexity · e996952fd4c056f63bdc6dfecd09100e MD5 · raw file

  1. <?php
  2. /**
  3. * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
  4. * @license GNU General Public License version 2 or later; see LICENSE.txt
  5. */
  6. defined('_JEXEC') or die;
  7. jimport('joomla.application.component.controlleradmin');
  8. /**
  9. * The Categories List Controller
  10. *
  11. * @package Joomla.Administrator
  12. * @subpackage com_categories
  13. * @since 1.6
  14. */
  15. class CategoriesControllerCategories extends JControllerAdmin
  16. {
  17. /**
  18. * Proxy for getModel
  19. *
  20. * @param string $name The model name. Optional.
  21. * @param string $prefix The class prefix. Optional.
  22. *
  23. * @return object The model.
  24. * @since 1.6
  25. */
  26. function getModel($name = 'Category', $prefix = 'CategoriesModel', $config = array('ignore_request' => true))
  27. {
  28. $model = parent::getModel($name, $prefix, $config);
  29. return $model;
  30. }
  31. /**
  32. * Rebuild the nested set tree.
  33. *
  34. * @return bool False on failure or error, true on success.
  35. * @since 1.6
  36. */
  37. public function rebuild()
  38. {
  39. JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
  40. $extension = JRequest::getCmd('extension');
  41. $this->setRedirect(JRoute::_('index.php?option=com_categories&view=categories&extension='.$extension, false));
  42. // Initialise variables.
  43. $model = $this->getModel();
  44. if ($model->rebuild()) {
  45. // Rebuild succeeded.
  46. $this->setMessage(JText::_('COM_CATEGORIES_REBUILD_SUCCESS'));
  47. return true;
  48. } else {
  49. // Rebuild failed.
  50. $this->setMessage(JText::_('COM_CATEGORIES_REBUILD_FAILURE'));
  51. return false;
  52. }
  53. }
  54. /**
  55. * Save the manual order inputs from the categories list page.
  56. *
  57. * @return void
  58. * @since 1.6
  59. */
  60. public function saveorder()
  61. {
  62. JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
  63. // Get the arrays from the Request
  64. $order = JRequest::getVar('order', null, 'post', 'array');
  65. $originalOrder = explode(',', JRequest::getString('original_order_values'));
  66. // Make sure something has changed
  67. if (!($order === $originalOrder)) {
  68. parent::saveorder();
  69. } else {
  70. // Nothing to reorder
  71. $this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_list, false));
  72. return true;
  73. }
  74. }
  75. }