本文整理汇总了PHP中Current_User::getGroups方法的典型用法代码示例。如果您正苦于以下问题:PHP Current_User::getGroups方法的具体用法?PHP Current_User::getGroups怎么用?PHP Current_User::getGroups使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Current_User
的用法示例。
在下文中一共展示了Current_User::getGroups方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: restrictEdit
/**
* Adds limits to a db select query to only pull items the user
* has permissions to view
*
* Note that BEFORE this is called, the developer should check whether
* the user has ANY rights to edit items in the first place.
* In other words, if Current_User::allow('module', 'edit_permission') == false
* then they shouldn't even use this function. If it is used anyway, a forced negative
* will be added (i.e. where 1 = 0);
* If you wish to add other qualifications, use the $db->addWhere() group 'key_id'
* in your module code.
*
* @modified Eloi George
* @param object db : Database object to modify
* @param string module : Calling module
* @param string edit_permission : Name of the editing permission
* @param string source_table : (optional) Name of the main table being searched
* @param string key_id_column : (optional) Usually "key_id". Only use this if you allow edits where "key_id=0"
* @param string owner_id_column : (optional) Only use this if you allow edits on content created by the user
*/
public static function restrictEdit($db, $module, $edit_permission = null, $source_table = null, $key_id_column = null, $owner_id_column = null)
{
if (Current_User::isDeity()) {
return;
}
// if the user doesn't have rights for the module or subpermissions,
// then we just stymie the whole query
if (!Current_User::allow($module, $edit_permission)) {
$db->setQWhere('1=0');
return;
}
// If the current user has unrestricted rights to edit the item
// linked to this key, no further restrictions are necessary
if (Current_User::isUnrestricted($module)) {
return;
} else {
$db->setDistinct(1);
if (empty($source_table)) {
$source_table = $db->tables[0];
}
if (!empty($key_id_column)) {
$db->addWhere($source_table . '.' . $key_id_column, 0, null, 'or', 'key_1');
}
if (!empty($owner_id_column)) {
$db->addWhere($source_table . '.' . $owner_id_column, Current_User::getId(), null, 'or', 'key_1');
}
$groups = Current_User::getGroups();
if (!empty($groups)) {
$db->addJoin('left', $source_table, 'phpws_key_edit', 'key_id', 'key_id');
$db->addWhere('phpws_key_edit.group_id', $groups, 'in', 'or', 'key_1');
}
return;
}
}
示例2: allowView
public static function allowView()
{
if (Current_User::allow('blog')) {
return true;
}
// Only logged users may view and user is not logged in
if (PHPWS_Settings::get('blog', 'logged_users_only') && !Current_User::isLogged()) {
return false;
}
$view_groups = PHPWS_Settings::get('blog', 'view_only');
if (!empty($view_groups)) {
$allowed_groups = explode(':', $view_groups);
} else {
$allowed_groups = null;
}
// Allowed groups is set, check the user
if ($allowed_groups) {
// User isn't even logged in. Don't show blog
if (!Current_User::isLogged()) {
return false;
}
// get logged user's groups
$user_groups = Current_User::getGroups();
// check intersection
$intersect = array_intersect($user_groups, $allowed_groups);
//no intersection found, deny
if (empty($intersect)) {
return false;
}
}
return true;
}