Forums / Developer / [php] what usergroup can see a contentobject?
Pascal Specht
Thursday 19 June 2008 5:52:02 am
Hi,
I have a list of user groups in one array ( "Users", "Members", "Administrator users", "Anonymous Users" etc).
I want to know which of these user groups are allowed to see (content/read) a given contentobject.
Anyone already tried to solve this challenge? I didn't find much in the documentation...
Any help much appreciated.
</Pascal>
Thursday 19 June 2008 9:13:41 am
If this can be of any help to others, I came up with the following code:It definitively could need some improvement, but works for me. If anyone knows a better way, please feel free to post it here.
Once the section of the contentobect has been determined with
$contentobject->attribute( 'section_id' );
you can then check if the section ID is contained in the array returned by this method:
/* for a given array of user or group contentobject_id, return an array of the Section IDs this user or group has access to. TBD: does not take class-level access restrictions per sections into account */ function getSectionsByUserIDArray( $userID_array ) { $accessPolicies = eZRole::accessArrayByUserID( $userID_array ); $sectionsByUserID = array(); foreach ( $accessPolicies['content']['read'] as $key => $ap ) { foreach( $ap as $k => $sections ) { if ( strtolower($k)=="section") { foreach ( $sections as $s) { $sectionsByUserID[]=$s; } } } } $sectionsByUserID=array_unique($sectionsByUserID); return $sectionsByUserID; }