select field for object relation

Author Message

Kai Duebbert

Monday 04 August 2003 12:35:48 am

Hi,

I have the following situation:
1. A class with several object relation fields
2. Objects for these fields can only be selected from a specified directory.
3. Instead of doing the complicated way which the admin area uses, I want to use a select field.

Building the page with the right select values etc. all went fine. But what values do I have to give the select structure so that the objects get saved?

Other than the variables for the select field, the following code (seems to) work(s):

{section name=top loop=fetch( content, list, hash( parent_node_id, 104, class_filter_type, include, class_filter_array, array( 1 ) ) )}

{section show=eq($:item.name,$attribute.contentclass_attribute_identifier)}
<select name="ContentObjectAttribute_data_object_relation_id_{$:item.node_id}">
{section name=Child loop=fetch(content, list, hash( parent_node_id, $top:item.node_id ))}
<option value="{$:item.node_id}">{$:item.name|wash} ({$:item.node_id})</option>
{/section}
</select>
{/section}
{/section}

Anyone got any ideas? Going with the "Find object" button is very user unfriendly. I want them to be able to just select the fields. Help!

Thanks,
Kai

Bruce Morrison

Tuesday 05 August 2003 7:08:39 pm

Hi Kai

I've also come across this issue and looked into it in some depth.
http://ez.no/developer/ez_publish_3/forum/developer/related_objects_choosing_from_a_dropdown_instead_of_using_browse

Unfortunately it does not seem possible to achieve this with templates alone. After the related object is select from the browse window entries are made in the database to link to related object. Because of this functionality it is not possible to do this in the object edit screen.

I have been considering how to handle this. I think there are a couple of options.

1. Create a new data type "Relational Object - Select". This would allow you to nominate a node (and possibly a class id) from which the dropdown is populated. When the object is published the correct entries are created in the database.

2. Use the keywords feature to link items. Haven't looked at these yet but it may be a solution without having to code a new extension.

Cheers
Bruce
designIT

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

Kai Duebbert

Friday 22 August 2003 3:02:27 am

Ok, found the solution. It's really simple after all and I wonder, why I didn't get it to work before. (Tried it on 3.2b1 but it also should work on 3.1)

All you have to do is change the "edit" template for the Object Relation datatype:

1. copy design/standard/templates/content/datatype/edit/ezobjectrelation.tpl to your custom design folder. Or start with an empty one.
2. The crucial line for assigning an object relation is:
<input type="hidden" name="ContentObjectAttribute_data_object_relation_id_{$attribute.data_int}" value="[CONTENTOBJECT_ID]" />

Change the "[CONTENTOBJECT_ID]" to the id of an object you want to link. E.g. I use a dropdown select box and it works like a charm.

I found it difficult to understand how the object relation actually works at first. As soon as you create a new object with object relation fields, it creates new database entries for them (have a look at contentobject_attributes and compare to the source code of the generated webpages). This is why it was hard to understand (for me).

If there is demand, then I will write a small howto in the documentation area.

Have fun,
Kai

ruud prein

Thursday 29 January 2004 2:52:45 pm

If you can find some time to write a doc about this I would be very gratefull.

regards,

Ruud

---
groet,

Ruud

Trond Åge Kvalø

Monday 23 February 2004 7:09:19 am

Hello Kai!

We're building an LMS based on eZpublish and would very much like to create relations between users and courses. In our implementation an admin user can create users and courses. Then we would like the admin user to create a "course license" with the userid and the courseid. From the little I've seen about object relations so far, I beleive that is the best option here.

Could you please provide us with an example on how to accomplish this?

Best regards
Trond Kvalo
Atlantia as
http://www.atlantia.no/

trondåge

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