Subversion Repositories sortobjectsoperators

[/] [README] - Blame information for rev 1

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1 akozeka
Content objects/nodes sorting template operators extension for eZ Publish
2
=========================================================================
3
Author: Alex Kozeka <kozeka.alex@gmail.com>
4
Date: July 2011
5
 
6
 
7
An extension aiming to perform server-side content objects/nodes sorting.
8
May be helpful when it is required to do fine-tuning after fetch operator which could not do the job.
9
Various sorting coditions can be applied.
10
 
11
 
12
License
13
=======
14
GNU General Public License v2.0
15
 
16
 
17
Requirements
18
============
19
- eZ Publish 4.0+ (tested with 4.3).
20
 
21
Installation
22
============
23
1) Copy sortobjectsoperators directory to eZ Publish extension directory.
24
 
25
2) Generate autoloads using commands:
26
cd ezp_dir
27
php bin/php/ezpgenerateautoloads.php
28
 
29
3) Activate extension in your site.ini.append.php
30
 
31
 
32
Description and usage
33
=====================
34
Extension adds template operators:
35
 
36
1) get_sorted_objects( $unsorted_nodes_or_objects, $sort_conditions )
37
 
38
Sorts nodes/objects using specified sort_conditions and returns sorted objects.
39
$unsorted_nodes_or_objects: An array returned from fetch or like that. Elements are content objects or nodes.
40
$sort_conditions: An array of sort conditions.
41
Each element is SORT_ORDER specificator + at least one SORT_SOURCE specificator.
42
See examples for common usage scenarios.
43
 
44
$sort_conditions = array(
45
    array(
46
        SORT_ORDER: {true(): ASC | false(): DESC},
47
        SORT_SOURCE: {
48
            'parent': object's parent node |
49
            array( 'attribute': object's attribute, 'ATTRIBUTE_IDENTIFIER': attribute name ) |
50
            array( 'system_attribute': object's system attribute, 'ATTRIBUTE_IDENTIFIER': attribute name ) |
51
            array( 'relation_attribute': object's relation attribute, 'ATTRIBUTE_IDENTIFIER': attribute name )
52
        }
53
    ),
54
    ...
55
)
56
 
57
2) get_unique_sorted_objects( $unsorted_nodes_or_objects, $sort_conditions )
58
 
59
Sorts nodes/objects using specified sort_conditions and returns only unique (by object id) sorted objects.
60
Parameters are the same as for get_sorted_objects operator.
61
 
62
3) get_objects_from_nodes( $nodes_or_objects )
63
 
64
Returns objects from mixed list of nodes/objects
65
 
66
 
67
Examples
68
========
69
 
70
Assume content classes (significant fields only):
71
 
72
Folder
73
- name [text line]
74
- location [object relation, allowed classes: Location]
75
 
76
Article
77
- title [text line]
78
- locations [object relations, allowed classes: Location]
79
 
80
Location
81
- title [text line]
82
 
83
Content tree structure:
84
- Articles are grouped by Folders.
85
- Folders are under one parent Folder.
86
- Each article can have 0/many related Locations.
87
- Each Folder can have 0 or 1 related Location.
88
 
89
Template code:
90
 
91
1) Sort node list by object's attribute title ASC
92
 
93
{def $unsorted_nodes = fetch( 'content', 'list', hash(
94
    'parent_node_id', PARENT_FOLDER_NODE_ID,
95
    'class_filter_type', 'include',
96
    'class_filter_array', array( 'article' )
97
))}
98
{def $sorted_objects = get_sorted_objects( $unsorted_nodes, array(
99
    array(
100
        true(),
101
        array( 'attribute', 'title' )
102
    )
103
))}
104
 
105
 
106
2) Sort node list by parent object's name ASC + object's publish date DESC
107
 
108
{def $unsorted_nodes = fetch( 'content', 'list', hash(
109
    'parent_node_id', PARENT_FOLDER_FOR_FOLDERS_NODE_ID,
110
    'class_filter_type', 'include',
111
    'class_filter_array', array( 'article' ),
112
    'depth', 2
113
))}
114
{def $sorted_objects = get_sorted_objects( $unsorted_nodes, array(
115
    array(
116
        true(),
117
        'parent',
118
        array( 'system_attribute', 'name' )
119
    ),
120
    array(
121
        false(),
122
        array( 'system_attribute', 'published' )
123
    )
124
))}
125
 
126
 
127
3) Sort node list by object's related object title ASC + object's name ASC
128
 
129
{def $unsorted_nodes = fetch( 'content', 'list', hash(
130
    'parent_node_id', PARENT_FOLDER_FOR_FOLDERS_NODE_ID,
131
    'class_filter_type', 'include',
132
    'class_filter_array', array( 'article' ),
133
    'depth', 2
134
))}
135
{def $sorted_objects = get_sorted_objects( $unsorted_nodes, array(
136
    array(
137
        true(),
138
        array( 'relation_attribute', 'locations' ),
139
        array( 'attribute', 'title' )
140
    ),
141
    array(
142
        true(),
143
        array( 'system_attribute', 'name' )
144
    )
145
))}
146
 
147
 
148
4) Sort node list by parent object's related object's title ASC + parent object's name ASC + object's name ASC
149
 
150
{def $unsorted_nodes = fetch( 'content', 'list', hash(
151
    'parent_node_id', PARENT_FOLDER_FOR_FOLDERS_NODE_ID,
152
    'class_filter_type', 'include',
153
    'class_filter_array', array( 'article' ),
154
    'depth', 2
155
))}
156
{def $sorted_objects = get_sorted_objects( $unsorted_nodes, array(
157
    array(
158
        true(),
159
        'parent',
160
        array( 'relation_attribute', 'location' ),
161
        array( 'attribute', 'title' )
162
    ),
163
    array(
164
        true(),
165
        'parent',
166
        array( 'system_attribute', 'name' )
167
    ),
168
    array(
169
        true(),
170
        array( 'system_attribute', 'name' )
171
    )
172
))}
173
 
174
 
175
Known issues
176
============
177
- Attributes and system attributes should exist. No checks performed about that.
178
- Sorting is performed correctly for textual attributes only.