Caution: This documentation is for eZ Publish legacy, from version 3.x to 6.x.
For 5.x documentation covering Platform see eZ Documentation Center, for difference between legacy and Platform see 5.x Architecture overview.

list

Summary

Fetches the children of a node or a collection of nodes.

Usage

fetch( 'content', 'list',
 hash( 'parent_node_id',            parent_node_id,
     [ 'sort_by',                   sort_by,                   ]
     [ 'offset',                    offset,                    ]
     [ 'limit',                     limit,                     ]
     [ 'attribute_filter',          attribute_filter,          ]
     [ 'extended_attribute_filter', extended_attribute_filter, ]
     [ 'class_filter_type',         class_filter_type,         ]
     [ 'class_filter_array',        class_filter_array,        ]
     [ 'only_translated',           only_translated,           ]
     [ 'language',                  language,                  ]
     [ 'main_node_only',            main_node_only,            ]
     [ 'as_object',                 as_object,                 ]
     [ 'depth',                     depth,                     ]
     [ 'limitation',                limitation,                 ]
     [ 'ignore_visibility',         ignore_visibility,          ]
     [ 'load_data_map',         load_data_map,          ]
     [ 'objectname_filter',         objectname_filter,          ] ) )

Parameters

NameTypeDescriptionRequired
parent_node_id mixed The ID number(s) of the parent node(s). Yes.
sort_by array The sorting mechanism that should be used. No.
offset integer The offset to start at. No.
limit integer/boolean The number of nodes that should be fetched or false for no limit. No.
attribute_filter mixed The attribute level filter logic. No.
extended_attribute_filter mixed The extended attribute level filter logic. No.
class_filter_type string The type of class filtering (include/exclude). No.
class_filter_array array The classes that should be filtered. No.
group_by array DEPRECATED No.
only_translated boolean Translation filtering (on/off). DEPRECATED No.
language string The translations that should be fetched. No.
main_node_only boolean Type of nodes that should be fetched (all or main nodes only). No.
as_object boolean If TRUE (or omitted), an array of "ezcontentobjecttreenode" objects will be fetched. Otherwise, an array of arrays will be returned. No.
depth integer The maximum level of depth that should be explored (1 by default). No.
limitation array Limitation array (emtpy array = access override). No.
ignore_visibility boolean Makes it possible to fetch hidden nodes. No.
load_data_map boolean Forces preloading of data map when fetch is performed. Default is on if fetch returns less than 15 items. No.
objectname_filter string searches object names, which start with the given string: 'car' finds objects which names start with car and cars. 'others' finds objects which don't start with a letter. No.

Returns

An array of ezcontentobjecttreenode objects or FALSE.

Description

This function fetches the children of a single node or a collection of nodes. The parent node(s) must be specified using the "parent_node_id" parameter. This parameter can either be the ID number of a single node or an array containing several node ID numbers. The function will fetch the nodes that are directly under the specified parent node(s). The collection is returned as an array of ezcontentobjecttreenode objects. If no nodes are found or if an error occurs, the function will return FALSE. The optional "group_by" parameter (grouping on a date/time basis) is deprecated since this functionality is not supported by Oracle and PostgreSQL.

Sorting

The "sort_by" parameter makes it possible to sort the result in different ways. This parameter must be provided as an array. The first element of the array must be the desired sorting method. The second element of the array must be the sorting direction, it can be either true() or false() - ascending or descending. The following table shows the sorting methods that can be used.

Sorting method

Description

attribute

The nodes are sorted according to the value of a specific attribute.

class_identifier

The nodes are sorted by the class identifiers of the objects.

class_name

The nodes are sorted by the class names of the objects.

depth

The nodes are sorted by their depth in the content tree.

modified

The nodes are sorted by the modification time of the objects.

name

The nodes are sorted by the names of the objects.

path

The nodes are sorted by their node ID path strings (/1/2/43/56).

path_string

The nodes are sorted by their virtual path strings (/company/about).

priority

The nodes are sorted by their priority.

published

The nodes are sorted by the creation time of the objects.

section

The nodes are sorted by the section IDs of the objects.

It is possible to combine different sorting methods. For example, it is possible to sort the nodes alphabetically and by their publish date/time at the same time.

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

The syntax for doing attribute level sorting is almost the same as for normal sorting. The only difference is that the ID number or the identifier of the target attribute must be specified. If the identifier is used then both the identifier of the class and the attribute must be specified (separated by a slash, like this: "my_class/my_attribute"). Attribute sorting can only be used if the returned collection contains the same type of nodes.

Fetching subsets

By making use of the "offset" and "limit" parameters, it is possible to fetch only a subset of the collection that would have been returned if these parameters were omitted. While the "offset" parameter defines the start of the subset, the "limit" parameter defines the length (number of elements/nodes) of the subset. These parameters are processed at the final stage. In other words, it is possible to do advanced sorting/filtering and grab only a specific chunk of from the sorted/filtered/etc. collection.

Class filtering

The class filter mechanism is controlled by the "class_filter_type" and "class_filter_array" parameters. The "class_filter_type" parameter tells eZ Publish to include or exclude specific node types. This parameter must be either "include" or "exclude". It is not possible to include one set and to exclude another at the same time. The value of the "class_filter_array" parameter specifies the type of nodes that should be included or excluded. This parameter must be an array of class ID numbers or class identifier strings.

Attribute filtering

The attribute filter mechanism is controlled by the "attribute_filter" parameter. Attribute filtering makes it possible to fetch a set of nodes where an attribute (or several attributes) contains some specific data. 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

The "attribute_filter" parameter must be an array. The first element may be set to either "and" or "or" - this controls how the matching specified in the upcoming elements should be carried out. If this parameter is omitted, the system will default to "and". The rest of the elements are arrays, each array specifies a match. The elements in this array are:

  1.  Attribute ID
  2.  Match type
  3.  Match value

The attribute ID can be specified either as the ID number of the attribute or as a string that contains the identifier of the class and the identifier of the attribute separated by a slash. (Note that it is also possible to specify one of the pre-defined strings in order to do filtering on a non-attribute.) The ID number of the attribute or the identifier of the class and the attribute can be found when viewing/editing content classes.

The match type tells how eZ Publish should try to match the values. The match value is the data that should be matched. The following match types can be used:

Type

Description

=

Equal

!=

Not equal

<

Less than

>

Greater than

<=

Less than or equal to

>=

Greater than or equal to

in

Matches one of the array values

not_in

Does not match any of the array values

between

Is a part of the range determined by the start and end values

not_between

Is outside the range determined by the start and end values

like

Matches the wildcard string (the wildcard character is '*')

Note: the ‘state’ attribute filter only support =, !=, in, and not_in filter type. It is not possible to filter on attributes of different classes, for example it is not possible to filter on both "article/show_comments" and "folder/show_comments" in the same filter.

Filtering on a non-attribute

Instead of the class/attribute syntax, you can use "published" and "priority" as "AttributeID". It is also possible to use "owner" as "AttributeID" which refers to the owner's identifier of the content object. This can for instance be used to find all objects of a given user.

There are also some other pre-defined strings that can be used as "AttributeID" (refer to the following table). When one of these strings is used as "AttributeID", filtering is based on template object attributes (not on content object attributes). This means that if you use for example "priority" as "AttributeID", the system will check the value of the "priority" attribute of the "ezcontentobjecttreenode" objects that represent information about content nodes.

The following table describes the pre-defined strings and corresponding attributes.

Name

Description

class_identifier

The identifier of the class which the object encapsulated by the node is an instance of.

class_name

The name of the class which the object encapsulated by the node is an instance of.

depth

The depth of the node within the content node tree.

modified

A UNIX timestamp pinpointing the exact date/time when the object encapsulated by the node was last modified (the "modified" attribute of the corresponding "ezcontentobject" object).

modified_subnode

A UNIX timestamp pinpointing the exact time a sub node was changed.

name

The name of the object the node encapsulates.

owner

The ID number of the object representing the user who initially created the object (the "owner_id" attribute of the corresponding "ezcontentobject" object).

path

The node's path string (the "path_string" attribute).

priority

The node's priority.

published

A UNIX timestamp pinpointing the exact date/time when the object was published for the first time (the "published" attribute of the corresponding "ezcontentobject" object).

section

The ID number of the section that the object belongs to (the "section_id" attribute of the corresponding "ezcontentobject" object).

state

This parameter allows to filter on a content object state id or an array of content object states ids. This parameter only supports =, !=, in and not_in operator in the attribute filter. With = and != operators, it's possible to filter on a numeric id while in and not_in are dedicated to filter an array of id.

Extended attribute filtering

The "extended_attribute_filter" parameter can be used to do advanced attribute filtering. It is for expert/experienced users. This mechanism makes it possible to introduce additional SQL conditions within the fetch. It allows filtering based on values in custom tables and/or special filtering within the "ezcontentobject_attribute" table.

When an extended attribute filter adds a new column in the result set from the database, it is possible to use it for sorting, by specifying new_table.column in the sort_by parameter of the fetch.

The mechanism must be configured using a configuration override for "extendedattributefilter.ini". This file allows the site administrator to set up different custom filters. Each filter must be a named collection of configuration settings. The name of a filter is the name of the configuration block under which the filter's settings are defined. The following text shows an example that demonstrates the setup of a filter called "MyFilter".

#The name of the filter.
[MyFilter]
 
#The name of the extension where the filtering code is defined.
ExtensionName=myextension
 
#The name of the filter class.
ClassName=eZMyExtendedFilter
 
#The name of the method which is called to generate the SQL parts.
MethodName=createSqlParts
 
#The file which should be included (extension/myextension will automatically be prepended).
FileName=classes/ezmyextendedfilter.php

The function defined by the "MethodName" setting must return an associative array containing two strings:

array( 'tables' => '...', 'joins' => '...' , 'columns' => '...', 'group_by' => '...' ));

Up to 4.7 :

  • tables : must start with a comma. The rest of the string should contain a comma separated list of other tables that should be included in the query.
  • joins : will be added inside the "WHERE" section of the query. This string must start with a space and contain an "AND" and an additional space at the end.
  • columns : Additional columns to fetch in the query
  • group_by (not required) : Fill it with specific column when necessary

As of 5.0 :

  • tables : The tables you want to join using the JOIN/INNER JOIN syntax. Use ON clause for join conditions.
  • joins : Must NOT contain join conditions any more, but general filters that will be added inside the WHERE section of the query.
  • columns : Unchanged
  • group_by : Unchanged

The example below shows a solution that filters the content based on values within an additional/custom table. This table is joined with the node table (by object ID and object version). The additional/custom table would most likely be maintained by a special/custom datatype.

Note : This example is valid for eZ Publish versions up to 4.7. For 5.x, please refer to changes mentioned above.

class eZMyExtendedFilter
{
    /*!
     Constructor
    */
    public function __construct()
    {
        // Empty...
    }
 
    public function createSqlParts( $params )
    {
        $sqlTables= ', ezmyfiltertable ';
 
        $sqlJoins = ' ezcontentobject_tree.contentobject_id = ezmyfiltertable.contentobject_id AND ezcontentobject_tree.contentobject_version = ezmyfiltertable.version AND ';
 
        if ( isset( $params['value1'] ) )
        {
             $value1 = $params['value1'];
        }
        else
        {
             $value1 = "10";
        }
        if ( isset( $params['value2'] ) )
        {
             $value2 = $params['value2'];
        }
        else
        {
             $value2 = "10";
        }
 
        $sqlCondArray = array();
 
        $sqlCondArray[] = 'ezmyfiltertable.my_cond1 = ' . $value1;
 
        $sqlCondArray[] = 'ezmyfiltertable.my_cond1 = ' . $value2;
 
        $sqlCond = implode( ' or ', $sqlCondArray );
 
        $sqlCond = ' ( ' . $sqlCond . ' ) AND ' . $sqlJoins . ' ';
 
        return array( 'tables' => $sqlTables, 'joins' => $sqlCond, 'columns' =>'' );
 
    }
}

The following template code shows how the extended attribute filter (see the PHP code above) can be used within a fetch.

{fetch( 'content', 'list',
        hash( 'parent_node_id', 2,
              'sort_by', array( 'priority', false() ),
              'limit', 15,
              'extended_attribute_filter',
                            hash( 'id', 'MyFilter',
                                          'params', hash( 'value1', 15,
                                                        'value2', 30 ) ),
              'depth', 10,
              'main_node_only', true() ) )}

There is an additional example at the bottom of this page: Example 20.

Fetching main nodes only

The "main_node_only" parameter can be used to tell eZ Publish that it should only fetch main nodes (nodes that are main locations for content objects). This parameter is optional and can be set to either true() or false(). When set to true(), the fetch function will only return main nodes. This functionality can be used to avoid duplicates (different nodes but same objects) in the result.

Fetching translated objects only

Note: This description applies to eZ Publish 3.8 or earlier. The "only_translated" parameter is deprecated in all later versions. In some multi-language scenarios, not all objects are translated into other/all languages. When the "only_translated" parameter is set to "true()" the system will only fetch objects that have been translated into the language used by the siteaccess (the current language). The "language" parameter can be used to control which translations that should be fetched. The value of this parameter must be a valid locale string, for example "ger-DE".

Access override

The "limitation" parameter makes it possible to instruct the system to use an alternate set of access limitations instead of the ones that belong to the current user. This is typically useful when there is a need to fetch nodes that the current user does not have access to. All permission checking can be skipped by providing an empty array. It is also possible to provide arrays that dictate the access limitations of other users and/or virtual sets of limitations. The array follows an internal structure that will be documented in the future.

Visibility override

The "ignore_visibility" parameter makes it possible to fetch hidden nodes. It can be set to either "true()" or "false()". If set to "true()", the fetch will ignore the visibility flags of nodes and thus it will return all nodes regardless of their visibility status. In other words, this parameter overrides the "ShowHiddenNodes" configuration directive for a specific fetch operation in a template.

Examples

Example 1

{def $nodes=fetch( 'content', 'list',
        hash( 'parent_node_id', 42,
              'depth', 3 ) )}
 
{foreach $nodes as $node}
    {$node.name|wash} <br />
{/foreach}

This example demonstrates how to fetch nodes which are until the third level under the parent node number 42. Outputs the names of all these nodes.

Example 2

{fetch( 'content', 'list',
        hash( 'parent_node_id', 42,
              'sort_by',        array( 'published', false() ) ) )}

This example demonstrates how to fetch all nodes that are the children of node number 42. The nodes are sorted by the time they were created; the most recently created node will be the first element in the collection.

Example 3

{fetch( 'content', 'list',
        hash( 'parent_node_id', array( '42', '43', '45' ),
              'sort_by',        array( 'published', false() ) ) )}

This example demonstrates how to fetch all nodes that are the children of multiple nodes; number 42, 43 and 45. The nodes are sorted by the time they were created; the most recently created node will be the first element in the collection.

Example 4

{fetch( 'content', 'list',
        hash( 'parent_node_id', 42,
              'sort_by',        array( array( 'name',      false() ),
                                      array( 'published', false() ) ) )}

This example demonstrates how to combine different sorting methods. The fetch function will fetch the child nodes of node number 42. The fetched nodes will be sorted by their name and the time they were created.

Example 5

{fetch( 'content', 'list',
        hash( 'parent_node_id', 42,
              'sort_by',        array( 'attribute',
                                      false(),
                                      107 ) ) )}

This example demonstrates attribute sorting by using the ID number of the attribute.

Example 6

{fetch( 'content', 'list',
        hash( 'parent_node_id', 42,
              'sort_by',        array( 'attribute',
                                      false(),
                                      'person/last_name' ) ) )}

This example demonstrates attribute sorting by using the string notation to pinpoint the identifier of the class and the attribute.

Example 7

{fetch( 'content', 'list',
        hash( 'parent_node_id',     42,
              'class_filter_type',  'include',
              'class_filter_array', array( '13' ) ) )}

This example demonstrates how to use class filtering to fetch only nodes that reference objects that are instances of class number 13.

Example 8

{fetch( 'content', 'list',
        hash( 'parent_node_id',     42,
              'class_filter_type',  'include',
              'class_filter_array', array( 'folder' ) ) )}

This example demonstrates how to use class filtering to fetch only nodes that reference folder objects.

Example 9

{fetch( 'content', 'list',
        hash( 'parent_node_id',     42,
              'class_filter_type',  'exclude',
              'class_filter_array', array( 'article',
                                          'comment' ) ) )}

This example demonstrates how to use class filtering to exclude articles and comments from a fetch.

Example 10

{fetch( 'content', 'list',
        hash( 'parent_node_id',   42,
              'attribute_filter', array( 'or',
                                        array( 152, '=', 'abc' ),
                                        array( 153, '=', '42' ) ) ) )}

This example demonstrates how to do attribute filtering. Only nodes that have attributes number 152 and 153 set to "abc" and 42 respectively will be included in the result.

Example 11

{fetch( 'content',
        'list',
        hash( 'parent_node_id',   42,
              'attribute_filter', array( array( 'article/title',
                                        'like',
                                        '*story*' ) ) ) )}

This example demonstrates how to do attribute filtering. Instead of specifying the ID number of the attribute (as in the previous example), the identifier of the class and the attribute is used. Only article nodes that contain the text "story" in their title attribute will be included in the result.

Example 12

{fetch( 'content',
        'list',
        hash( 'parent_node_id',   42,
              'attribute_filter', array( array( 'article/image',
                                        '=',
                                        87 ) ) ) )}

This example demonstrates how to do attribute filtering using an attribute of the "Object relation" datatype. Only article nodes that store relation to the specified content object (object ID = 87) in their "image" attribute will be included in the result.

Example 13

{fetch( 'content',
        'list',
        hash( 'parent_node_id',   42,
              'attribute_filter', array( array( 'review/rating',
                                        'between',
                                        array( 0, 2 ) ) ) ) )}

This example demonstrates how to do attribute filtering using an attribute of the "Selection" datatype. Only review nodes that contain "Very good", "Good" or "Ok" (options 0, 1 or 2) in their "rating" attribute will be included in the result.

Example 14

{fetch( 'content',
        'list',
        hash( 'parent_node_id',   42,
              'attribute_filter', array( array( 'bug/priority',
                                        'in',
                                        array( 1, 4 ) ) ) ) )}

Fetches bugs with priority 1 and 4 (i.e. bug nodes that have their priority attribute set to 1 or 4).

Example 15

{fetch( 'content',
        'list',
        hash( 'parent_node_id',   42,
              'attribute_filter', array( array( 'bug/priority',
                                        'between',
                                        array( 2, 4 ) ) ) ) )}

Fetches bugs with priority 2, 3 and 4 (i.e. bug nodes that have their priority attribute value between 2 and 4).

Example 16

{fetch( 'content', 'list',
        hash( 'parent_node_id',   42,
              'attribute_filter', array( 'and',
                                        array( 'priority', '>', '20' ),
                                        array( 'article/title', '=', 'abc' ) ) ) )}

This example demonstrates how to do filtering on a non-attribute. Instead of specifying the identifier of the class and the attribute, "priority" is used. Only article nodes that have their title attribute set to "abc" and have a priority greater than 20 will be included in the result.

Example 17

{def $nodes=fetch( 'content', 'list',
        hash( 'parent_node_id', 42,
             'attribute_filter', array( 'and',
                                 array( 'owner',
                                  '=',
                                 $current_user.contentobject_id ) ,
                                 array( 'class_identifier', '=', 'folder' ) ) ,
             'depth', 3 ) )}
 
{foreach $nodes as $node}
    {$node.name|wash}<br />
{/foreach}
 
{undef $nodes}

Fetches folder nodes which are until the third level under the parent node number 42 and are created by the current user.

Example 18

{fetch( 'content', 'list',
        hash( 'parent_node_id',  2,
              'only_translated', true() ) )}

This example demonstrates how to fetch only nodes that reference objects that have been translated into the current language (the language that the siteaccess is using).

Example 19

{fetch( 'content', 'list',
        hash( 'parent_node_id',  2,
              'limit',           3,
              'only_translated', true(),
              'language',        'ger-DE' ) )}

This example demonstrates another way to fetch translated objects. The fetch will return nodes that reference objects which have been translated into the German language.

Example 20

{fetch( 'content', 'list',
        hash( 'parent_node_id', 2,
              'sort_by', array( 'priority', false() ),
              'limit', 15,
              'extended_attribute_filter',
                            hash( 'id', 'MyFilter',
                            'params', hash( 'value1', 'text1',
                                          'value2', 'text2' ) ) ) )}

This example demonstrates how the extended attribute filter can be used. The template code above will fetch objects that match the following condition: any object using the ezstring datatype containing either "text1" or "text2". The necessary PHP implementation is shown in the example below.

class eZMyExtendedFilter
{
    /*!
     Constructor
    */
    function eZMyExtendedFilter()
    {
        // Empty...
    }
 
    function createSqlParts( $params )
    {
        $sqlTables= ', ezcontentobject_attribute as myfilter_alias ';
 
        $sqlJoins = ' ezcontentobject_tree.contentobject_id = myfilter_alias.contentobject_id AND ezcontentobject_tree.contentobject_version = myfilter_alias.version AND myfilter_alias.data_type_string = "ezstring"  AND';
 
        if ( isset( $params['value1'] ) )
        {
             $value1 = $params['value1'];
        }
        else
        {
             $value1 = 'fooo';
        }
        if ( isset( $params['value2'] ) )
        {
             $value2 = $params['value2'];
        }
        else
        {
             $value2 = 'boooo';
        }
 
        $sqlCondArray = array();
 
        $sqlCondArray[] = 'myfilter_alias.data_text = "' . $value1 . '"';
        $sqlCondArray[] = 'myfilter_alias.data_text = "' . $value2 . '"';
 
        $sqlCond = implode( ' or ', $sqlCondArray );
 
        $sqlCond = ' ( ' . $sqlCond . ' ) AND ' . $sqlJoins . ' ';
 
        return array( 'tables' => $sqlTables, 'joins' => $sqlCond );
 
    }
}

Example 21

{fetch( 'content', 'list', hash( 'parent_node_id', 2,
                                'ignore_visibility', true() ) )}

This example demonstrates how to fetch nodes regardless of their visibility status. The operation above will return both visible and hidden nodes that are directly below node #2.

Example 22

{def $nodes=fetch( 'content', 'list', hash( 'parent_node_id', 2,
                                'as_object', false() ) )}
 
The result is an array of arrays. The first inner array reveals information about the node "{$nodes[0].name|wash}":
<br /> {$nodes[0]|attribute( show, 1 )}

This example demonstrates the behavior when the "as_object" parameter is set to FALSE. The following output will be produced:

The result is an array of arrays. The first inner array reveals information about the node "Multiprice products":

Attribute

Type

Value

contentclass_id

string

1

current_version

string

1

id

string

61

initial_language_id

string

2

is_published

string

 

language_mask

string

3

modified

string

1161682117

name

string

'Multiprice products'

owner_id

string

14

published

string

1161682117

remote_id

string

'f3f9d3443e61498e01523e3016ca136b'

section_id

string

1

status

string

1

contentobject_id

string

61

contentobject_is_published

string

1

contentobject_version

string

1

depth

string

2

is_hidden

string

 

is_invisible

string

 

main_node_id

string

63

modified_subnode

string

1161682290

node_id

string

63

parent_node_id

string

2

path_identification_string

string

'multiprice_products'

path_string

string

'/1/2/63/'

priority

string

 

sort_field

string

2

sort_order

string

 

class_name

string

'Folder'

class_identifier

string

'folder'

real_translation

string

'eng-GB'

Example 23

{def $items=fetch('content', 'tree', hash( 'parent_node_id', 2,
                         'attribute_filter', array( 'and',
                                               p;array('state', "=", 3))
                           ))}

The following fetch function would bring back all nodes under node 2 that has a state with the id of 3.

Balazs Halasy (06/02/2004 12:07 pm)

Sarah Haïm-Lubczanski (06/08/2014 4:21 pm)

André R., Geir Arne Waaler, Jérôme Vieilledent, Sarah Haïm-Lubczanski


Comments

  • like filter

    like is case sensitive when using postgresql

    would be nice to have ilike for case insensitive like.
  • limitation

    When 'limitation' is explained, it is refered to "limitations" witch is wrong.
  • Syntax for sorting by multiple attributes should be specified

    Example 3 should be complemented by an outline of the syntax for sorting by multiple attributes. For instance, replace the sentence

    "It is possible to combine different sorting methods. For example, it is possible to sort the nodes alphabetically and by their publish date/time at the same time."

    with

    "To combine several sorting methods, put the sort arrays in an outer array. See Example 3."
  • Sort by price datatype seems works as well

    Sorting on attribute level seems to work for the price datatype too. I assume that it works for all datatypes that have some content in the sort key string, so generally just try it out.
  • Multiple attribute sorting ?

    Seems not possible.

    Is it ?
    • Re: Multiple attribute sorting ?

      Yes, you can sort by multiple attributes using an array of arrays.
      This uses fetch_alias but it would be the same for fetch list.

      {set list_items=fetch_alias( children,hash( 'parent_node_id', $node.node_id,
                                                                   'offset', $view_parameters.offset,
                                                                   'sort_by', array( array( 'attribute', false(), 'news/sticky' ), array(  'attribute', false(), 'news/date')),
                                                                   'limit', $page_limit ) ) }
      
  • sorting by modified_subnode

    sorting method 'modified_subnode' don't seem to be documentet but works on list and tree fetch.
  • Extended attribute filter

    If you use an attribute filter, since the 3.10 version, the array to return is :
    array( 'tables' => '...', 'joins' => '...', 'columns' => '...' );
    
  • Don't forget attribute_filter 'not_like' in the doc

    for attribute_filter, we can use 'not_like' too.
  • pay attention to commas in attribute_filter-array

    If you're like me and coding a fetch() like this:

    {def $calist=fetch('content', 'list', hash(
        'parent_node_id', 6250,
        'attribute_filter', array(
            array( 'name', '=', $cacode ),
        ),
    ))}
    


    with a comma at the end of each line in an array or hash (so that you can easily remove/comment that line), you'll have no result. It took us a while to figure out that the comma after $cacode) generates a new empty entry in that array which results to false(). And since the default operation (if omitted) is 'AND', the whole attribute_filter returns false. In this example, eZ would see it like this:

    'attribute_filter', array('and', array( 'name', '=', $cacode ), false())
    


    So pay attention to your commas!
  • thank

    with this Doc, I understand well what I did not understand i.e. bases of ez
  • Good Doc

    Thank's for this doc i understand many things :)
  • 'only_translated? deprecated?

    I noticed that all PHP code related do 'only_translated' in ezcontentobjecttreenode.php is commented out in version 4.0.0. As a result the option does not work.
    Is this option on the "deprecating" way?

    g
    • Re: 'only_translated? deprecated?

      Your question is now posted here: http://issues.ez.no/13321.
      Thanks for your feedback.
    • Re: 'only_translated? deprecated? => workaround

      'only_translated' seems to work only when it is followed by 'language', 'xxx-YY'

      To filter on the current language, you can therefore use thise code :
      {def $locale = ezini( 'RegionalSettings', 'Locale', 'site.ini' )}
       
      {def $items=fetch( 'content', 'tree',
      		                   hash( 'parent_node_id', $node.node_id',
      		                   		'only_translated', true(),
                    					'language', $locale ))}
      


      It seems to work for me :-)
      I hope this will help...
      • Re: Re: 'only_translated? deprecated? => workaround

        I want to fetch all language node list, i set 'only_translated', false(), but it not work.
        I use below code:
        {def $items=fetch( 'content', 'list',
        hash( 'parent_node_id', $node.node_id' ))}
        the result is equal to:
        {def $locale = ezini( 'RegionalSettings', 'Locale', 'site.ini' )}
        {def $items=fetch( 'content', 'list',
        hash( 'parent_node_id', $node.node_id',
        'only_translated', true(),
        'language', $locale ))}
        but it is not i want.
  • many classes, one attribute

    Is it truely impossible to fetch different classes of content, and sort them by a common attribute ??

    {set $item_list = fetch('content', 'tree', hash( 'parent_node_id', $node.node_id,
    'sort_by', array( array('attribute',false(),'*/rating'), array('published',false()) ),
    'class_filter_type', 'include',
    'class_filter_array', array( 'article', 'slideshow', 'quizz' ) ) )} could have been so sexy!

    Nothing helps to avoid the need of inheritance...
  • Attribute filtering

    Looking into the code, it looks like the following datatypes also support attribute filtering: country, identifier, package, price, category.

    Nb: some of those attributes will be a bit hard to match against:
    - country datatype will return a comma-imploded list of country names
    - price type is multiplied by 100 and rounded to int

    all all strings to be matched against (even for string datatypes) are lowercase!!!
  • Attribute filtering on States in 4.1

    Though not documented, "states" are available as a attribute filter using a standard fetch('content', 'list', ...) function with an "attribute_filter" in 4.1.

    kernel/classes/ezcontentobjecttreenode.php - line #958

    // state only supports =, !=, in, and not_in
    // other operators do not make any sense in this context
    


    As an example, the following fetch function would bring back all nodes under node 2 with a that has a state with the id of 3.

    {def $items=fetch('content', 'tree', hash( 'parent_node_id', 2,
                                               'attribute_filter', array( 'and',
                                                                          array('state', "=", 3))
                                              ))}
    
    • Re: Attribute filtering on States in 4.1

      Sooo helpfull!
  • default sort order?

    It would be nice to have it specified here. It is, afaict, the same as set in the admin interface
  • Sorting on Object State

    It's possible to sort on Object State, here is the syntax :

    array( 'state', [Sorting Order], [Object State Group Id]  )
    


    Where [Sorting Order] is true() or false(), as always, and [Object State Group Id] is the groupe of object state on which you want to sort. It's then possible to sort on multiple Object State Groups.
  • attribute filter doesnt work

    if i make a fetch code like this,

    {def $news = fetch('content','list',hash(
    'parent_node_id',179,
    'depth',2,
    'limit',5,
    'sort_by',array('published',false()),
    'class_filter_type','include'
    'class_filter_array',array('article','blog')
    'attribute_filter_array',array('or',array('article/headline','=',1),array('blog/headline','=',1))
    ))}

    it doesnt work ... but if i removed the attribute_filter_array it works but of course without attributes filtering. and i'm very sure that the content that i expected to show is should be available from that fetch statement...so my question is, can attribute_filter_array work if we use class_filter_array?

    thanks
    • Re: attribute filter doesnt work

      I'm pretty sure up there above they wrote that you cannot filter objects of different classes in the same fetch ....
    • Re: attribute filter doesnt work

      attribute_filter_array isn't this something like attribute_filter
  • limitation example

    example for using "limitation"

     
    {def $newslist=fetch('content','tree',
                           hash('parent_node_id', 123,
                                'sort_by',array('published',false()),
                                'class_filter_type',  'include',
                                'class_filter_array', array('news','article'),
                                'limit',5,
                                'limitation', array( hash( 'Section', array( 1, 3, 6, 7 ) )
                                                   )
                                )
                         )
    }
     
    
  • class_filter_array and attribute_filter

    i`ve the same Problem is it solved ? have you found any solution ?
  • complexPublish

    Why is eZ Publish called eZ? I hope it doesn't stand for easy...

    Ok, ofcourse it's much easier than building from scratch indeed! But for a CMS... I think it's way too heavy and too complex to be called eZ.

    What a hell of configuration files, unbelievable! And for what? Convention over configuration is something that I believe is much EZier!

    I also wonder why it has an own proprietary template language for views? Why not good old PHP? An extra language is an extra burden and an extra complexity for developers. Instead of making it simpler, you end up figuring out how things are done in this 'special language' instead of PHP. It's far more eZ to stick with a language that everyone knows. :S

    And then there's the documentation part. It seems cool, and there is a lot of documentation at first sight. But every time I encounter a problem, and search for it, I'm usually 'the first guy on the net' that encounters it. And then I end up digging into the codes of eZ Publish. What it seems to be missing is large community of eZ Publish lovers that like to talk about it. When I dig into the documentation it's very abstract and seems to be missing in depth tutorials.

    And a little in contradiction what is more powerful, something that everybody understands immediately? Or all the documentation in the world? In my opinion I'd go for something that everybody understands. And with eZ Publish I got the opposite feeling, I had to dig into long documents before I could understand the very basics. And in my perception this is wrong for something that is called eZ!

    And ok, you can say enterprise this, and enterprise that. It's an enterprise solution bla bla. That's no reason for making things complex!

    Well, I cannot speak for everyone ofcourse, but eZ Publish is certainly not easy for me.

    EZ? NO! www.ez.no
    • Re: complexPublish

      We've taken to calling it ezNO! for the very reasons you describe. Poor documentation, convoluted ini configurations, odd templating language decisions...
  • Sort by multiple attributes

    Hi

    I have a fetch that is calling two different classes.
    {def $reviews = fetch( content, tree, hash( parent_node_id, $node.node_id,
    class_filter_type, 'include',
    class_filter_array, array(43,175),
    sort_by, array( 'attribute', false(),345)
    ))
    $year=''
    $month=''
    }


    175 is a newly added class ID. So obviously this fetch fails because the sort_by attribute has a different ID number (1677) in that class.

    How can I make this fetch work so that the returned objects are sorted correctly by this attribute (it is a date field, but independent from ez publish's published date). I tried using the identifier name, because it is the same for both, but that doesn't work.