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