eZ Community » Forums » Developer » Filtering on "multiple selection"...
expandshrink

Filtering on "multiple selection" field values

Filtering on "multiple selection" field values

Friday 30 March 2012 7:26:34 pm - 2 replies

Hi there!

I have class named "event", with a selection (multiple value) field named "category" (attribute 575).

I have another class named  "page" with another selection (single or multiple value... doesn't matter) field named event_type.

 

How can I fetch all the event belonging to a certain category specified in my page?

 

That's how I tried:

{def $today=currentdate()   
      $class_array=array('event')         
      $class_filter_type='include'         
      $page_limit='10'
      $news_filter = array() }

 {foreach $node.data_map.news_type.content as $TN}
    {set $news_filter = $news_filter|append($TN)}
{/foreach}
{def $list_items=fetch( 'content', 'list', hash( 'parent_node_id', 112,                                                
                                                               'class_filter_type', $class_filter_type,
                                                                'class_filter_array', $class_array,
                                                                'limit', $page_limit,
                                                                'offset', $view_parameters.offset,
                                                                'depth_operator', 'eq',                                                   
                                                         'attribute_filter', array(
 array( 575, 'in', $news_filter ) ),                                                                                         'sort_by', array( array('attribute', false(), 'event/from_time') )                                                  ) ) 

 

It's easy to see that it's not going to work because my attribute n.575 is an array and I'm trying to compare it to another array. I need something to say: select this event if one of the value of my attribute 575 appears into my $news_filter array.

 

Is that possible??

 

EDIT

Hi again,

I was thinking about my code and I guess that a solution should be something like "contains" as a match type for attribute_filter. Something like that:

{set $news_filter = $news_filter|append('or')}
{foreach $node.data_map.news_type.content as $TN}
    {set $news_filter = $news_filter|append( array(575,'contains',$TN) )}
{/foreach} 

{def $list_items=fetch( 'content', 'list', hash(
                                             ....
                                             'attribute_filter', $news_filter,
                                              ... 

 

But documentation does not report 'contains' as a valid match criteria for filtering!!

How can I solve this big problem? I have to publish te site very soon... I really need your help!

Thank you

Modified on Saturday 31 March 2012 10:14:38 am by Simone Conti

Monday 02 April 2012 3:46:14 pm

Hi Simone,

If you want all the element linked to an another one, you should use reverse_related_objects ( http://doc.ez.no/eZ-Publish/Technical-manual/4.x/Reference/Modules/content/Fetch-functions/reverse_related_objects ).

I use it for the same kind of things and it works well blunk.gif Emoticon

Monday 02 April 2012 4:58:34 pm

Hi Simone,

In documentation say:

Filtering on the attribute level is supported for the following datatypes:

  •  Checkbox
  •  Date
  •  Date and time
  •  E-mail
  •  Integer
  •  Object relation
  •  Selection (will not work when used as multiple selector)
  •  Text line
  •  Time

I think your solution is to create a custom extended_attribute_filter or a custom template operator.

expandshrink

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

36 542 Users on board!

Forums menu

Proudly Developed with from