[php] what usergroup can see a contentobject?

Author Message

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>

Pascal Specht

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;
	}

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 22:26:17
Script start
Timing: Jan 18 2025 22:26:17
Module start 'layout'
Timing: Jan 18 2025 22:26:17
Module start 'content'
Timing: Jan 18 2025 22:26:18
Module end 'content'
Timing: Jan 18 2025 22:26:18
Script end

Main resources:

Total runtime1.0403 sec
Peak memory usage4,096.0000 KB
Database Queries52

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0061 589.4766152.6406
Module start 'layout' 0.00620.0036 742.117239.4766
Module start 'content' 0.00971.0293 781.5938462.2344
Module end 'content' 1.03900.0012 1,243.82818.1250
Script end 1.0403  1,251.9531 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00320.3038160.0002
Check MTime0.00130.1224160.0001
Mysql Total
Database connection0.00130.126310.0013
Mysqli_queries0.992995.4462520.0191
Looping result0.00050.0507500.0000
Template Total1.009097.020.5045
Template load0.00210.197820.0010
Template processing1.006996.789820.5035
Template load and register function0.00010.008910.0001
states
state_id_array0.00070.067310.0007
state_identifier_array0.00140.132120.0007
Override
Cache load0.00170.1630180.0001
Sytem overhead
Fetch class attribute can translate value0.00090.090510.0009
Fetch class attribute name0.00160.157130.0005
XML
Image XML parsing0.00050.051210.0005
class_abstraction
Instantiating content class attribute0.00000.001040.0000
General
dbfile0.00080.0815160.0001
String conversion0.00000.001140.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
2content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
2content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
3content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
1content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
2content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 12
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs