本文整理汇总了PHP中JUserHelper::checkSuperUserInUsers方法的典型用法代码示例。如果您正苦于以下问题:PHP JUserHelper::checkSuperUserInUsers方法的具体用法?PHP JUserHelper::checkSuperUserInUsers怎么用?PHP JUserHelper::checkSuperUserInUsers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JUserHelper
的用法示例。
在下文中一共展示了JUserHelper::checkSuperUserInUsers方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: batchUser
/**
* Perform batch operations
*
* @param integer $group_id The group ID which assignments are being edited
* @param array $user_ids An array of user IDs on which to operate
* @param string $action The action to perform
*
* @return boolean True on success, false on failure
*
* @since 1.6
*/
public function batchUser($group_id, $user_ids, $action)
{
JArrayHelper::toInteger($user_ids);
// Check if I am a Super Admin
$iAmSuperAdmin = JFactory::getUser()->authorise('core.admin');
// Non-super super user cannot work with super-admin user.
if (!$iAmSuperAdmin && JUserHelper::checkSuperUserInUsers($user_ids)) {
$this->setError(JText::_('COM_USERS_ERROR_CANNOT_BATCH_SUPERUSER'));
return false;
}
// Non-super admin cannot work with super-admin group.
if (!$iAmSuperAdmin && JAccess::checkGroup($group_id, 'core.admin') || $group_id < 1) {
$this->setError(JText::_('COM_USERS_ERROR_INVALID_GROUP'));
return false;
}
// Get the DB object
$db = $this->getDbo();
switch ($action) {
// Sets users to a selected group
case 'set':
$doDelete = 'all';
$doAssign = true;
break;
// Remove users from a selected group
// Remove users from a selected group
case 'del':
$doDelete = 'group';
break;
// Add users to a selected group
// Add users to a selected group
case 'add':
default:
$doAssign = true;
break;
}
// Remove the users from the group if requested.
if (isset($doDelete)) {
$query = $db->getQuery(true);
// Remove users from the group
$query->delete($db->quoteName('#__user_usergroup_map'))->where($db->quoteName('user_id') . ' IN (' . implode(',', $user_ids) . ')');
// Only remove users from selected group
if ($doDelete == 'group') {
$query->where($db->quoteName('group_id') . ' = ' . (int) $group_id);
}
$db->setQuery($query);
try {
$db->execute();
} catch (RuntimeException $e) {
$this->setError($e->getMessage());
return false;
}
}
// Assign the users to the group if requested.
if (isset($doAssign)) {
$query = $db->getQuery(true);
// First, we need to check if the user is already assigned to a group
$query->select($db->quoteName('user_id'))->from($db->quoteName('#__user_usergroup_map'))->where($db->quoteName('group_id') . ' = ' . (int) $group_id);
$db->setQuery($query);
$users = $db->loadColumn();
// Build the values clause for the assignment query.
$query->clear();
$groups = false;
foreach ($user_ids as $id) {
if (!in_array($id, $users)) {
$query->values($id . ',' . $group_id);
$groups = true;
}
}
// If we have no users to process, throw an error to notify the user
if (!$groups) {
$this->setError(JText::_('COM_USERS_ERROR_NO_ADDITIONS'));
return false;
}
$query->insert($db->quoteName('#__user_usergroup_map'))->columns(array($db->quoteName('user_id'), $db->quoteName('group_id')));
$db->setQuery($query);
try {
$db->execute();
} catch (RuntimeException $e) {
$this->setError($e->getMessage());
return false;
}
}
return true;
}