how to have a preferred field with many to many rel

A place for users and developers of the Xataface to discuss and receive support.

how to have a preferred field with many to many rel

Postby fabiofromfrance » Sat Feb 20, 2010 11:11 am

Hi,
I have a many to many relationships + a one-to-many relationships between a personne and telephone table. Basically I want to show a personne with a preferred telephone and allow the personne to select from his list of telephones which one should be shown in the list view (as pref tel). so I have the following setup but doesn't work as expected.

tables setup:
personne=
id (primary)
fname
lname
tel_id

personneTelephone
pers_id (primary)
tel_id (primary)

telephone
id (primary)
number
type

in my tables/personne directory I have put relationships.ini file as follow and I do see the 'telephones' tab and the list of telephone associated to a given personne

relationships.ini=
[telephones]
__sql__ = "SELECT telephone.number,telephone.type
FROM personneTelephone pt
INNER JOIN telephone t
ON pt.tel_id = t.id
WHERE pt.pers_id = '$id'"

so in my personne table list I now see in the detail view a tab called 'telephones' where I can see all related telephone for that given personne.

Now how would you do to see in the edit tab for that given personne the list of telephone so you could allocated one telephone id as the preferred telephone for that given personne.

I am trying with valuelists.ini and fields.ini but I can't get it. I either have only an id telephone or a full list of telephone number stored in the DB ...

in my tables/personne directory I have put a valuelists.ini and fields.ini files with following setup but this where I don't have it working ... see below
valuelists.ini=
[telpref]
__sql__ = "select t.id,t.number
FROM telephone t
LEFT JOIN personneTelephone pt
ON pt.tel_id = t.id
WHERE pt.pers_id = '$id'"
fields.ini=
[id]
visibility:list = hidden
[lastname]
widget:label = "Nom "

[firstname]
widget:label = "Prénom "

[tel_id]
widget:label = "Téléphone préferré "
widget:type = select
vocabulary = telpref

Now the result is that I only got the id number of the telephone (not the number) and when editing the record the select field only shows the preferred id (not the list of telephone associated for this personne) and I have about 3 tel number in my db.

thanks for your help in advance.

Fabrice,
fabiofromfrance
 
Posts: 14
Joined: Mon Feb 15, 2010 3:03 pm

Re: how to have a preferred field with many to many rel

Postby shannah » Mon Feb 22, 2010 3:30 pm

Valuelists can't use variables in their sql definitions like you can with relationships. There are 4 possible strategies I can think of to achieve what you want:

1. Add a "preferred" checkbox to the join table for the telephone relationship which marks which number is preferred as part of the relationship.

2. Make the relationship orderable and use the grid widget to let the user edit the telephone numbers on the edit form of the personne table - then just assume that the first number is the preferred number.

3. Define the valuelist programmatically (in the delegate class).

4. Use your existing strategy, but instead of using a valuelist, use blocks and javascript to populate the select list manually.


-Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: how to have a preferred field with many to many rel

Postby fabiofromfrance » Tue Feb 23, 2010 2:41 am

Steve,
from your response and having look around various demo and post on the forum, I believe I am going to change my look and feel and do it programmatically.

I am going to keep my DB structure i.e not put an extra field in the join table.

I am looking at something similar to the web auction demo. I have been through the source but without doc it is not easy for me to understand all various pieces. would you mind to let me know the following so I can get started for my new look and feel?

1) how do you specify the default page to return i.e the public_product_list when a user only type the URL without index.php?-action= etc ..
I see the following code in tables/products/products.php but not sure how block__result_list() function get called.

Code: Select all
function block__view_tab_content(){
        $app =& Dataface_Application::getInstance();
        $record =& $app->getRecord();
        df_display(array('product'=>&$record), 'view_product.html');
    }
   
    function block__result_list(){
        if ( isAdmin() ) return PEAR::raiseError("Just show the default list");
        $app =& Dataface_Application::getInstance();
        $query =& $app->getQuery();
        $products = df_get_records_array('products', $query);
        df_display(array('products'=>&$products), 'public_product_list.html');
    }


2) in the public_product_list.html file I do recall the normal php foreach ... is it an Xataface convention from following code?
Code: Select all
{foreach from=$products item=product name=product}

or is there some additional function being used?

3) is it true that even you do have php file + delegateclass file Xataface will still use fields.ini, valuelists.ini, relationships.ini as long as they exists ?

Thanks in advance Steve.
fabiofromfrance
 
Posts: 14
Joined: Mon Feb 15, 2010 3:03 pm

Re: how to have a preferred field with many to many rel

Postby shannah » Tue Feb 23, 2010 10:22 am

By "new look and feel" what are you thinking? (I.e. how radical of a change are you planning to make). Most of webauction's custom looks are provided by implementing blocks and slots which override default content. For example the result_list slot which is overridden using the block__result_list() method of the delegate class overrides the result list portion of the list tab.

There should be a few tutorials in the wiki on blocks and slots and look & feel that can help to get you started. One tip, is that to see a readout of the available blocks and slots you can add
Code: Select all
debug=1

to the beginning of your conf.ini file and then reload your app.

-Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: how to have a preferred field with many to many rel

Postby fabiofromfrance » Tue Feb 23, 2010 10:58 am

Steve,
I am looking at completely changing the default look and feel to something similar to web auction and to the site called 'credit union database' (which is powered by xataface). I found the two really good and inline with my goal.

I am looking at having default list of all contact (like public_product_list) when a user hit the url page. So I am assuming that the block__result_list() is the one being return when going to the url without any action specified?

I also like the menu on the left side with options depending on your right and I did figure out how to work with it.

I do like the url format of the credit union database (http://www.credituniondb.com/browse/brandenburg_ky.html) where the url is more explicit than index.php?-action= etc... is there a tuto on how to change that to the one like credit union database?

Again thank you Steve for your response.

Fabrice,
PS:I did post a request on the Xataface News forum and I believe an intermediate presentation around the set up of the web auction side would be ideal for my case and may be other. It is a shame I missed your presentation done in November last year ...
fabiofromfrance
 
Posts: 14
Joined: Mon Feb 15, 2010 3:03 pm

Re: how to have a preferred field with many to many rel

Postby shannah » Tue Feb 23, 2010 11:11 am

Both credit union db and webauction actually make very few changes to the look and feel. They implement the result_list slot to override the default list view and they add or replace the content of the left column with their own content using the left_column, before_left_column, or after_left_column slots.

The clean urls in credit union DB would be done using apaches mod_rewrite in an .htaccess file. It is possible he also implemented the getPublicLink() method in the delegate class of records also to specify an alternate URL for a record.
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: how to have a preferred field with many to many rel

Postby fabiofromfrance » Wed Feb 24, 2010 9:52 am

Thank you Steve,
I have been looking on various part of your web site but didn't find much about getPublicLink() method. only a description inthe wiki reference page. Do you have an example that would explain it a bit more? thank you

Fabrice
fabiofromfrance
 
Posts: 14
Joined: Mon Feb 15, 2010 3:03 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 38 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved