Default Sort Order Bug

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

Default Sort Order Bug

Postby mikep » Mon Jan 11, 2010 5:18 pm

Hi,
So this is a bit of a strange bug and I was wondering if anyone had sorted it out.

I have xataface set up with login authentication. Upon logging in, xataface automatically routs the user to the list view of the table 'Client'. The client table is set to sort the Client ID descending using the following statement in the index.php file

if ( !isset($_REQUEST['-sort']) and @$_REQUEST['-table'] == 'Client' ){
$_REQUEST['-sort'] = $_GET['-sort'] = 'Client_ID desc';
}

The links are sorted correctly, but the information is incorrect. For example, if client number 1 is named John Doe, and client number 10 is named Jane Doe, the list view will display the following way

1 John Doe
...
...
...
10 Jane Doe

However, upon clicking 1 for John Doe the user is brought to Jane Doe's record and vice versa. Hense, the links are sorted in the correct order but the data is not sorted.

Now, this problem only occurs when authentication is enabled. Additionally, if I click the Client tab to bring me to the client table, the list view is then sorted correctly.

Any help is appreciated,
Mike
mikep
 
Posts: 44
Joined: Fri Apr 24, 2009 2:21 pm

Re: Default Sort Order Bug

Postby shannah » Mon Jan 11, 2010 5:39 pm

Strange.

What are the URLs (i'm interested particularly in the query strings) for the pages that work incorrectly and correctly. Let me recap and correct me if I'm wrong:

1. Upon logging in, the list view appears in the correct order, but the links are for the wrong rows.
2. Any other time it all works correctly.


One thing (that may not make a difference) that I like to do if I'm going to modify the GET or REQUEST parameters in the index.php file, is check for $_POST and only make the change if $_POST is empty - so I don't screw up any requests meant to alter data.
e.g.
Code: Select all
if ( !$_POST and !isset($_REQUEST['-sort']) and @$_REQUEST['-table'] == 'Client' ){
$_REQUEST['-sort'] = $_GET['-sort'] = 'Client_ID desc';
}
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Default Sort Order Bug

Postby mikep » Tue Jan 12, 2010 8:00 pm

ok, so for record 1, the URL is http://sc-database/Psychology/index.php ... -mode=list

The link for the client tab is http://sc-database/Psychology/index.php?-table=Client

There are no messages in the apache error log about it and checking for $_POST makes no difference.

Do you need any other information?

Mike
mikep
 
Posts: 44
Joined: Fri Apr 24, 2009 2:21 pm

Re: Default Sort Order Bug

Postby shannah » Tue Jan 12, 2010 8:22 pm

OK.. the sort is not getting retained in the link, which is quite strange. Can you post your entire index.php file? (that is where your custom sort rule is placed, right?).
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Default Sort Order Bug

Postby mikep » Thu Jan 14, 2010 1:07 pm

Here it is.

<?php
/**
* File: index.php
* Description:
* -------------
*
* This is an entry file for this Dataface Application. To use your application
* simply point your web browser to this file.
*/



if (!$_POST and !isset($_REQUEST['-sort']) and @$_REQUEST['-table'] == 'Client' ){
$_REQUEST['-sort'] = $_GET['-sort'] = 'Client_ID desc';
}

if ( !isset($_REQUEST['-sort']) and @$_REQUEST['-table'] == 'Status_Form' ){
$_REQUEST['-sort'] = $_GET['-sort'] = 'Client_ID desc, Date desc';
}

if ( !isset($_REQUEST['-sort']) and @$_REQUEST['-table'] == 'Progress_Notes' ){
$_REQUEST['-sort'] = $_GET['-sort'] = 'Client_ID desc, Date desc';
}



$time = microtime(true);
// use the timer to time how long it takes to generate a page
require_once '/srv/www/htdocs/Psychology/xataface/dataface-public-api.php';
// include the initialization file
df_init(__FILE__, 'http://sc-database/Psychology/xataface');
// initialize the site

$app =& Dataface_Application::getInstance();
// get an application instance and perform initialization
$app->display();
// display the application


$time = microtime(true) - $time;
echo "<p>Execution Time: $time</p>";
?>
mikep
 
Posts: 44
Joined: Fri Apr 24, 2009 2:21 pm

Re: Default Sort Order Bug

Postby shannah » Thu Jan 14, 2010 2:18 pm

This is very strange. There are a couple things to check out here.

1. Is Clients the first table listed in your conf.ini file? If so your special rule won't be picked up unless -table is explicitly specified in the URL (which may not be the case as Client would be the default loaded table).

2. Check the database table definition to make sure that your column names and table names are exactly as you have specified in your rules (INCLUDING TEXT CASE).

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

Re: Default Sort Order Bug

Postby mikep » Thu Jan 14, 2010 7:42 pm

The client table is the first one in the conf.ini file. Whichever table I move to be first exhibits the same problem. So how ca we explicitly specify -table in the URL?

The case and spelling are perfect.

Thanks,
Mike
mikep
 
Posts: 44
Joined: Fri Apr 24, 2009 2:21 pm

Re: Default Sort Order Bug

Postby shannah » Thu Jan 14, 2010 10:24 pm

OK.. no need to look into case and spelling... you have nailed it down by pointing out that it is the first table listed in the conf.ini file.
The method that you used works fine most of the time.... unfortunately it doesn't work when -table isn't explicitly specified in the URL.

The more stable way to achieve this is to define a beforeHandleRequest() method in the application delegate class and change it there.

E.g.
Code: Select all
function beforeHandleRequest(){
    $query =& Dataface_Application::getInstance()->getQuery();
    if ( !$_POST and $query['-table'] == 'foo' and !isset($query['-sort']) ){
        $query['-sort'] = 'foo_id desc';
    }
}
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 22 guests

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