| [ Index ] |
PHP Cross Reference of Joomla 2.5.4 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @version $Id$ 4 * @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved. 5 * @license GNU General Public License version 2 or later; see LICENSE.txt 6 */ 7 8 defined('JPATH_BASE') or die; 9 10 JFormHelper::loadFieldClass('list'); 11 12 /** 13 * Form Field class for the Joomla Framework. 14 * 15 * @package Joomla.Administrator 16 * @subpackage com_categories 17 * @since 1.6 18 */ 19 class JFormFieldCategoryEdit extends JFormFieldList 20 { 21 /** 22 * A flexible category list that respects access controls 23 * 24 * @var string 25 * @since 1.6 26 */ 27 public $type = 'CategoryEdit'; 28 29 /** 30 * Method to get a list of categories that respects access controls and can be used for 31 * either category assignment or parent category assignment in edit screens. 32 * Use the parent element to indicate that the field will be used for assigning parent categories. 33 * 34 * @return array The field option objects. 35 * @since 1.6 36 */ 37 protected function getOptions() 38 { 39 // Initialise variables. 40 $options = array(); 41 $published = $this->element['published']? $this->element['published'] : array(0,1); 42 $name = (string) $this->element['name']; 43 44 // Let's get the id for the current item, either category or content item. 45 $jinput = JFactory::getApplication()->input; 46 // Load the category options for a given extension. 47 48 // For categories the old category is the category id or 0 for new category. 49 if ($this->element['parent'] || $jinput->get('option') == 'com_categories') 50 { 51 $oldCat = $jinput->get('id', 0); 52 $oldParent = $this->form->getValue($name, 0); 53 $extension = $this->element['extension'] ? (string) $this->element['extension'] : (string) $jinput->get('extension','com_content'); 54 } 55 else 56 // For items the old category is the category they are in when opened or 0 if new. 57 { 58 $thisItem = $jinput->get('id',0); 59 $oldCat = $this->form->getValue($name, 0); 60 $extension = $this->element['extension'] ? (string) $this->element['extension'] : (string) $jinput->get('option','com_content'); 61 } 62 63 $db = JFactory::getDbo(); 64 $query = $db->getQuery(true); 65 66 $query->select('a.id AS value, a.title AS text, a.level, a.published'); 67 $query->from('#__categories AS a'); 68 $query->join('LEFT', $db->quoteName('#__categories').' AS b ON a.lft > b.lft AND a.rgt < b.rgt'); 69 70 // Filter by the extension type 71 if ($this->element['parent'] == true || $jinput->get('option') == 'com_categories') 72 { 73 $query->where('(a.extension = '.$db->quote($extension).' OR a.parent_id = 0)'); 74 } 75 else 76 { 77 $query->where('(a.extension = '.$db->quote($extension).')'); 78 } 79 // If parent isn't explicitly stated but we are in com_categories assume we want parents 80 if ($oldCat != 0 && ($this->element['parent'] == true || $jinput->get('option') == 'com_categories')) 81 { 82 // Prevent parenting to children of this item. 83 // To rearrange parents and children move the children up, not the parents down. 84 $query->join('LEFT', $db->quoteName('#__categories').' AS p ON p.id = '.(int) $oldCat); 85 $query->where('NOT(a.lft >= p.lft AND a.rgt <= p.rgt)'); 86 87 $rowQuery = $db->getQuery(true); 88 $rowQuery->select('a.id AS value, a.title AS text, a.level, a.parent_id'); 89 $rowQuery->from('#__categories AS a'); 90 $rowQuery->where('a.id = ' . (int) $oldCat); 91 $db->setQuery($rowQuery); 92 $row = $db->loadObject(); 93 } 94 // Filter on the published state 95 96 if (is_numeric($published)) 97 { 98 $query->where('a.published = ' . (int) $published); 99 } 100 elseif (is_array($published)) 101 { 102 JArrayHelper::toInteger($published); 103 $query->where('a.published IN (' . implode(',', $published) . ')'); 104 } 105 106 $query->group('a.id, a.title, a.level, a.lft, a.rgt, a.extension, a.parent_id, a.published'); 107 $query->order('a.lft ASC'); 108 109 // Get the options. 110 $db->setQuery($query); 111 112 $options = $db->loadObjectList(); 113 114 // Check for a database error. 115 if ($db->getErrorNum()) { 116 JError::raiseWarning(500, $db->getErrorMsg()); 117 } 118 119 120 // Pad the option text with spaces using depth level as a multiplier. 121 for ($i = 0, $n = count($options); $i < $n; $i++) 122 { 123 // Translate ROOT 124 if ($this->element['parent'] == true || $jinput->get('option') == 'com_categories') 125 { 126 if ($options[$i]->level == 0) 127 { 128 $options[$i]->text = JText::_('JGLOBAL_ROOT_PARENT'); 129 } 130 } 131 if ($options[$i]->published == 1) 132 { 133 $options[$i]->text = str_repeat('- ', $options[$i]->level). $options[$i]->text ; 134 } 135 else 136 { 137 $options[$i]->text = str_repeat('- ', $options[$i]->level). '[' .$options[$i]->text . ']'; 138 } 139 } 140 141 142 // Get the current user object. 143 $user = JFactory::getUser(); 144 145 // For new items we want a list of categories you are allowed to create in. 146 if ($oldCat == 0) 147 { 148 foreach ($options as $i => $option) 149 { 150 // To take save or create in a category you need to have create rights for that category 151 // unless the item is already in that category. 152 // Unset the option if the user isn't authorised for it. In this field assets are always categories. 153 if ($user->authorise('core.create', $extension . '.category.' . $option->value) != true ) 154 { 155 unset($options[$i]); 156 } 157 } 158 } 159 // If you have an existing category id things are more complex. 160 else 161 { 162 // If you are only allowed to edit in this category but not edit.state, you should not get any 163 // option to change the category parent for a category or the category for a content item, 164 // but you should be able to save in that category. 165 foreach ($options as $i => $option) 166 { 167 if ($user->authorise('core.edit.state', $extension . '.category.' . $oldCat) != true && !isset($oldParent)) 168 { 169 if ($option->value != $oldCat ) 170 { 171 unset($options[$i]); 172 } 173 } 174 if ($user->authorise('core.edit.state', $extension . '.category.' . $oldCat) != true 175 && (isset($oldParent)) && $option->value != $oldParent) 176 { 177 unset($options[$i]); 178 } 179 180 // However, if you can edit.state you can also move this to another category for which you have 181 // create permission and you should also still be able to save in the current category. 182 if (($user->authorise('core.create', $extension . '.category.' . $option->value) != true) 183 && ($option->value != $oldCat && !isset($oldParent))) 184 { 185 { 186 unset($options[$i]); 187 } 188 } 189 if (($user->authorise('core.create', $extension . '.category.' . $option->value) != true) 190 && (isset($oldParent)) && $option->value != $oldParent) 191 { 192 { 193 unset($options[$i]); 194 } 195 } 196 } 197 } 198 if (($this->element['parent'] == true || $jinput->get('option') == 'com_categories') 199 && (isset($row) && !isset($options[0])) && isset($this->element['show_root'])) 200 { 201 if ($row->parent_id == '1') { 202 $parent = new stdClass(); 203 $parent->text = JText::_('JGLOBAL_ROOT_PARENT'); 204 array_unshift($options, $parent); 205 } 206 array_unshift($options, JHtml::_('select.option', '0', JText::_('JGLOBAL_ROOT'))); 207 } 208 209 210 211 // Merge any additional options in the XML definition. 212 $options = array_merge(parent::getOptions(), $options); 213 214 return $options; 215 } 216 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Tue Apr 3 11:40:28 2012 | Cross-referenced by PHPXref 0.7.1 |