本文整理汇总了PHP中eZRole::fetchByUser方法的典型用法代码示例。如果您正苦于以下问题:PHP eZRole::fetchByUser方法的具体用法?PHP eZRole::fetchByUser怎么用?PHP eZRole::fetchByUser使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eZRole
的用法示例。
在下文中一共展示了eZRole::fetchByUser方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testFetchByUser
/**
* Unit test for eZRole::fetchByUser
**/
public function testFetchByUser()
{
// test with an empty array
$roles = eZRole::fetchByUser(array());
$this->assertType('array', $roles, "eZRole::fetchByUser with an empty array should have returned an array");
$this->assertEquals(0, count($roles), "eZRole::fetchByUser with an empty array should have returned an empty array");
// test with users with no direct role assignment (group assignment)
// should return an empty array since anonymous/admin role is assigned
// by group
$parameter = array(self::$anonymousUserID, self::$adminUserID);
$roles = eZRole::fetchByUser($parameter);
$this->assertType('array', $roles, "eZRole::fetchByUser with admin & anonymous should have returned an array");
$this->assertEquals(0, count($roles), "eZRole::fetchByUser with admin & anonymous should have returned an empty array");
foreach ($roles as $role) {
$this->assertType('eZRole', $role, "Returned items should be roles");
}
// test with the same users, but recursively: should return anonymous
// and administrator roles
$parameter = array(self::$anonymousUserID, self::$adminUserID);
$roles = eZRole::fetchByUser($parameter, true);
$this->assertType('array', $roles, "recursive eZRole::fetchByUser with admin & anonymous should have returned an array");
$this->assertEquals(2, count($roles), "recursive eZRole::fetchByUser with admin & anonymous should have returned an empty array");
foreach ($roles as $role) {
$this->assertType('eZRole', $role, "Returned items should be roles");
}
}
示例2: testPolicyList
/**
* Test for eZRole::policyList()
* Checks that policyList doesn't return temporary policies
*/
public function testPolicyList()
{
$role = array_shift(eZRole::fetchByUser(array(self::$anonymousUserID), true));
$policy = array_shift($role->policyList());
// create a temporary copy of one of the role's policies
$policy->createTemporaryCopy();
// check that the role's policies all are final (not temporary)
foreach ($role->policyList() as $policy) {
$this->assertType('eZPolicy', $policy);
$this->assertEquals(0, $policy->attribute('original_id'));
}
}
示例3: roles
function roles()
{
$groups = $this->attribute('groups');
$groups[] = $this->attribute('contentobject_id');
return eZRole::fetchByUser($groups);
}
示例4: fetchMemberOf
/**
* Fetch role list
* Used by fetch( 'user', 'member_of', hash( 'id', $id ) ) template function.
*
* @param int $id User id or normal content object id in case of none user object (user group)
* @return array(string=>array)
*/
function fetchMemberOf($id)
{
$user = eZUser::fetch($id);
if ($user instanceof eZUser) {
$roleList = $user->roles();
} else {
// user group or other non user classes:
$roleList = eZRole::fetchByUser(array($id), true);
}
return array('result' => $roleList);
}
示例5: accessArrayByUserID
/**
* Return access array by passing in list of groups user belongs to and his user id
*
* @param array $idArray Array of eZContentObject IDs, either groups + user id or user id's only
* If only user id's, then remember to set $recursive to true
* @param bool $recursive See {@link eZRole::fetchByUser()}
* @return array Hash with complete access limitation description
*/
static function accessArrayByUserID($idArray, $recursive = false)
{
$roles = eZRole::fetchByUser($idArray, $recursive);
$userLimitation = false;
$accessArray = array();
foreach (array_keys($roles) as $roleKey) {
$accessArray = array_merge_recursive($accessArray, $roles[$roleKey]->accessArray());
if ($roles[$roleKey]->attribute('limit_identifier')) {
$userLimitation = true;
}
}
if ($userLimitation) {
foreach ($accessArray as $moduleKey => $functionList) {
foreach ($functionList as $functionKey => $policyList) {
foreach ($policyList as $policyKey => $limitationList) {
if (is_array($limitationList)) {
foreach ($limitationList as $limitationKey => $limitKeyArray) {
if (is_array($limitKeyArray)) {
$accessArray[$moduleKey][$functionKey][$policyKey][$limitationKey] = array_unique($limitKeyArray);
}
}
}
}
}
}
}
return $accessArray;
}