Source for file rules.php
Documentation is available at rules.php
* @package Joomla.Platform
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
* Form Field class for the Joomla Platform.
* Field for assigning permissions to groups for a given asset
* @package Joomla.Platform
protected $type =
'Rules';
* Method to get certain otherwise inaccessible properties from the form field object.
* @param string $name The property name for which to the the value.
* @return mixed The property value or null.
public function __get($name)
return parent::__get($name);
* Method to set certain otherwise inaccessible properties of the form field object.
* @param string $name The property name for which to the the value.
* @param mixed $value The value of the property.
public function __set($name, $value)
$this->$name = (string)
$value;
parent::__set($name, $value);
* Method to attach a JForm object to the field.
* @param SimpleXMLElement $element The SimpleXMLElement object representing the <field /> tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
* @return boolean True on success.
* @see JFormField::setup()
public function setup(SimpleXMLElement $element, $value, $group =
null)
$return =
parent::setup($element, $value, $group);
* Method to get the field input markup for Access Control Lists.
* Optionally can be associated with a specific component and section.
* @return string The field input markup.
* @todo: Add access check.
JHtml::_('bootstrap.tooltip');
// Initialise some field attributes.
// Get the actions for the asset.
// Iterate over the children and add to the actions.
foreach ($this->element->children() as $el)
if ($el->getName() ==
'action')
$actions[] = (object)
array('name' => (string)
$el['name'], 'title' => (string)
$el['title'],
'description' => (string)
$el['description']);
// Get the explicit rules for this asset.
if ($section ==
'component')
// Need to find the asset id by the name of the component.
$query =
$db->getQuery(true)
->select($db->quoteName('id'))
->from($db->quoteName('#__assets'))
->where($db->quoteName('name') .
' = ' .
$db->quote($component));
$assetId = (int)
$db->loadResult();
// Find the asset id of the content.
// Note that for global configuration, com_config injects asset_id = 1 into the form.
$assetId =
$this->form->getValue($assetField);
// Get the rules for just this asset (non-recursive).
// Get the available user groups.
$html[] =
'<p class="rule-desc">' .
JText::_('JLIB_RULES_SETTINGS_DESC') .
'</p>';
$html[] =
'<div id="permissions-sliders" class="tabbable tabs-left">';
$html[] =
'<ul class="nav nav-tabs">';
foreach ($groups as $group)
$html[] =
'<li class="' .
$active .
'">';
$html[] =
'<a href="#permission-' .
$group->value .
'" data-toggle="tab">';
$html[] =
str_repeat('<span class="level">–</span> ', $curLevel =
$group->level) .
$group->text;
$html[] =
'<div class="tab-content">';
// Start a row for each user group.
foreach ($groups as $group)
$html[] =
'<div class="tab-pane' .
$active .
'" id="permission-' .
$group->value .
'">';
$html[] =
'<table class="table table-striped">';
$html[] =
'<th class="actions" id="actions-th' .
$group->value .
'">';
$html[] =
'<span class="acl-action">' .
JText::_('JLIB_RULES_ACTION') .
'</span>';
$html[] =
'<th class="settings" id="settings-th' .
$group->value .
'">';
$html[] =
'<span class="acl-action">' .
JText::_('JLIB_RULES_SELECT_SETTING') .
'</span>';
// The calculated setting is not shown for the root group of global configuration.
$canCalculateSettings =
($group->parent_id ||
!empty($component));
if ($canCalculateSettings)
$html[] =
'<th id="aclactionth' .
$group->value .
'">';
$html[] =
'<span class="acl-action">' .
JText::_('JLIB_RULES_CALCULATED_SETTING') .
'</span>';
foreach ($actions as $action)
$html[] =
'<td headers="actions-th' .
$group->value .
'">';
$html[] =
'<label for="' .
$this->id .
'_' .
$action->name .
'_' .
$group->value .
'" class="hasTooltip" title="'
$html[] =
JText::_($action->title);
$html[] =
'<td headers="settings-th' .
$group->value .
'">';
$html[] =
'<select class="input-small" name="' .
$this->name .
'[' .
$action->name .
'][' .
$group->value .
']" id="' .
$this->id .
'_' .
$action->name
.
'_' .
$group->value .
'" title="'
// Get the actual setting for the action for this group.
$assetRule =
$assetRules->allow($action->name, $group->value);
// Build the dropdowns for the permissions sliders
// The parent group has "Not Set", all children can rightly "Inherit" from that.
$html[] =
'<option value=""' .
($assetRule ===
null ?
' selected="selected"' :
'') .
'>'
.
JText::_(empty($group->parent_id) &&
empty($component) ?
'JLIB_RULES_NOT_SET' :
'JLIB_RULES_INHERITED') .
'</option>';
$html[] =
'<option value="1"' .
($assetRule ===
true ?
' selected="selected"' :
'') .
'>' .
JText::_('JLIB_RULES_ALLOWED')
$html[] =
'<option value="0"' .
($assetRule ===
false ?
' selected="selected"' :
'') .
'>' .
JText::_('JLIB_RULES_DENIED')
$html[] =
'</select>  ';
// If this asset's rule is allowed, but the inherited rule is deny, we have a conflict.
if (($assetRule ===
true) &&
($inheritedRule ===
false))
$html[] =
JText::_('JLIB_RULES_CONFLICT');
// Build the Calculated Settings column.
// The inherited settings column is not displayed for the root group in global configuration.
if ($canCalculateSettings)
$html[] =
'<td headers="aclactionth' .
$group->value .
'">';
// This is where we show the current effective settings considering currrent group, path and cascade.
// Check whether this is a component or global. Change the text slightly.
if ($inheritedRule ===
null)
$html[] =
'<span class="label label-important">' .
JText::_('JLIB_RULES_NOT_ALLOWED') .
'</span>';
elseif ($inheritedRule ===
true)
$html[] =
'<span class="label label-success">' .
JText::_('JLIB_RULES_ALLOWED') .
'</span>';
elseif ($inheritedRule ===
false)
if ($assetRule ===
false)
$html[] =
'<span class="label label-important">' .
JText::_('JLIB_RULES_NOT_ALLOWED') .
'</span>';
$html[] =
'<span class="label"><i class="icon-lock icon-white"></i> ' .
JText::_('JLIB_RULES_NOT_ALLOWED_LOCKED')
elseif (!empty($component))
$html[] =
'<span class="label label-success"><i class="icon-lock icon-white"></i> ' .
JText::_('JLIB_RULES_ALLOWED_ADMIN')
// Special handling for groups that have global admin because they can't be denied.
// The admin rights can be changed.
if ($action->name ===
'core.admin')
$html[] =
'<span class="label label-success">' .
JText::_('JLIB_RULES_ALLOWED') .
'</span>';
elseif ($inheritedRule ===
false)
// Other actions cannot be changed.
$html[] =
'<span class="label label-important"><i class="icon-lock icon-white"></i> '
.
JText::_('JLIB_RULES_NOT_ALLOWED_ADMIN_CONFLICT') .
'</span>';
$html[] =
'<span class="label label-success"><i class="icon-lock icon-white"></i> ' .
JText::_('JLIB_RULES_ALLOWED_ADMIN')
$html[] =
'</table></div>';
$html[] =
'</div></div>';
$html[] =
'<div class="alert">';
if ($section ==
'component' ||
$section ==
null)
$html[] =
JText::_('JLIB_RULES_SETTING_NOTES');
$html[] =
JText::_('JLIB_RULES_SETTING_NOTES_ITEM');
* Get a list of the user groups.
$query =
$db->getQuery(true)
->select('a.id AS value, a.title AS text, COUNT(DISTINCT b.id) AS level, a.parent_id')
->from('#__usergroups AS a')
->join('LEFT', $db->quoteName('#__usergroups') .
' AS b ON a.lft > b.lft AND a.rgt < b.rgt')
->group('a.id, a.title, a.lft, a.rgt, a.parent_id')
$options =
$db->loadObjectList();
Documentation generated on Tue, 19 Nov 2013 15:12:32 +0100 by phpDocumentor 1.4.3