Re: DB_DataObject and Structures_DataGrid integration

From: Date: Thu, 12 Aug 2004 19:06:54 +0000
Subject: Re: DB_DataObject and Structures_DataGrid integration
References: 1 2 3  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-32597@lists.php.net to get a copy of this message
On Thursday 12 August 2004 09:03 am, Andrew Nagy wrote: > Jackson Miller wrote: > > I completely agree. Now is a good time to mention that we (myself and > > Marcus Whitney) have also integrated DB_QueryTool with SDG to allow > > complex searching on SDG data. We have incorporated paging, sorting, > > limiting, and conditional getting (where) of SDG data. It is also really > > easy to create a multi-dimensional array from the result set and use > > $dg-bind to set all of the records in one-fell-swoop. I understand the > > need/desire to use bind in other ways, but this one works really well > > already. so... > > Cool, do you have an example we can look at? Can you explain it more? As I mentioned yesterday, my work with DataGrid has been when creating CEP modules/components (http://sf.net/projects/cep). I will try to adapt a simple example from some of that work. If you want a more detailed explaination or want to see it in action just email me off-list (or join the cep-developers list). My example was stripped down from other code. I crafted it in the email client, so there could be a typo or two. I am leaving out the DataGrid creation code since everyone following this thread probably has that part down. Here is the basic run down: // params $records_per_page = '25'; $available_fields; // would be holding an array of db field names $dg; // the DataGrid object reference. // instantiate a library that uses QueryTool $dbqt = new Example_QueryTool_Library(); // build the search params $search_params = null; // handle ordering if (isset($_GET['orderBy'])) { $search_params['order']['condition'] = $_GET['orderBy']; if (isset($_GET['direction'])) { $search_params['order']['direction'] = $_GET['direction']; } } // allow search strings to be in GET, POST, COOKIE, etc if (isset($_REQUEST['search']) && '' != $_REQUEST['search']) { // allow searching on a specific field if (isset($_REQUEST['search_field']) && '*' != $_REQUEST['search_field']) { $search_params['where'] = "{$_REQUEST['search_field']} LIKE '%{$_REQUEST['search']}%'"; } // when not searching on a specific field, search all fields else { foreach ($available_fields as $field) { $where[] = "{$field} LIKE '%{$_REQUEST['search']}%'"; } $search_params['where'] = implode($where,' OR '); } } // paging $search_params['limit'] = $records_per_page; $search_params['start'] = '0'; if (isset($_GET['page']) && 1 < $_GET['page']) { $search_params['start'] = (($_GET['page'] - 1) * $records_per_page) - 1; } // set the QueryTool params (where clause) $dbqt->setSearch($search_params); // get the total number of records $num_records = $dbqt->searchCount(); // bind the displayed records to the DataGrid $dg->bind( $dbqt->getAll($search_params['start'],$search_params['limit'])); // paging has to be done using PEAR::Pager directly $options = array('mode'=>'Sliding', 'separator'=>' | ', 'prev'=>'<<', 'next'=>'>>', 'delta'=>'5', 'totalItems'=>$num_results, 'perPage'=>$records_per_page, 'urlVar'=>'page'); $pager =& Pager::factory($options); // display the DataGrid and Pager $dg->render(); $pager->render();

« previous php.pear.dev (#32597) next »