Path

ez projects / enhanced_objectrelation


Enhanced ObjectRelation

UNIX name Owner Status Version Compatible with
enhanced_objectrelation Xavier Dutoit planning 1.1 3.4->3.7.x (latest from svn)

That's a mix between the default object relation (single relation, ala
radio button) and the object relation list datatypes (multiple
relations, ala check boxes). It provides the same functionalities,
but store the relation into the object relation table instead of into
the object as an xml node and support and a more intuitive interface
to select the related objects (4 options to let your editor choose
the related objects).


/*
Enhanced Object Relation extension for eZ publish 3.x
Copyright (C) 2004-2005 Sydesy ltd
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
Context
--------
We needed to build a 'survey like' object (with several questions
either "check boxes" or "radio buttons"). Each
answer of each question has to be an independant object (as it contains a
lot of extra informations beside its name).
We needed to be able to retrieve all the objects linked to a specific
answer (an independant object).
The existing objectrelation datatype has several limitations:
- that's always a single relation (no multiple selections)
- the layout is not what we wanted (list with check boxes and list
with radio buttons)
- you can't easily retrieve all the objects that are related to a
specific object (reverse related)
2. Features
-----------
We have created an enhancedobjectrelation :
- that stores the object relations as it is implemented on ez,
therefore keeping all the nice features ez provides
(eg list all the object related to aka reverse related),
- that is able to handle a one to one or one to many
relationship,
- that let you define the target objects list based on their parent
node.
- that provide two new interfaces two manage the relation: a list with
radio button (single selection)
and a list with check boxes (multiple selection)
- that allows you (based on the option you choose when you edit the
class) to select one or multiple related objects.
- You can search the related objects (thx Gabriel Ambuhel),
- You can choose the related objects based on their class,
- You can choose the related objects based on their parent node,
- You can choose the related objects based on their parent node and
their class (thx rudy demo)
If you need to store relations between objects and have a nicer
interface than the 'browse' default solution,
this datatype might do it.
3. Example of use
-----------------
You want to create a directory of companies, with one of its attribute
being the country it belongs to.
You create a company class and a country class.
To store the country, Instead of using the ezcountry datatype, you can
simply create a country node (a folder),
with its children being the countries (a new country class).
On the country class, You can have as many information as you want (its
flag, a map, a description...) and you can
list all the companies that belong to this country (reverse
related).
On the company class, you add an enhancedobjectrelation, with "default
selection node"=the country node (the folder).
If a company can only belong to one country, choose "Selection
method"="Dropdown list" or "list with radio button".
If a company can belong to several contries, choose "Selection
method"="list with check box".
That's it. To alter the county list, simply create or delete objects under
the country node.
4. Implementation and interraction with ez kernel
-------------------------------------------------
For ez > 3.6, you don't have anything to do.
For the ez 3.5, you need to modify the structure of one table (from the
sql client type
"alter table ezcontentobject_link add contentclassattribute_id int(11) NULL
default null;"
I have modified the existing table ezcontentobject_link to add a new
column contentclassattribute_id in order
to be able to know if a relation between two objects is created by the
standard relation system or by this datatype
and to be able to distinguish if you put two enhancedobjectrelation
attributes into the same class.
This allows us to benefit directy of several interresting standard
features (the most obvious is the reverse relation
list and be sure that all the relations are deleted when you delete the
object).
However, without hacking the kernel, all the objects selected via a
enhancedobjectrelation attributes are displayed
on the related attributes. In our case, that's a feature but you might
have to modify ezcontentobject.php
to change the default behavior.
5. Known bugs and limitations
-----------------------------
The select query is called more than once when editing an object. I've
an explaination from ez (dynamic attributes, but need to modify the
code to go around that).
You can't define if you want to select the element directly under the
current node (list) or down several levels (tree). Now that's based
on the type (if you select a parent node, that's list, if you select
a class, that's a tree).
6. TO DO and possible evolutions
--------------------------------
Well, it does what we need so far, but if you have a nice idea we might
implement it... and be more than happy to
add your patches ;).
Do the pdf and info templates (I don't know how to test them). Do the
info collector.
On the long run, I'd like to have this attribute as the default
objectrelation one shipped with ez, as I think
that's a better implementation that the existing one and it offers more
features.
7. Disclaimer & Copyright
-------------------------
Enhanced Object Relation for eZ publish 3.x
Copyright (C) 2004-2005 Sydesy ltd
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This extension has been created using Enhanced Selection has a template
and inspiration.
The operator is tailored to fit our needs, and is shared with the
community as is.
8. A last trick
----------------
On 3.6, you have two operators allowing to fetch the reverse related
objects and related objects (with the attributeid of the enhanced
object relation).
On 3.5
A template example to retrieve all the objects reverse related to an
object (having a relation to it). Couldn't find
this on the doc and had to dig the code to find it.
{* Reverse relation *}
{let
reverse_related=$node.object.current.reverse_related_object_list}

  • {$ReverseObject:item.name}

Screenshot

This project has no reviews yet. Be the first one to review it!

No forum messages yet.