Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
category.php
Aller à la documentation de ce fichier.
1 <?php
2 /**
3  * @package Joomla.Legacy
4  * @subpackage Form
5  *
6  * @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
7  * @license GNU General Public License version 2 or later; see LICENSE
8  */
9 
10 defined('JPATH_PLATFORM') or die;
11 
12 JFormHelper::loadFieldClass('list');
13 
14 /**
15  * Form Field class for the Joomla Platform.
16  * Supports an HTML select list of categories
17  *
18  * @package Joomla.Legacy
19  * @subpackage Form
20  * @since 11.1
21  */
23 {
24  /**
25  * The form field type.
26  *
27  * @var string
28  * @since 11.1
29  */
30  public $type = 'Category';
31 
32  /**
33  * Method to get the field options for category
34  * Use the extension attribute in a form to specify the.specific extension for
35  * which categories should be displayed.
36  * Use the show_root attribute to specify whether to show the global category root in the list.
37  *
38  * @return array The field option objects.
39  *
40  * @since 11.1
41  */
42  protected function getOptions()
43  {
44  $options = array();
45  $extension = $this->element['extension'] ? (string) $this->element['extension'] : (string) $this->element['scope'];
46  $published = (string) $this->element['published'];
47 
48  // Load the category options for a given extension.
49  if (!empty($extension))
50  {
51  // Filter over published state or not depending upon if it is present.
52  if ($published)
53  {
54  $options = JHtml::_('category.options', $extension, array('filter.published' => explode(',', $published)));
55  }
56  else
57  {
58  $options = JHtml::_('category.options', $extension);
59  }
60 
61  // Verify permissions. If the action attribute is set, then we scan the options.
62  if ((string) $this->element['action'])
63  {
64 
65  // Get the current user object.
66  $user = JFactory::getUser();
67 
68  foreach ($options as $i => $option)
69  {
70  /*
71  * To take save or create in a category you need to have create rights for that category
72  * unless the item is already in that category.
73  * Unset the option if the user isn't authorised for it. In this field assets are always categories.
74  */
75  if ($user->authorise('core.create', $extension . '.category.' . $option->value) != true)
76  {
77  unset($options[$i]);
78  }
79  }
80 
81  }
82 
83  if (isset($this->element['show_root']))
84  {
85  array_unshift($options, JHtml::_('select.option', '0', JText::_('JGLOBAL_ROOT')));
86  }
87  }
88  else
89  {
90  JLog::add(JText::_('JLIB_FORM_ERROR_FIELDS_CATEGORY_ERROR_EXTENSION_EMPTY'), JLog::WARNING, 'jerror');
91  }
92 
93  // Merge any additional options in the XML definition.
94  $options = array_merge(parent::getOptions(), $options);
95 
96  return $options;
97  }
98 }