generic csv import for tables relationships to other tables

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

generic csv import for tables relationships to other tables

Postby rscales » Tue Mar 09, 2010 3:13 am

Hi,

I'd like to know if there is an easy way for me to develop a generic csv import function that would be able to reference the same relationships I've defined for new records in Xataface with valuelists feeding the fields.ini file.

For example, imagine the following 2 tables:
Code: Select all
Table category
id    category_type
1         black
2         red
3         yellow

Table jelly_bean
id      name     category
1       lemon         3
2      cherry         2
3     strawberry      2


Now imagine I have a csv file:
Code: Select all
Tablename,jelly_bean
liquorice,black
raspberry,red


I'd like to know how I could know from a generic import_csv file (stored in each table delegate class) what the relationships defined in valuelists.ini and fields.ini are such that I could:

1) check for validity of the input (i.e. does black exist in the category table or not)
2) input the correct value for the table (i.e. input "1" into the third column, rather than "black").

For now, I don't have a problem copying this generic import_csv to all table delegate classes, but it would also be nice if I could somehow centralize this script and call from each table delegate class (I'm a php novice).

Thanks,
Rich
rscales
 
Posts: 18
Joined: Mon Sep 14, 2009 1:10 am
Location: FR

Re: generic csv import for tables relationships to other tables

Postby rscales » Wed Mar 10, 2010 10:35 am

Hi,

I have since made some progress. I now am able to find the fields of a table, if the widget type is text or select, and the valuelist name if they are select.

Now, I need to know how I can use the valuelist name to give me an array of possible possible entries for that column from within my import__csv php function.

Code: Select all
      $table =& Dataface_Table::loadTable('jelly_bean'');
      $fields =& $table->fields();
      foreach (array_keys($fields) as $fieldname){
         echo $fieldname." ".$fields[$fieldname]['visibility']['list']." ".$fields[$fieldname]['widget']['type']." ".$fields[$fieldname]['vocabulary']." ";
         }
      $valuelists =& $table->valuelists();
      foreach (array_keys($valuelists) as $valuelistname){
         echo $valuelistname."-";
         }


Again, I need to know which fields are actually relationships with other tables, and what those relationships are so I can correctly import the category id, rather than the category type name in my example from the first post.

Regards,
Rich
rscales
 
Posts: 18
Joined: Mon Sep 14, 2009 1:10 am
Location: FR

Re: generic csv import for tables relationships to other tables

Postby rscales » Fri Mar 12, 2010 3:18 am

Hi,

I have since made some more progress but am missing one final piece of information.

How can I retrieve the sql query defined in valuelists.ini? I can retrieve the name of the valuelist for all fields in a table that are of type select, but I can't seem to find if/where the string is stored in dataface. Alternatively, I don't necessarily need to do the query if the results of the valuelist query are stored somewhere. Also, if the results are stored, how can I get a list of them?

-Rich
rscales
 
Posts: 18
Joined: Mon Sep 14, 2009 1:10 am
Location: FR

Re: generic csv import for tables relationships to other tables

Postby rscales » Fri Mar 12, 2010 3:44 am

Hi,

Never mind on this.

$table->valuelists();

and array_keys / array_values in php did the trick.

-Rich
rscales
 
Posts: 18
Joined: Mon Sep 14, 2009 1:10 am
Location: FR


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 2 guests

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