Radicore Forum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » RADICORE » How To » [tip] Changing scrolling order outer/middle table
[tip] Changing scrolling order outer/middle table [message #423] Mon, 27 November 2006 09:46 Go to next message
johandewit is currently offline  johandewit
Messages: 25
Registered: May 2006
Location: Belgium
Junior Member
Hi all,

In my specific case, in the list3 pattern, the middle table contains a list of weeknumbers, which are found in the database.

The first entry should be the latest weeknumber found in the database. This could be done using the $this->sql_orderby property, but this resulted in a a scrolling that is not so natural, because to go to a previous week, one needs to press on the next link.

So i needed to be able to display the last available week first when entering the list task.

Here is the code to achieve this.

I'm using the std.list3.inc pattern (but it should work in all similar patterns)

In the middle.table.class.inc :

function _cm_pre_getData($where, $where_array)
    {

        if ( $GLOBALS['task_id'] == "ts_in_input(list3)" )
        {
            if ( isset($_POST['reset'])  || ( ( $this->getPageNo() == 1 ) && ( ! isset($_GET['item']) ) ) )
            {

               // use a different object of $this, to avoid
               // temptering with the properties.

               // in this specifi case I retrieve all
               // weeknumbers from the database, which are passed
               // via the $whee function

                require_once 'input.class.inc';
                $test_object =& Singleton::getInstance('input');
                $test_object->sql_select = 'input_week';
                $test_object->sql_groupby = 'input_week';
                $test_object->sql_orderby = 'input_week';

                $rows= $test_object->getData_raw($where);
                $current_week = date('W');
                // Look for the weeknumber closest to the 
                // current week to be the default

                foreach ($rows as $index =>$val_array)
                {
                    if ($val_array['input_week'] >= $current_week)
                    {
                        break;
                    }
                }
                $this->setpageNo($index+1);
            }
        }
        return $where;
    }



I hope it is clear and it is useful for someone. I've attached a screendump where you can see the first screen displays the last week found in the middle table.

Greetings

Johan

Re: [tip] Changing scrolling order outer/middle table [message #424 is a reply to message #423] Mon, 27 November 2006 19:14 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2368
Registered: April 2006
Location: Surrey, UK
Senior Member
That's nice, but there is an easier method. All scrolling areas, just like pagination areas, are constructed using $this->pageno and $this->rows_per_page, which are used to calculate the OFFSET and LIMIT clauses of the sql SELECT statement.

In multi-line pagination areas $this->rows_per_page is either 10, 25,50 or 100, but in single item scrolling areas $this->rows_per_page is always set to 1.

The reason that each scrolling and pagination area always starts at page 1 is because this is the default value for $this->pageno. When you actually click on one of the scrolling/pagination links it sets the value of $this->pageno to something else.

So, if you want a scrolling or pagination area in a LIST3 screen to start at a value which is not 1 then all you have to do is set $this->pageno to the desired value in the _cm_initialise() method of the relevant class.

I hope you find this tip useful.


Re: [tip] Changing scrolling order outer/middle table [message #425 is a reply to message #424] Tue, 28 November 2006 04:17 Go to previous messageGo to next message
johandewit is currently offline  johandewit
Messages: 25
Registered: May 2006
Location: Belgium
Junior Member
Initially, I used the cm_initialise() function to change the order, but when someone presses the reset button, this function is not executed. And since the pageno must be set before the $this->getData() function, it seems obvious to use the $this->cm_pre_getData() function.

Looking into the std.list3.inc code, the $this->initialise() function ids only called when a new object is created, and not when when the object is 'unserialized'.

I also need to change the $where. Using _cm_initialise() the $where changes are lost.

From std.list3.inc line 106
   $null = $dbmiddle->initialise($where);   


In my case there is no $selection, because the grandparent is 'computed' (taken form the $_SESSION['logon_user_name']).

I will test the _cm_initialise() method also in less complicated situation where no manipulation of the $selection and/or $where variables are needed. In those case i think it will work, except for the 'reset' action.

Anyway, I love using radicore.

johan



Re: [tip] Changing scrolling order outer/middle table [message #426 is a reply to message #425] Tue, 28 November 2006 06:29 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2368
Registered: April 2006
Location: Surrey, UK
Senior Member
How important is it that the RESET button sets the pointer to an entry other than the first entry?

The problem with putting code in the _cm_pre_getData() function is that this function is called just before every database read and not just once a the start of the transaction. This code would therefore have to differentiate between the first read and other reads, and also identify when the RESET button had been pressed, which could mean some complicated code.


Re: [tip] Changing scrolling order outer/middle table [message #427 is a reply to message #426] Tue, 28 November 2006 08:39 Go to previous messageGo to next message
johandewit is currently offline  johandewit
Messages: 25
Registered: May 2006
Location: Belgium
Junior Member
If the pointer was set to the last entry, the RESET button should set the pointer also to the last entry, not to the first. Thats what my users expects from a RESET.


Keeping the representation of the scrolling 'natural' in the human way of thinking does make the code more complicated, and following if-clause seems to handle everything well.

if ( isset($_POST['reset'])  || ( ( $this->getPageNo() == 1 ) && ( ! isset($_GET['item']) ) ) )
{
  // code that changes the order comes here
  $this->pageno = $this->lastpage;   // eg start at the last element  
}






Re: [tip] Changing scrolling order outer/middle table [message #428 is a reply to message #427] Tue, 28 November 2006 09:14 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2368
Registered: April 2006
Location: Surrey, UK
Senior Member
That code infers that it always starts at the last entry, but that is too inflexible. What happens if you want to start at at entry which is neither the first nor the last? In your previous example you had 52 entries, one for each week in the current year, and you wanted the transaction to start at the week number which represents the current week.

If you have code in _cm_initialise() which sets the initial value for $this->pageno then I have managed to get a RESET to restart at the same value by making a small change to std.list3.inc from
if (isset($_POST['reset'])) {
    // initialise all settings to start afresh
    $dbouter->setSqlSearch(null);
    $dbouter->setPageNo(1);
    $dbmiddle->setPageNo(1);
} // if
to
if (isset($_POST['reset'])) {
    // initialise all settings to start afresh
    $dbouter->setSqlSearch(null);
    $where = $dbouter->initialise($where);
    $null = $dbmiddle->initialise($where);
} // if

I think this method will give more flexibility.


Re: [tip] Changing scrolling order outer/middle table [message #429 is a reply to message #428] Tue, 28 November 2006 09:44 Go to previous message
johandewit is currently offline  johandewit
Messages: 25
Registered: May 2006
Location: Belgium
Junior Member
Seems great, I will try your code and tell you the result.




Previous Topic: New Application
Next Topic: Concurrency / freshness of data objects
Goto Forum:
  


Current Time: Sat Nov 23 13:32:41 EST 2024

Total time taken to generate the page: 0.01230 seconds