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  |
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   |
AJM
Messages: 2382 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   |
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
|
|
|
|
|
|
|
Goto Forum:
Current Time: Fri Jul 04 08:33:12 EDT 2025
Total time taken to generate the page: 0.01296 seconds
|