This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit ezplatform.com

eZ Community » Forums » Developer » Editable drafts for every user !
expandshrink

Editable drafts for every user !

Editable drafts for every user !

Friday 22 June 2012 3:42:58 pm - 8 replies

Hi there,

I'm a recent member of the Ez Community.

I am in a training course and the compagny ask me to let the Ez Draft module of the Dashboard show every user draft. Actualy, hey want to edit the draft of the other users.

I've seen /www/kernel/content/drafts, but I don't know how to loop the userID.

Have you got an idea, a solution that can help me ?

Thanks and sorry for my bad english...!

    static public function fetchDraftVersionList( $offset, $limit )
    {
        $userID = eZUser::currentUserID();
        $draftVersionList =  eZPersistentObject::fetchObjectList( eZContentObjectVersion::definition(),
                                                                   null, array(  'creator_id' => $userID,
                                                                                 'status' => eZContentObjectVersion::STATUS_DRAFT ),
                                                                   array( 'modified' => true,
                                                                          'initial_language_id' => true ),
                                                                   array( 'length' => $limit, 'offset' => $offset ),
                                                                   true );
        return array( 'result' => $draftVersionList );
    }

Friday 22 June 2012 4:45:18 pm

Hi Arnaud,

I think you just have to remove the "creator_id" => $userID  from your fetch function (assuming that u override it)

let me know if this works,

regards

$draftVersionList =  eZPersistentObject::fetchObjectList( eZContentObjectVersion::definition(), null, array( 'status' => eZContentObjectVersion::STATUS_DRAFT ));

Modified on Friday 22 June 2012 4:48:45 pm by Remy MOURARD

Saturday 23 June 2012 8:45:13 pm

Hi Arnaud

Firstly you should not change any of kernel files.

You can do this same way as the other blocks in dashboard panel, namely:

  • Add new block to settings/siteaccess/admin_siteaccess/dashboard.ini.append.php (eg. all_dratfs)
  • For each block must exist template file with corresponding name, you can copy the design/standard/templates/dashboard/drafts.tpl to the corresponding path in your design, and change its name (in this example: all_drafts.tpl)
  • In this file you should change the fetch function fetch( 'content', 'draft_version_list'... to your own (eg. fetch( 'my_module', 'draft_version_list'...)
  • Then you need to create new fetch function within new module (Unfortunately, you need to create new module to not modify the kernel). In this module create 'function_definition.php' and 'my_modulefunctioncollection.php' with the corresponding functions (analogous to files: kernel/content/function_definition.php and kernel/content/ezcontentfunctioncollection.php)

If you do not now, how to create custom fetch function, check this: http://share.ez.no/learn/ez-publish/an-introduction-to-developing-ez-publish-extensions

Cheers

Tuesday 26 June 2012 3:57:17 pm

HI.  Just a few notes to add - breaking this up into the three relevant steps:
Dashboard - as described by Karol
it's just a setting and a template ( logic is separate)

Fetch Logic
Yes, you need an extension to hold your fetch logic.  We use a dashboard extension where we can hold all of our custom dashboards nice and tidy.  most of our custom ones load via javascript directly into a div - allowing us to create a 'dashboard' view and then a corresponding full  view with all of the logic for more detaied functionality,  However, For Your fetch, a simple template operator wrapping eZPersistentObject::fetchObjectList is enough for your fetch as it does not look like you need the overhead of the logic behind a full custom fetch (just getting back all drafts).

Please keep in mind that there may be multiple drafts for an object returned in the fetch.  you can decide how to deal with this based on your requirements (show only last, etc). This can be accomplished partly by fetchObjectList(grouping, sort order, fields displayed) to give you a targeted list, or by PHP post-processing your results. Using the features of fetchObject list may be less expensive as it uses the grouping and ordering of the database. 

 

Editing Drafts(versions) for others:
This is the most complicated part of what you have mentiond.. Drafts are owned by a specific user.. So, even though you may be able to alter some code to get tot he edit screen, content/action and it's cohorts are complicated parts of ezPublish and may have some code that gets unhappy with one user trying to save a draft owned by another user..  I would suggest you do one of the following dynamically before starting to edit:

  • Clone or copy the version (if you do this from ezContentObject as opposed to ezContentObjectVersion, then the new version will be created by the logged in user)
    Note: This has the overhead of increasing version numbers and may cause a headache
  • OR just before directing the user to content/edit, dynamically change the creator_id (part of the version, not the object) so that th person editing is the one that ezPublish would expect[queue grumble noise of audit-conscious people].

A note on who can edit what:
Somewhere in the logic above, you probably want to make sure that the drafts shown are drafts that the current user can actually edit. Otherwise, when they go to save (or somewhere else in the process) they will be faced with a permission denied error.  So, I suggest that your fetch also include logic to filter those objects that the user actually has permission to edit.  This will have some overhead, but is cleaner than letting them get part of the way through the process and then have a permission issue.

Modified on Tuesday 26 June 2012 3:59:07 pm by David Ennis

Wednesday 27 June 2012 3:53:33 pm

Ok, thanks for your detailed answers !

@Remy MOURARD : your solution simply works !

I've now my list of ALL DRAFTS happy.gif Emoticon

But when I click on one, to edit the draft, Ez displays an error.

I can not edit other users drafts.

 

I've searched on the forum how to solve this issue, but it still doesn't work...!

 

Thanks again for your help !

Wednesday 27 June 2012 4:10:18 pm

Hi,

You are welcome blunk.gif Emoticon

You actually cannot edit the others user draft because the creator_id field of it's version.

You have to find a way to set this field to your current user id, then you could edit the draft.

Just don't forget to change back this field with the original user id to let him edit his draft anymore.

regards,

Wednesday 27 June 2012 4:16:09 pm

Quote from Arnaud Cabrolier :

Ok, thanks for your detailed answers !

@Remy MOURARD : your solution simply works !

I've now my list of ALL DRAFTS happy.gif Emoticon

But when I click on one, to edit the draft, Ez displays an error.

I can not edit other users drafts.

 

I've searched on the forum how to solve this issue, but it still doesn't work...!

 

Thanks again for your help !

HI.

in my posty above, I described two ways around this expected issue:

1 - create a new draft for the user that is going to edit (this new draft is 'owned' by the user logged in (creator_id is set properly) - but then you may have a version limit issue..

OR

2 - dynamically change the creator_id of that version just before editing it (not nice for audit purposes, but completely doable - module that simply changes creator_id on a content/version and then passes you to content/edit/id/version
Keep in mind that this will get you around the 'owner' issue for editing the draft, but still, not all content is editable by all users for various granular permission reasons, so to truly complete your modification, you should be filtering on content that is editable by the logged in user (after changing the ownership of the draft)
-david

Thursday 28 June 2012 10:29:34 am

Ok,

Thanks David for your help !

Now, users click on the "pain button" to edit; they are redirected on a versions table of the draft.

They must duplicate the last version and edit it to add modifications.

But now, on my drafts fetch, I see all the versions !

Can I make a DISTINCT filter to fetch only the last version ?

 

Thanks for your help !

Thursday 28 June 2012 10:50:17 am

Quote from Arnaud Cabrolier :

Ok,

Thanks David for your help !

Now, users click on the "pain button" to edit; they are redirected on a versions table of the draft.

They must duplicate the last version and edit it to add modifications.

But now, on my drafts fetch, I see all the versions !

Can I make a DISTINCT filter to fetch only the last version ?

 

Thanks for your help !

Hi.
I noted that you opened a separate forum topic for this question: "DISTINCT filter on a fetch function"
- Could you please close this one as solved and I'll reply to the new topic posted.
Thanks,

David

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from