Grouping by an attribute

Author Message

Pablo C. Vergara Castro

Tuesday 14 September 2004 6:26:29 am

Hi to all.

I would like to know the way to make fetch that simply return objects grouped by a certain attribute. For example, I have several objects of a class "publication" that have an attribute "date", and what I want it is to know the way to extract the dates that are different and in addition to solely be able to count them.

{... 1999 ...},{... 2000 ...},{... 1999 ...},{... 2001 ...},{... 2000 ...} ===> {1999},{2000},{2001}, (3 attributes)

Sven Anderson

Wednesday 15 September 2004 3:20:25 am

If it's an existing arry, have a look here:
http://www.ez.no/community/forum/developer/sorting_an_array

If you get your array by the fetch functions, have a look here:
http://www.ez.no/ez_publish/documentation/development/libraries/ez_template/operators/data_fetch

hoping this helps,

greets,
Sven

Pablo C. Vergara Castro

Wednesday 15 September 2004 3:46:52 am

Thanks Sven but

a) The first link is really too old and the only answer that it gives is that ez can't sort.

b) I know the steps to sort data using fetch function but I don't want to sort, the think I want to do is Grouping by.

Sort:

{... 1999 ...},{... 2000 ...},{... 1999 ...},{... 2001 ...},{... 2000 ...} ===>{... 1999 ...},{... 1999 ...},{... 2000 ...},{... 2000 ...},{... 2001 ...}

Group:

{... 1999 ...},{... 2000 ...},{... 1999 ...},{... 2001 ...},{... 2000 ...} ===> {1999},{2000},{2001}

I begin to think that at the moment ezpublish cannot group data :_(.

Ekkehard Dörre

Wednesday 15 September 2004 5:28:36 pm

in 3.3 blog template archive_navigatorbar.tpl there is a "group_by":

{let show_week=false()
     item_node_id=50
     month_list=fetch( content, tree, hash( parent_node_id, $item_node_id,
                                            class_filter_type, include,
                                            class_filter_array, array( 'log' ),
                                            attribute_filter, array( and, array( 'published', '>=',
                                                                                  maketime( 0, 0, 0, $today_info.month, 1, $today_info.year ) ),
                                                                          array( 'published', '<=',
                                                                                  maketime( 23, 59, 59, $today_info.month | inc, 0, $today_info.year ) ) ),
                                            group_by, array( "published", "day" ),
                                            as_object, false() ) )
     month=$month_list|month_overview( 'published', maketime( 0, 0, 0, $today_info.month, $today_info.day, $today_info.year ),
                                        hash( current, maketime( 0, 0, 0, $today_info.month, $today_info.day, $today_info.year ),
                                              current_class, 'selected',
                                              link, concat( "content/view/full/", $item_node_id ),
                                              month_link, true(), year_link, true(), day_link, true(),
                                              next, hash( link, concat( "content/view/full/", $item_node_id ) ),
                                              previous, hash( link, concat( "content/view/full/", $item_node_id ) )  ) )}

other tread:
http://ez.no/community/forum/setup_design/group_by_parameter_in_fetch_function

Greetings, ekke

http://www.coolscreen.de - Over 40 years of certified eZ Publish know-how: http://www.cjw-network.com
CJW Newsletter: http://projects.ez.no/cjw_newsletter - http://cjw-network.com/en/ez-publ...w-newsletter-multi-channel-marketing

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