| [ Index ] |
PHP Cross Reference of Joomla 2.5.4 DE |
[Summary view] [Print] [Text view]
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 7 defined('JPATH_BASE') or die; 8 9 JFormHelper::loadFieldClass('list'); 10 11 /** 12 * Form Field class for the Joomla Framework. 13 * 14 * @package Joomla.Administrator 15 * @subpackage com_categories 16 * @since 1.6 17 */ 18 class JFormFieldCategoryParent extends JFormFieldList 19 { 20 /** 21 * The form field type. 22 * 23 * @var string 24 * @since 1.6 25 */ 26 protected $type = 'CategoryParent'; 27 28 /** 29 * Method to get the field options. 30 * 31 * @return array The field option objects. 32 * @since 1.6 33 */ 34 protected function getOptions() 35 { 36 // Initialise variables. 37 $options = array(); 38 $name = (string) $this->element['name']; 39 40 // Let's get the id for the current item, either category or content item. 41 $jinput = JFactory::getApplication()->input; 42 // For categories the old category is the category id 0 for new category. 43 if ($this->element['parent']) 44 { 45 $oldCat = $jinput->get('id',0); 46 $oldParent = $this->form->getValue($name); 47 } 48 else 49 // For items the old category is the category they are in when opened or 0 if new. 50 { 51 $thisItem = $jinput->get('id',0); 52 $oldCat = $this->form->getValue($name); 53 } 54 55 $db = JFactory::getDbo(); 56 $query = $db->getQuery(true); 57 58 $query->select('a.id AS value, a.title AS text, a.level'); 59 $query->from('#__categories AS a'); 60 $query->join('LEFT', $db->quoteName('#__categories').' AS b ON a.lft > b.lft AND a.rgt < b.rgt'); 61 62 // Filter by the type 63 if ($extension = $this->form->getValue('extension')) { 64 $query->where('(a.extension = '.$db->quote($extension).' OR a.parent_id = 0)'); 65 } 66 if ($this->element['parent']) 67 { 68 // Prevent parenting to children of this item. 69 if ($id = $this->form->getValue('id')) { 70 $query->join('LEFT', $db->quoteName('#__categories').' AS p ON p.id = '.(int) $id); 71 $query->where('NOT(a.lft >= p.lft AND a.rgt <= p.rgt)'); 72 73 $rowQuery = $db->getQuery(true); 74 $rowQuery->select('a.id AS value, a.title AS text, a.level, a.parent_id'); 75 $rowQuery->from('#__categories AS a'); 76 $rowQuery->where('a.id = ' . (int) $id); 77 $db->setQuery($rowQuery); 78 $row = $db->loadObject(); 79 } 80 } 81 $query->where('a.published IN (0,1)'); 82 $query->group('a.id, a.title, a.level, a.lft, a.rgt, a.extension, a.parent_id'); 83 $query->order('a.lft ASC'); 84 85 // Get the options. 86 $db->setQuery($query); 87 88 $options = $db->loadObjectList(); 89 90 // Check for a database error. 91 if ($db->getErrorNum()) { 92 JError::raiseWarning(500, $db->getErrorMsg()); 93 } 94 95 // Pad the option text with spaces using depth level as a multiplier. 96 for ($i = 0, $n = count($options); $i < $n; $i++) 97 { 98 // Translate ROOT 99 if ($options[$i]->level == 0) { 100 $options[$i]->text = JText::_('JGLOBAL_ROOT_PARENT'); 101 } 102 103 $options[$i]->text = str_repeat('- ', $options[$i]->level).$options[$i]->text; 104 } 105 106 // Initialise variables. 107 108 // Get the current user object. 109 $user = JFactory::getUser(); 110 111 // For new items we want a list of categories you are allowed to create in. 112 if ($oldCat == 0) 113 { 114 foreach ($options as $i => $option) 115 { 116 // To take save or create in a category you need to have create rights for that category 117 // unless the item is already in that category. 118 // Unset the option if the user isn't authorised for it. In this field assets are always categories. 119 if ($user->authorise('core.create', $extension . '.category.' . $option->value) != true ) 120 { 121 unset($options[$i]); 122 } 123 } 124 } 125 // If you have an existing category id things are more complex. 126 else 127 { 128 //$categoryOld = $this->form->getValue($name); 129 foreach ($options as $i => $option) 130 { 131 // If you are only allowed to edit in this category but not edit.state, you should not get any 132 // option to change the category parent for a category or the category for a content item, 133 // but you should be able to save in that category. 134 if ($user->authorise('core.edit.state', $extension . '.category.' . $oldCat) != true) 135 { 136 if ($option->value != $oldCat) 137 {echo 'y'; 138 unset($options[$i]); 139 } 140 } 141 // However, if you can edit.state you can also move this to another category for which you have 142 // create permission and you should also still be able to save in the current category. 143 elseif 144 (($user->authorise('core.create', $extension . '.category.' . $option->value) != true) 145 && $option->value != $oldCat) 146 {echo 'x'; 147 unset($options[$i]); 148 } 149 } 150 } 151 152 153 if (isset($row) && !isset($options[0])) { 154 if ($row->parent_id == '1') { 155 $parent = new stdClass(); 156 $parent->text = JText::_('JGLOBAL_ROOT_PARENT'); 157 array_unshift($options, $parent); 158 } 159 } 160 161 // Merge any additional options in the XML definition. 162 $options = array_merge(parent::getOptions(), $options); 163 164 return $options; 165 } 166 }
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 |