List View Filtering/ Multiple fields.ini Files?

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

Postby moj0rising » Thu Feb 01, 2007 4:23 pm

OK. Now I'm told my application has to be able to show different fields depending on certain criteria.

I want to do this my having 2 - 4 different buttons on the bottom of the page. As an example, when a user clicks on button 1, the list view comes up showing fields A, B, and C (and all other fields are not visible in list view). When the user clicks on button 2, the list view instead shows only fields D, E, and F.

This seems like it could be done by using multiple fields.ini files but I don't know and I don't know how that would be done if it is possible.

Can someone tell me what the best (hopefully an easy) way to do this is?

Thanks,
Mike
moj0rising
 
Posts: 26
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Thu Feb 01, 2007 4:35 pm

OK.. this is possible.Ê All of the information from the fields.ini file is loaded into an associative array at run-time.Ê You can modify this information using PHP to suite your needs.


You just need to:
  1. be able to track which button was pressed (easy using GET variables)
  2. load the Dataface_Table object for the table in question some time before the list is displayed (e.g. in the index.php file after df_init() but before $app->display()).
  3. Set the visbility:list attribute to 'hidden' (or 'visible') on the fields that you want to change.
e.g.
if ( *button 1 was pressed*){
ÊÊÊ $table =& Dataface_Table::loadTable('mytable');
ÊÊÊ $fields =& $table->fields();
ÊÊÊ foreach (array_keys($fields) as $fieldname){
ÊÊÊÊÊÊÊ if ( in_array($fieldname, array('A','B','C') ){
Ê Ê Ê ÊÊÊÊÊÊ $fields[$fieldname]['visibility']['list'] = 'visible';
Ê ÊÊÊÊÊ } else {
Ê Ê Ê ÊÊÊÊÊÊ $fields[$fieldname]['visibility']['list'] = 'hidden'; Ê
ÊÊÊ }
} else if (*button 2 was pressed*){
ÊÊÊ //.. same thing, but changing the visiblity of different fields according to what you want.
}


--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby moj0rising » Thu Feb 01, 2007 4:57 pm

As I'm sure you have noticed by now, I'm pretty new to PHP.

How can I track which button was pressed w/ GET variables? In other words, what goes in-between the *'s in the line, if ( *button 1 was pressed*){ ?

Mike
moj0rising
 
Posts: 26
Joined: Wed Dec 31, 1969 5:00 pm

Postby roginald » Thu Feb 01, 2007 7:32 pm

hello,

in order to utilize the 'GET' superglobal array, simply append key/value pairs to the url associated with each of your buttons, for example:

http://www.dfapp.com/index.php?-choice=button1 for button 1
http://www.dfapp.com/index.php?-choice=button2 for button 2

I used a '-' before the variable name to keep in line with Steve's set-up. Then in your conditional statement, you can access the value of 'choice' in a number of ways. Example: $mychoice = $_GET['choice'] will assign the value to the local variable '$mychoice', which you can then use to test in the if/else statements. The key here is to note that all values that are passed via the url string are available inside the $_GET[] array.

if( $mychoice == 'button1' ) {

//do stuff

} else if ( $mychoice == 'button2') {


//do other stuff

}
roginald
 
Posts: 24
Joined: Wed Dec 31, 1969 5:00 pm

Postby roginald » Thu Feb 01, 2007 7:58 pm

quick fix, it should be: $mychoice = $_GET['-choice']

sorry about that...

hello,

>

in order to utilize the 'GET' superglobal array, simply append key/value pairs to the url associated with each of your buttons, for example:

>

http://www.dfapp.com/index.php?-choice=button1 for button 1

> http://www.dfapp.com/index.php?-choice=button2 for button 2

>

I used a '-' before the variable name to keep in line with Steve's set-up. Then in your conditional statement, you can access the value of 'choice' in a number of ways. Example: $mychoice = $_GET['choice'] will assign the value to the local variable '$mychoice', which you can then use to test in the if/else statements. The key here is to note that all values that are passed via the url string are available inside the $_GET[] array.

>

if( $mychoice == 'button1' ) {

>

//do stuff

>

} else if ( $mychoice == 'button2') {

>



> /do other stuff

>

}

>

roginald
 
Posts: 24
Joined: Wed Dec 31, 1969 5:00 pm

Postby generatedname » Fri Feb 02, 2007 1:57 am

$table =& Dataface_Table::loadTable('certifications');





thats the line that is giving this error:

Fatal error: Undefined class name 'dataface_table' in ........index.php on line 28
generatedname
 
Posts: 53
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Fri Feb 02, 2007 2:06 am

You may have to import the class first:
import('Dataface/Table.php');
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby generatedname » Fri Feb 02, 2007 10:14 am

Thanks a ton, that helped a great deal, got that working and just realized I need to further my sql query based on which button is pressed. Is there an easy way to do this?

Right now I have my form that has 2 drop down's and 2 submit buttons (type="submit" name="button") for both. in the index.php I use the GET to see which value of "button" was sent, and based on that I modify the fields to be hidden/shown. Is there a way, now, to sort of add to the form. I need one button to filter the search to show only one type of media 'MediaType' in the table, and the other button to show all other types of media,but both searching based on the 2 drop down's.

Thanks in advance!

-Kurtis
generatedname
 
Posts: 53
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Fri Feb 02, 2007 10:34 am

I would do it with 2 separate forms.Ê Place hidden fields in each form to specify your search parameters with consideration for the dataface url conventions.Ê This will allow you complete flexibility as to what query parameters are sent with each button.


One helpful tip:

The Dataface_Application class has a method url() that will produce a url with all of the current query parameters intact, plus any changes you make.

e.g.

$app->url('');

Will return a full url to the current page.

$app->url('-action=foo');

will return a url with all of the query parameters intact except it will change the -action parameter to foo.

$app->url('-action=foo&-table=bar');

... you can guess what this will return.

Note that this method will skip parameters beginning with '--'.

Why is this helpful?Ê Because you may want your form to simply maintain the current user settings and query parameters aside from the specific query terms that your form introduces.Ê In this case, your form's action parameter may be:

$app->url('');

Just a small tip that you may or may not choose to use.


-Steve

--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby generatedname » Fri Feb 02, 2007 12:19 pm

Thanks for the help, the last bit confused me a little because I could not figure out becaues I couldn't relate it to my situation. However, I came up with a solution that turned out to be something we needed anyways. I added a field to the table for Media Category and added it to the form a third dropdown, so now that filters the search for me and allows more options in the future without cluttering up with several submit buttons.

Thanks again for the help!
generatedname
 
Posts: 53
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 26 guests

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