Forums / Developer / how fetch all objects which can be editted by current user?

how fetch all objects which can be editted by current user?

Author Message

Vytautas Germanavičius

Friday 08 April 2005 5:55:42 am

how fetch all objects which can be edited by current user? (from tree)

:/ Is it so hard, I'm waiting for answer more than week.

{set-block scope=root variable=cache_ttl}0{/set-block}

Sebastiaan van der Vliet

Thursday 14 April 2005 3:40:38 am

Hi,

I'm not sure about fetching everything from a tree,
but to fetch all publications owned by the current user you could use the following function:

function fetchPublicationList( $class_id, $offset, $limit )
{
	$userID = eZUser::currentUserID();
	$publicationList = & eZPersistentObject::fetchObjectList( eZContentObject::definition(),
	null, array(  'owner_id' => $userID,
	'status' => EZ_VERSION_STATUS_PUBLISHED,
	'contentclass_id' => $class_id ),
	null, array( 'length' => $limit, 'offset' => $offset ),
	true );
	return array( 'result' => &$publicationList );
}

Certified eZ publish developer with over 9 years of eZ publish experience. Available for challenging eZ publish projects as a technical consultant, project manager, trouble shooter or strategic advisor.

Vytautas Germanavičius

Thursday 14 April 2005 5:08:51 am

Thank you for replay. I need this function too. but... how to use it?

Should i write it to template, or to any PHP file? or it is already there?

{set-block scope=root variable=cache_ttl}0{/set-block}

Sebastiaan van der Vliet

Thursday 14 April 2005 5:41:40 am

Hi,

The best solution would be to integrate this functionality as a template plugin in your site. However, for a number of reasons I choose to modify the kernel. Among others because I wanted to set up a "http://mysite/content/publication_list" or "Contributions" page that displays an overview all contributions (owned) by the user.

This is what I did:

1. To /kernel/content/ezcontentfunctioncollection.php I added:

function fetchPublicationList( $class_id, $offset, $limit )
{
$userID = eZUser::currentUserID();
$publicationList = & eZPersistentObject::fetchObjectList( eZContentObject::definition(),
null, array(  'owner_id' => $userID,
'status' => EZ_VERSION_STATUS_PUBLISHED,
'contentclass_id' => $class_id ),
null, array( 'length' => $limit, 'offset' => $offset ),
true );
return array( 'result' => &$publicationList );
}

2. To /kernel/content/function_definition.php I added:

$FunctionList['publication_list'] = array( 'name' => 'publication_list',
'operation_types' => array( 'read' ),
'call_method' => array( 'include_file' => 'kernel/content/ezcontentfunctioncollection.php',
'class' => 'eZContentFunctionCollection',
'method' => 'fetchPublicationList' ),
'parameter_type' => 'standard',
'parameters' => array( array('name' => 'class_id',
	'type' => 'integer',
	'required' => true),
array( 'name' => 'offset',
     'type' => 'integer',
     'required' => false,
     'default' => false ),
array( 'name' => 'limit',
     'type' => 'integer',
     'required' => false,
     'default' => false ) ) );

3. Inside the template I call the function as follows:

{section loop=fetch( 'content', 'can_instantiate_class_list' )}
{let publication_list=fetch('content', 'publication_list', hash(class_id, $:item.id, limit, 100, offset, 0))}
	{section loop=$publication_list sequence=array(bgdark,bglight)}
		[..etc...]
	{/section}	
{/let}
{/section}

The code above displays all classes, but you can restrict it to only articles. It is not a real elegant solution, in terms of upgrading etc.

Certified eZ publish developer with over 9 years of eZ publish experience. Available for challenging eZ publish projects as a technical consultant, project manager, trouble shooter or strategic advisor.

Xavier Dutoit

Thursday 14 April 2005 6:26:32 am

Hi Sebastiaan,

Have you tried to create a module in extension/contentuser (for instance) with a list function (the one you've wrote).

Have a look at the doc if you haven't already, not complicated.

Then, intead of using /contentuser/list you could add a url rewrite (from the back office) between content/contribution_list and contentuser/list ?

X+

http://www.sydesy.com

Sebastiaan van der Vliet

Thursday 14 April 2005 6:39:55 am

Hi Xavier,

That sounds like a better solution-I'll give it a try and report back here...

Thanks!

Certified eZ publish developer with over 9 years of eZ publish experience. Available for challenging eZ publish projects as a technical consultant, project manager, trouble shooter or strategic advisor.