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

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

eZ debug

Timing: Jan 18 2025 19:19:38
Script start
Timing: Jan 18 2025 19:19:38
Module start 'layout'
Timing: Jan 18 2025 19:19:38
Module start 'content'
Timing: Jan 18 2025 19:19:39
Module end 'content'
Timing: Jan 18 2025 19:19:39
Script end

Main resources:

Total runtime0.8477 sec
Peak memory usage4,096.0000 KB
Database Queries82

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0077 587.9297152.6250
Module start 'layout' 0.00770.0031 740.554739.4453
Module start 'content' 0.01080.8353 780.0000710.9141
Module end 'content' 0.84610.0016 1,490.914124.1406
Script end 0.8477  1,515.0547 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00340.3998160.0002
Check MTime0.00130.1496160.0001
Mysql Total
Database connection0.00250.295010.0025
Mysqli_queries0.748188.2430820.0091
Looping result0.00070.0863800.0000
Template Total0.813696.020.4068
Template load0.00210.244820.0010
Template processing0.811595.723020.4057
Template load and register function0.00010.011310.0001
states
state_id_array0.00100.113710.0010
state_identifier_array0.00110.126720.0005
Override
Cache load0.00200.2354860.0000
Sytem overhead
Fetch class attribute can translate value0.00060.067540.0001
Fetch class attribute name0.00170.2038120.0001
XML
Image XML parsing0.00110.130640.0003
class_abstraction
Instantiating content class attribute0.00000.0053180.0000
General
dbfile0.00100.1131240.0000
String conversion0.00000.001240.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
8content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
10content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
17content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
5content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
4content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 46
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs