Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 0.9.3

Bug #2125 GET parameters are intrusive and forbid using several DataGrids
Submitted: 2004-08-15 12:52 UTC
From: ylf at xung dot org Assigned: asnagy
Status: Closed Package: Structures_DataGrid
PHP Version: 4.3.4 OS: Linux Debian (testing)
Roadmaps: (Not assigned)    
Subscription  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 6 - 2 = ?

 
 [2004-08-15 12:52 UTC] ylf at xung dot org
Description: ------------ As it has been mentioned on the pear-dev mailing list, there's a need for namespacing the orderBy, direction and page GET parameters. About this issue, Jackson Miller stated : <jackson> I am not so sure this is a good thing. If SDG not only displays the UI but also processes incoming requests ($_GET['page'], $_GET['orderBy']) then we have to do something to make the SDG request vars not so global. Mybe something like this: $_GET['sdg[page]'] $_GET['sdg[orderBy]'] $_GET['sdg[direction]'] (order by and direction should probably be arrays themselves but...) </jackson> So, for sure, a prefix is needed. But there's another problem : if several grids are displayed on the same page, an arbitrary 'sdg' prefix will turn into a conflict. This means the prefix must be customizable. Side note : I don't think orderBy and direction should be arrays themselves. I don't see how the DataGrid would render that.

Comments

 [2004-10-02 15:31 UTC] joern_h at gmx dot net
Here is a patch for using multiple datagrids on one page. It adds methods for setting a "namespace" to Core.php which is then used by HTMLTable.php. I have also added code for indicating the current sort order with arrows in the table header. diff -r -d -U 4 c:\temp\Structures_DataGrid-0.5.3\DataGrid/Core.php structures\datagrid/Core.php --- c:\temp\Structures_DataGrid-0.5.3\DataGrid/Core.php Tue Aug 10 13:17:32 2004 +++ structures\datagrid/Core.php Sat Oct 2 15:26:45 2004 @@ -79,8 +79,14 @@ */ var $pager; /** + * The namespace for GET parameters + * @var string + */ + var $namespace = '_sdg'; + + /** * Constructor * * Creates default table style settings * @@ -94,8 +100,45 @@ $this->page = $page; } /** + * Sets the namepace for GET parameters + * + * @param string $ns The new namespace + * @access public + */ + function setNamespace($ns) + { + $this->namespace = $ns; + } + + /** + * Retrieves the current namespace for GET parameters + * @return string The current namespace + * @access public + */ + function getNamespace() + { + return $this->namespace; + } + + /** + * Sets the sort order, direction and page number from the GET parameters + * without actually sorting. Useful if sorting is done by a database. + * + * @access public + */ + function setRequestParams() + { + if (isset($_GET[$this->namespace . '_orderBy'])) + $this->sortArray[0] = $_GET[$this->namespace . '_orderBy']; + if (isset($_GET[$this->namespace . '_direction'])) + $this->sortArray[1] = $_GET[$this->namespace . '_direction']; + if (isset($_GET[$this->namespace . '_page'])) + $this->page = $_GET[$this->namespace . '_page']; + } + + /** * Retrieves the current page number when paging is implemented * * @return string the current page number * @access public @@ -226,9 +269,9 @@ function buildPaging($options) { $defaults = array('totalItems' => count($this->recordSet), 'perPage' => $this->rowLimit, - 'urlVar' => 'page'); + 'urlVar' => $this->namespace . '_page'); $options = array_merge($defaults, $options); $this->pager =& Pager::factory($options); } diff -r -d -U 4 c:\temp\Structures_DataGrid-0.5.3\DataGrid/Renderer/HTMLTable.php structures\datagrid/Renderer/HTMLTable.php --- c:\temp\Structures_DataGrid-0.5.3\DataGrid/Renderer/HTMLTable.php Tue Aug 10 15:54:44 2004 +++ structures\datagrid/Renderer/HTMLTable.php Sat Oct 2 15:21:54 2004 @@ -271,33 +271,35 @@ */ function _buildHTMLTableHeader() { $cnt = 0; + $directionstr = $this->_dg->namespace . '_direction='; + $orderbystr = $this->_dg->namespace . '_orderBy='; foreach ($this->_dg->columnSet as $column) { //Define Content if ($column->orderBy != null) { // Determine Direction if ($this->_dg->sortArray[1] == 'ASC') { - $direction = 'direction=DESC'; + $direction = $directionstr . 'DESC'; } else { - $direction = 'direction=ASC'; + $direction = $directionstr . 'ASC'; } // Build URL -- This needs much refinement :) if (isset($this->path)) { $url = $this->path . '?'; } else { $url = $_SERVER['PHP_SELF'] . '?'; } - if (isset($_SERVER['QUERY_STRING'])) { + if (!empty($_SERVER['QUERY_STRING'])) { $qString = explode('&', $_SERVER['QUERY_STRING']); $i = 0; foreach($qString as $element) { if ($element != '') { - if (stristr($element, 'orderBy')) { - $url .= 'orderBy=' . $column->orderBy; + if (stristr($element, $orderbystr)) { + $url .= $orderbystr . $column->orderBy; $orderByExists = true; - } elseif (stristr($element, 'direction')) { + } elseif (stristr($element, $directionstr)) { $url .= $direction; } else { $url .= $element; } @@ -308,16 +310,24 @@ } } if (!isset($orderByExists)) { - $url .= '&orderBy=' . $column->orderBy . '&' . + $url .= '&' . $orderbystr . $column->orderBy . '&' . $direction; } } else { - $url .= 'orderBy=' . $column->orderBy . '&' . $direction; + $url .= $orderbystr . $column->orderBy . '&' . $direction; } - $str = '<a href="' . $url . '"><b>' . $column->columnName . + $name = $column->columnName; + // if sorted by this column display an arrow indicating the order + if ($this->_dg->sortArray[0] == $name) { + if ($this->_dg->sortArray[1] == 'ASC') + $name .= ' ↓'; + elseif ($this->_dg->sortArray[1] == 'DESC') + $name .= ' ↑'; + } + $str = '<a href="' . $url . '"><b>' . $name . '</b></a>'; } else { $str = '<b>' . $column->columnName . '</b>'; }
 [2004-10-20 21:05 UTC] asnagy at webitecture dot org
This bug has been fixed in CVS. In case this was a documentation problem, the fix will show up at the end of next Sunday (CET) on pear.php.net. In case this was a pear.php.net website problem, the change will show up on the website in short time. Thank you for the report, and for helping us make PEAR better.