Create Object and Child Folder at the same time

Author Message

Håkan Bergman

Monday 15 November 2010 6:37:59 am

Hello,

We have a customer who wants bloggers to blog from the frontsite of Ez Publish.

Everything is working fine, but they want the blogger to have a sorted folder (automatically).

So what we have now is a root node for the blogger to blog to and create blog posts after login.

It basically looks like this:

* Root folder

-> Blog posts

Our customer would like it to be this way instead:

* Root folder

-> Year

--> Month

---> Blog post

So the tree is better/easier overviewed inside of ez publish Admin.

I am using the built in function content/action with a hidden node id to store the content at that location. But the script should automatically know that its 2010, november, 15th and create a sub/child folder and then re-node the content to that place.

So if we create "root folder" and point the blogger there.

The script will have to be able to tell that 2010 doesnt exist (create) and the month of that new folder (2010) does not exist (create november) and then store the new object in that node. Is there a way to do this without using extensions? I would like to tell the system to start at node X, create 2 folders then store the data (if the folders does not exist), otherwise just store the data in the appropriate folder.

Best regards,

Håkan Bergman

Heath

Monday 15 November 2010 9:41:17 pm

Hello Håkan,

I too have had customer requests for this exact functionality in the past! In the past we simply created the content structure by hand as needed.

But the solution you describe would be a great contribution for the rest of the community as well.

If you do create the solution you describe would you consider sharing it with the community on http://projects.ez.no

Cheers,

Heath

Brookins Consulting | http://brookinsconsulting.com/
Certified | http://auth.ez.no/certification/verify/380350
Solutions | http://projects.ez.no/users/community/brookins_consulting
eZpedia community documentation project | http://ezpedia.org

Nicolas Pastorino

Monday 15 November 2010 11:24:16 pm

Hi Håkan,

Sounds like a nice feature to have, pretty standard for blogging platforms. One extension exists, under the form of a workflow : Subtree Skeleton Publisher, http://projects.ez.no/ezssp , implementing a similar concept. Much of the code there is likely to be directly re-usable. Also, contributing back to this extension could be a smart move, enlarging its functional scope.

Cheers !

--
Nicolas Pastorino
Director Community - eZ
Member of the Community Project Board

eZ Publish Community on twitter: http://twitter.com/ezcommunity

t : http://twitter.com/jeanvoye
G+ : http://plus.tl/jeanvoye

Håkan Bergman

Tuesday 16 November 2010 2:39:20 am

Thank you for your input.

I Copied the function NewButton that is available at kernel/content/action.php into a new file and made en extension of it.

I am using the class blog_list as the root class for blog_post.

So I did it like this:

IF post to blog_list (node class I am are posting to)

Loop through childs

IF name of child is a blog_folder and name is YEAR

Loop trough that node and its childs

IF name of child is a blog_folder and name is MONTH

Set the node to this NodeID

The ELSE to the second IF is:

ELSE create blog_folder named YEAR

FETCH id of that NODE

create blog_folder named MONTH

Fetch ID of that NODE

set $node = eZContentObjectTreeNode::fetch($node);

Then the normal action script will proceed as normal, just that I switched ID to where the post should be created to the MONTH ID instead of the root folder ID.

I've made an extension and named it ezcreateobject and made a view of createSubFolders.

I am no extension expert so I will just post a link to my solution and if someone with more knowledge could make it better and then maybe post a project on it.

Link: http://s61762.gridserver.com/ezextensions/ezcreateobject_new.zip

This is a very hard coded version, this should be done more through INI-files and hidden form attributes, but it will get people like myself started and probably find a quick solution to things at hand.

Thanks again for your input.

Best regards,

Håkan Bergman

Gaetano Giunta

Tuesday 16 November 2010 4:15:54 am

I'd also suggest improving the existing workflow-based extension rather than hardcoding this into content/action stuff...

Principal Consultant International Business
Member of the Community Project Board

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