Forums / General / How to limit "Object relations" fetched

How to limit "Object relations" fetched

Author Message

Stéphane Bullier

Thursday 16 February 2006 5:46:20 am

Hello,

After looking for in the forum, I can't find a answer to my question :

I have 3 classes : "Artist", "Tools" and "News".

The attributes of "Artist" class are :
1. name
2. description
3. related_tools (Object relations)
4. related_news (Object relations)

On full view of artist node, I would like to have max 3 tools and 3 news related to the artist.

For related tools, I use :

{def $tools = fetch( 'content', 'related_objects',	
	                          hash( 'object_id',                   $node.object.id,
					     'attribute_identifier',    'artiste/tool_relie',
					    'sort_by',                        array( array( 'published', false() ) ) ) )}
{foreach $tools as $tool}
 {$tool.name|wash()}
 {attribute_view_gui attribute=$tool.data_map.type_tools}
 {$tool.data_map.date.data_int|datetime( 'mydate' )}
 {attribute_view_gui attribute=$tool.data_map.image}
 {attribute_view_gui attribute=$tool.data_map.description}
{/foreach}

If have more than 3 related tools, it's not possible to limit like in fetch list.

Any suggestion. Thank.

PS : I use ezpublish version 3.7.3 on apache2 and php 4.4.0-3 (Ubuntu).

Stéphane

Stéphane Bullier

Monday 20 February 2006 1:08:49 am

Hello,

No answer of my question..

I will try to rewrite :

What is the best way to have on view full of an node (artist in my case) link to news article limited at 3 ?

Stéphane

Stéphane Bullier

Monday 20 February 2006 2:28:45 am

I'm try to use max in foreach controller :

{def $actus = fetch( 'content', 'list', 
	 				 hash( 'parent_node_id', 	  59,
	 				 	   'sort_by',             $node.sort_array,
	 				 	   'only_translated',     only_translated ) )}
	 	 				 	  
<h3>News of artist</h3>
<ul>
{foreach $actus as $actu max 3}
   {if eq($actu.data_map.artiste_lie.content.keyword_string|contains( $node.name ), 1)}
    <li><a href={$actu.url_alias|ezurl()}>{$actu.name|wash()}</a></li>
	{/if}
{/foreach}
</ul>

It's not working. I have no result.

Any idea.

Stéphane

Tore Skobba

Monday 20 February 2006 2:29:25 am

Hi

You can use the limit parameter for your fetch (limit,3), i.e.

{def $tools = fetch( 'content', 'related_objects',
hash( 'object_id', $node.object.id, 'attribute_identifier', 'artiste/tool_relie',
'sort_by', array( array( 'published', false() ),limit,3 ) ) )}

Alternativley you can also set an maximum number of iterations for your foreach loop using "max" as described here: http://ez.no/doc_hidden/ez_publish/technical_manual/3_6/reference/template_control_structures/looping/foreach

Stéphane Bullier

Monday 20 February 2006 5:43:53 am

Hi Tore Skobba,

Thank you for your answer.

But I repeat : I have a problem with "max" in my foreach loop.

Is the code of my 3td message is correct ?

For example, in one case, I have 10 news article related to one artist with keyword. When I use max 3, thereis no list of news articles. When I use max 13, I got the 3 last news articles. I don't understand the use of max operator.

Thank for some informations.

Cheers.

Stéphane

Łukasz Serwatka

Monday 20 February 2006 6:00:47 am

Hi bobo,

Your code checks if fetched objects contains keyword,

{foreach $actus as $actu max 3} 
  {if eq($actu.data_map.artiste_lie.content.keyword_string|contains( $node.name ), 1)} 
   <li><a href={$actu.url_alias|ezurl()}>{$actu.name|wash()}</a></li> 
        {/if} 
{/foreach} 

So if first 3 did not match, then you will see nothing. max means that foreach will loop 3 times only and stop.

What you can do is build new array base on your condition in foreach, then loop throw this array and display data. In other words you will have array only with results which matches your condition. This is of course a little redundant, but still a solution.

Next thing what you can use is "keyword" fetch function. More info and examples you can find here:

http://ez.no/doc/ez_publish/technical_manual/3_6/reference/modules/content/fetch_functions/keyword

Hope it will help you.

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

Stéphane Bullier

Monday 20 February 2006 6:31:27 am

Thank Lukasz Serwatka,

I understand how "max" run now.

I have looked in documentation about fetch keyword.

I try this code :

{def $list=fetch( 'content', 'keyword',
                  hash( 'alphabet', $node.name,
                        'classid',   16,
                        'limit',    3 ) )              
     $count=fetch( 'content', 'keyword_count',
                   hash( 'alphabet', $node.name,
                   'classid',   16, ) )}

There are {$count} number of nodes using keywords starting with "{$node.name}".
 
{foreach $list as $element}
    {$element.link_object.name|wash} ({$element.keyword|wash}) <br />
{/foreach}

but for a "news" article with one keyword like $node.name I have :
There are 2 number of nodes using keywords starting with "<$node.name>".
Nouvelle release de Leanne (Leanne)
Nouvelle release de Leanne ()

I don't understand why I got 2 results and not only one.

If you have some advices ?

Stéphane

Stéphane Bullier

Tuesday 14 March 2006 8:10:56 am

Hi,

No people are some advice. Please help me !

Stéphane

Benj Duval

Wednesday 22 March 2006 4:46:12 am

Hi Bobo,
this is not a solution, just a question.

Can you explain me what you are trying to do please ?

Does your code automatically find and display related objects without having to manually relate an object with the other ?

Thanks,
Benj

Stéphane Bullier

Monday 27 March 2006 11:42:54 am

Hi Benj Duval,

I'm trying to show (or to post ) the related news (max 3) for each artist. Yes, my code display related objects without having to manually relate an object with the other. I'm using the attribute "Keyword" in my class "news" that corresponding to the name of the artist. So, when you display the artists' page you can see each related news of each artist. But for there is a bug in the fetch of keyword.

Thank.

Bobo

Stéphane