Forums / Setup & design / Fetch children of node in media section

Fetch children of node in media section

Author Message

Luke Barton

Tuesday 06 June 2006 12:32:57 am

Hi,

I need help fetching the children of a folder in the media section so that I can randomly display an image, but the fetch returns nothing.

Here's what I've done:

1. I have set anonymous user's role to read content from Media.

2. I can fetch a single image node in that folder and display that image:


{let img_node=fetch( 'content', 'node', hash( 'node_id', 98 ) )}
     {attribute_view_gui attribute=$img_node.data_map.image image_class=original}
{/let}

3. Whenever I fetch a list of children of a node in the Media section, the children_count is zero.


{let img_parent_node=fetch( 'content', 'list', hash( 'parent_node_id', 94 ) )}
     {$img_parent_node|attribute(show)}
{/let}

4. I've cleared the cache from the command line and from the EZP UI several times.

5. If I created the same folder structure in the content tree, everything works. But I do not want to store the image library in the content tree.

I'm using EZP 3.8.0.

Thanks in advance for your help. I'm sure it is a simple modification to a setting, but I cannot think clearly anymore.

-Luke

Kristof Coomans

Tuesday 06 June 2006 1:38:36 am

Hi Luke

Can you enable SQL debugging and then search the query resulting from the template code mentioned in point 3? It could help you finding out what goes wrong.

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Luke Barton

Tuesday 06 June 2006 2:22:04 am

Krisof,

Thanks for the fast response. Based on your suggestion, I issued this template code:

{let img_list=fetch( 'content', 'list', hash( 'parent_node_id', 94 ) )}
	{$img_list|attribute(show)}		
{/let}

The queries of interest are below. I find this "where" clause interesting:

WHERE path_string like '/1/43/51/67/94/%' and depth <= 5 and  ezcontentclass.version=0 AND <...>

It seems that the item might be too deep. Is depth an .ini setting?

I re-issued the fetch like this:

{let img_list=fetch( 'content', 'tree', hash( 'parent_node_id', 94 ), 'depth', 10 )}
	{$img_list|attribute(show)}		
{/let}

The resulting WHERE clause had no depth parameter:

WHERE  path_string like '/1/43/51/67/94/%' and ezcontentclass.version=0 AND <...>

But I still cannot fetch a list of images from a folder in the media section.

Thanks in advance for any followup advise.

-Luke

This is the original SQL output of interest:

Notice: eZMySQLDB::query(1 rows, 0.519 ms) query number per page:8  	Jun 06 2006 08:58:14

SELECT ezcontentobject.*
FROM
    ezcontentobject
WHERE
    ezcontentobject.id='94'

	

Notice: eZMySQLDB::query(1 rows, 0.920 ms) query number per page:9 	Jun 06 2006 08:58:14

SELECT ezcontentobject.*,
                       ezcontentobject_tree.*,
                       ezcontentclass.name as class_name,
                       ezcontentclass.identifier as class_identifier
                       , ezcontentobject_name.name as name,  ezcontentobject_name.real_translation 
                FROM ezcontentobject_tree,
                     ezcontentobject,
                     ezcontentclass
                     , ezcontentobject_name 
                WHERE node_id IN ( 94 ) AND
                      ezcontentobject_tree.contentobject_id=ezcontentobject.id AND
                      ezcontentclass.version=0  AND
                      ezcontentclass.id = ezcontentobject.contentclass_id
                       AND 
 ezcontentobject.language_mask & 7 > 0 

                       and  ezcontentobject_tree.contentobject_id = ezcontentobject_name.contentobject_id and
                                  ezcontentobject_tree.contentobject_version = ezcontentobject_name.content_version and 
 ( ezcontentobject_name.language_id & ezcontentobject.language_mask > 0 AND
     ( (   ezcontentobject.language_mask - ( ezcontentobject.language_mask & ezcontentobject_name.language_id ) ) & 1 )
   + ( ( ( ezcontentobject.language_mask - ( ezcontentobject.language_mask & ezcontentobject_name.language_id ) ) & 4 ) >> 1 )
   + ( ( ( ezcontentobject.language_mask - ( ezcontentobject.language_mask & ezcontentobject_name.language_id ) ) & 2 ) << 1 )
   <
     ( ezcontentobject_name.language_id & 1 )
   + ( ( ezcontentobject_name.language_id & 4 ) >> 1 )
   + ( ( ezcontentobject_name.language_id & 2 ) << 1 )
 )

Notice: eZMySQLDB::query(0 rows, 1.227 ms) query number per page:9 	Jun 06 2006 08:58:14

SELECT ezcontentobject.*,
                       ezcontentobject_tree.*,
                       ezcontentclass.name as class_name,
                       ezcontentclass.identifier as class_identifier
                       
                       , ezcontentobject_name.name as name,  ezcontentobject_name.real_translation 
                   FROM
                      ezcontentobject_tree,
                      ezcontentobject,ezcontentclass
                      , ezcontentobject_name 
                      
                      
                      
                   WHERE
                       path_string like '/1/43/51/67/94/%' and  depth <= 5 and  
                      
                      
                      
                      ezcontentclass.version=0 AND
                      node_id != 94 AND
                      ezcontentobject_tree.contentobject_id = ezcontentobject.id  AND
                      ezcontentclass.id = ezcontentobject.contentclass_id AND
                      
                      
                       ezcontentobject_tree.contentobject_id = ezcontentobject_name.contentobject_id and
                                   ezcontentobject_tree.contentobject_version = ezcontentobject_name.content_version and 
 ( ezcontentobject_name.language_id & ezcontentobject.language_mask > 0 AND
     ( (   ezcontentobject.language_mask - ( ezcontentobject.language_mask & ezcontentobject_name.language_id ) ) & 1 )
   + ( ( ( ezcontentobject.language_mask - ( ezcontentobject.language_mask & ezcontentobject_name.language_id ) ) & 4 ) >> 1 )
   + ( ( ( ezcontentobject.language_mask - ( ezcontentobject.language_mask & ezcontentobject_name.language_id ) ) & 2 ) << 1 )
   <
     ( ezcontentobject_name.language_id & 1 )
   + ( ( ezcontentobject_name.language_id & 4 ) >> 1 )
   + ( ( ezcontentobject_name.language_id & 2 ) << 1 )
 ) 

                      AND ezcontentobject_tree.is_invisible = 0
                       AND ((ezcontentobject.section_id in (1))) 
                       AND 
 ezcontentobject.language_mask & 7 > 0 

                 ORDER BY  path_string ASC

Kristof Coomans

Tuesday 06 June 2006 2:45:58 am

Hi Luke

It seems that the item might be too deep. Is depth an .ini setting?

No, depth is used there to only fetch children of the node, and not just any descendant.

Your SQL output, and especially this condition:

... ezcontentobject.section_id in (1) ...

makes me think the user does not have sufficient rights to read the media section. Check the policies assigned to your user and if they are allright, then clear all caches and retry.

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Luke Barton

Tuesday 06 June 2006 3:15:53 am

Kristoff,

Thanks for the clarification.

I thought about user privileges as well. The user can see a single image, so it seems that the privileges are correct, unless another privilege is required to fetch a list.

I cleared the cache from the command line and checked the policy and reloaded the page. Here's a screen shot:
http://clients.lukebarton.com/public_images/ezp/ez_anon_policy_clear_cache.gif

Right now, I'm issuing 2 fetches:
1. Just show a temporary image from the group of images from which I would like to randomly select an image.

2. Try to get the children of the parent folder. Once I get that, I know how to use "|shuffle" and then pick the first child of the array to achieve a random selection.

You can see the actual page here:
http://ggf.ten24inc.com/industry_insights

If you view source and search for "EZP:" you'll see HTML comments where the fetches should be taking place.

Thanks again for all of you help.

-Luke

Kristof Coomans

Tuesday 06 June 2006 4:20:52 am

The content/node fetch function doesn't test if you have permission to read the node. The content/list and content/tree fetch functions do.

But your permissions seem to be allright, so there has to be another problem.

What do you get when using this code:

{let $img_nodes=fetch('content','tree',hash('parent_node_id', $mediaNodeID,                 'class_filter_type','include', 'class_filter_array', array('image')))}
{$img_nodes|attribute(show)}
{/let}

Replace or set $mediaNodeID to the top node id of your media tree.

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Luke Barton

Tuesday 06 June 2006 5:54:10 am

Kristof,

I've added a few fetches to the template:

1. Your suggestion with the class filter on image.

2. Your suggestion without the class filter.

3. Then I tried to fetch the tree of each folder in the directory structure housing the image.

You can view the static output of the page here:
http://ggf.ten24inc.com/media_fetch_static.html

You can search the source code for "EZP: Kristof" to find the code in question.

Thanks again.

-Luke

Kristof Coomans

Tuesday 06 June 2006 6:47:19 am

Hi Luke

I'm still seeing all those conditions like

ezcontentobject.section_id in (1)

. Strange.

Can you do this to take a look at the current user's policies:

     {let $currentUser=fetch('user','current_user')}
        {$currentUser.login|wash}
        {foreach $currentUser.roles as $role}
            {$role.policies|attribute(show)}
        {/foreach}
     {/let}

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Luke Barton

Tuesday 06 June 2006 7:11:24 am

Krisof,

Thanks for the troubleshooting.

The result of your fetch is here:
http://ggf.ten24inc.com/media_fetch_static.html

It's generated from this page (look at bottom of source code):
http://ggf.ten24inc.com/microfinance

-Luke

Kristof Coomans

Tuesday 06 June 2006 7:23:24 am

At first sight your policies seem allright.

Just to be absolutely sure, can you replace {$role.policies|attribute(show)} with:

{foreach $role.policies as $policy}
{$policy.limitations|attribute(show)}
{/foreach}

and show me what you get now.

Which version of eZ are you using?

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Luke Barton

Tuesday 06 June 2006 8:32:05 am

Kristof,

I added your output and a few more:

{let $currentUser=fetch('user','current_user')}
	{$currentUser.login|wash}
    {foreach $currentUser.roles as $role}
		<b>POLICY</b>
		{$role.policies|attribute(show)}			
	
		 <b>LIMITATIONS</b>
		{foreach $role.policies as $policy}
			{$policy.limitations|attribute(show)}
			
			<b>SUB POLICY OBJECT</b>
			{$policy.limitations.0.policy|attribute(show)}
			
			<b>SUB POLICY VALUES</b>
			{$policy.limitations.0.values|attribute(show)}			
		{/foreach}
	{/foreach}
{/let}

The static result is here:
http://ggf.ten24inc.com/media_fetch_static.html

The generating page is here with debug turned back on with SQL output:
http://ggf.ten24inc.com/microfinance

Thanks again.

-Luke

Kristof Coomans

Tuesday 06 June 2006 8:59:22 am

Hi Luke

Does it work now?
In you SQL debug output I see now:

AND ((ezcontentobject.section_id in (1)) OR (ezcontentobject.section_id in (3)))

That looks better.

What did you do to solve it?

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Luke Barton

Tuesday 06 June 2006 10:08:37 am

Kristof,

I still can't see the image or the SQL you quote.

The static result is here:
http://ggf.ten24inc.com/media_fetch_static.html

The generating page is here with debug turned back on with SQL output:
http://ggf.ten24inc.com/microfinance

Thanks so much for all of your follow through.

-Luke