Source for file group.php
Documentation is available at group.php
* @package Joomla.Administrator
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* @package Joomla.Administrator
* @var string The event to trigger after saving the data.
* @var string The event to trigger after before the data.
* Returns a reference to the a Table object, always creating it.
* @param type The table type to instantiate
* @param string A prefix for the table class name. Optional.
* @param array Configuration array for model. Optional.
* @return JTable A database object
public function getTable($type =
'Usergroup', $prefix =
'JTable', $config =
array())
* Method to get the record form.
* @param array $data An optional array of data for the form to interogate.
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
* @return JForm A JForm object on success, false on failure
public function getForm($data =
array(), $loadData =
true)
$form =
$this->loadForm('com_users.group', 'group', array('control' =>
'jform', 'load_data' =>
$loadData));
* Method to get the data that should be injected in the form.
* @return mixed The data for the form.
// Check the session for previously entered form data.
* Override preprocessForm to load the user plugin group instead of content.
* @param object A form object.
* @param mixed The data expected for the form.
* @throws Exception if there is an error in the form event.
if (isset
($obj->parent_id) &&
$obj->parent_id ==
0 &&
$obj->id >
0)
$form->setFieldAttribute('parent_id', 'type', 'hidden');
$form->setFieldAttribute('parent_id', 'hidden', 'true');
parent::preprocessForm($form, $data, 'user');
* Method to save the form data.
* @param array The form data.
* @return boolean True on success.
public function save($data)
// Include the content plugins for events.
// Check the super admin permissions for group
// We get the parent group permissions and then check the group permissions manually
// We have to calculate the group permissions manually because we haven't saved the group yet
// Get core.admin rules from the root asset
// Get the value for the current group (will be true (allowed), false (denied), or null (inherit)
$groupSuperAdmin =
$rules['core.admin']->allow($data['id']);
// We only need to change the $groupSuperAdmin if the parent is true or false. Otherwise, the value set in the rule takes effect.
if ($parentSuperAdmin ===
false)
// If parent is false (Denied), effective value will always be false
$groupSuperAdmin =
false;
elseif ($parentSuperAdmin ===
true)
// If parent is true (allowed), group is true unless explicitly set to false
$groupSuperAdmin =
($groupSuperAdmin ===
false) ?
false :
true;
// Check for non-super admin trying to save with super admin group
if ((!$iAmSuperAdmin) &&
($groupSuperAdmin))
throw
new Exception(JText::_('JLIB_USER_ERROR_NOT_SUPERADMIN'));
// Check for super-admin changing self to be non-super-admin
// First, are we a super admin>
// Next, are we a member of the current group?
// Now, would we have super admin permissions without the current group?
$otherGroups =
array_diff($myGroups, array($data['id']));
$otherSuperAdmin =
false;
foreach ($otherGroups as $otherGroup)
$otherSuperAdmin =
($otherSuperAdmin) ?
$otherSuperAdmin :
JAccess::checkGroup($otherGroup, 'core.admin');
// If we would not otherwise have super admin permissions
// and the current group does not have super admin permissions, throw an exception
if ((!$otherSuperAdmin) &&
(!$groupSuperAdmin))
throw
new Exception(JText::_('JLIB_USER_ERROR_CANNOT_DEMOTE_SELF'));
return parent::save($data);
* @param array An array of item ids.
* @return boolean Returns true on success, false on failure.
// Check if I am a Super Admin
$iAmSuperAdmin =
$user->authorise('core.admin');
// do not allow to delete groups to which the current user belongs
// Iterate the items to delete each one.
foreach ($pks as $i =>
$pk)
$allow =
$user->authorise('core.edit.state', 'com_users');
// Don't allow non-super-admin to delete a super admin
$allow =
(!$iAmSuperAdmin &&
JAccess::checkGroup($pk, 'core.admin')) ?
false :
$allow;
// Fire the onUserBeforeDeleteGroup event.
$dispatcher->trigger('onUserBeforeDeleteGroup', array($table->getProperties()));
if (!$table->delete($pk))
// Trigger the onUserAfterDeleteGroup event.
$dispatcher->trigger('onUserAfterDeleteGroup', array($table->getProperties(), true, $this->getError()));
// Prune items that you can't change.
Documentation generated on Tue, 19 Nov 2013 15:04:05 +0100 by phpDocumentor 1.4.3