Home » Structures » Structures_DataGrid » Bug #4497
New feature , flexy datagrid renderer
Details
| Request #4497 | New feature , flexy datagrid renderer |
|---|---|
| Submitted | 2005-06-01 03:30 UTC |
| From | danielr at electroteque dot org |
| Assigned | olivierg |
| Status | Closed |
| Package | Structures_DataGrid |
| PHP Version | 5.0.3 |
| OS | N/A |
| Roadmaps | (Not assigned) |
Comments
[2005-06-01 03:30 UTC] danielr at electroteque dot org
Description:
------------
I have modified the smarty renderer which now allows for
a flexy renderer. I have added extra methods, so the
flexy datagrid template can use Pager options, so its a
combination of HtmlTable and Smarty renderer. There is a
rowcolour method, and a sort method, maybe this can come
from dg itself ?? There is also the number of results
per page list.
Here is the php source, I have found this quite useful.
www.electroteque.org/pear/Flexy.phps
[2005-06-05 12:41 UTC] post at mark-wiesemann dot de
I'd like to give some comments to your code:
- you are mixing tabs/spaces, PEAR CS require 4 spaces for indentations
- switch_row_colours() is not a valid function name according to PEAR CS, switchRowColours() would be correct
- maybe you should rework this function and do it the way HTMLTable renderer does it
- sorting is done by DG, no need to do this in the renderer
- you are using a DB_DataObject object in render method, but I think renderer classes should not be restricted to one special DataSource
- dirname($_SERVER['SCRIPT_FILENAME']).'/compile' is not very flexible (although it is done the same way in Smarty renderer) and this applies also to the other options; I think it's better to add $option as a second parameter to setTemplate and then merge it with your array to have default values for values the user did not set
- I think getResults() function does not belong into the renderer but in the script using the renderer / the DataGrid; maybe you also want to use the new functions that were added to Core.php (CVS) instead of using numItems() and numPages() from Pager
- and finally: maybe you can provide some example code so that other people can test it without having to figure out how to use your renderer
Just my opinions about this ...
[2005-06-10 01:32 UTC] danielr at electroteque dot org
Hi there I have made the perPage fix, aswell as some
other tweaks, getPaging now returns the entire array, I
call getPaging in the _buildPaging method which returns
as a casted object, flexy can then use this so i can
setup the paginging links in the template. Here is the
usage again, I tried a simple bind($do) however it didnt
work, it broke !
function data_grid($do, $template, $limit = 10, $obj =
null)
{
/**
* Require the DataGrid and DataSource
*/
require_once 'Structures/DataGrid.php';
require_once 'Structures/DataGrid/
DataSource.php';
/*
* Collect the Pager options
*/
$paging_options =
&PEAR::getStaticProperty('Pager','options');
$options = array(
'prevImg'=>"<img
name=\"Back$i\" src=\"images/nav_back_off.gif\"
border=\"0\"
alt=\"Previous Page\" onmouseover=\"this.src='images/
nav_back_on.gif'\"
onmouseout=\"this.src='images/nav_back_off.gif'\">",
'nextImg'=>"<img
name=\"Forward$i\" src=\"images/nav_forward_off.gif\"
border=\"0\"
alt=\"Next Page\" onmouseover=\"this.src='images/
nav_forward_on.gif'\"
onmouseout=\"this.src='images/nav_forward_off.gif'\">",
'firstPageText'=>"<img
name=\"First$i\" src=\"images/nav_first_off.gif\"
border=\"0\"
alt=\"First Page\" onmouseover=\"this.src='images/
nav_first_on.gif'\"
onmouseout=\"this.src='images/nav_first_off.gif'\">",
'lastPageText'=>"<img
name=\"Last$i\" src=\"images/nav_last_off.gif\"
border=\"0\" alt=\"Last
Page\" onmouseover=\"this.src='images/nav_last_on.gif'\"
onmouseout=\"this.src='images/nav_last_off.gif'\">",
'firstPagePre'=>'',
'firstPagePost'=>'',
'lastPagePre'=> '',
'lastPagePost'=> ''
);
if (is_array($this->settings['Pager'])) {
$paging_options =
array_merge($this->settings['Pager'],$options);
}
/*
* Setup the DataGrid
*/
$dg =& new
Structures_DataGrid($_GET['setPerPage'] ?
$_GET['setPerPage'] : $limit,$_GET['page'] ?
$_GET['page'] : 1,'Flexy');
$dg->sortRecordSet(isset($_GET['orderBy']) ?
$_GET['orderBy'] : '', isset($_GET['direction']) ?
$_GET['direction'] :
'ASC');
if (is_object($do)) {
/*
* Setup the DataObject as the DataSource
*/
$data =
Structures_DataGrid_DataSource::
create($do,false,'DataObject');
$dg->bindDataSource($data);
$this->dg = $dg;
/*
* Send the flexy object to the flexy
renderer
*/
$dg->renderer->setFlexyObj($this->tpl);
/*
* Send the template to the flexy renderer
*/
$dg->renderer->setTemplate($template);
$this->datagrid = $dg->renderer-
>render($obj);
$dg->renderer->_flexy-
>compile('datagrid.html');
return $dg->renderer->_flexy->output($this);
} elseif (is_array($do) && !empty($do)) {
/*
* Setup an array as the DataSource
*/
$data =
Structures_DataGrid_DataSource::create($do);
$dg->bindDataSource($data);
$this->dg = $dg;
$dg->renderer->setTemplate($template);
$this->datagrid = $dg->renderer-
>render($obj);
$dg->renderer->_flexy-
>compile('datagrid.html');
return $dg->renderer->_flexy->output($this);
}
}
www.electroteque.org/pear/DataGrid
[2005-06-12 20:07 UTC] post at mark-wiesemann dot de
- the tabs/spaces problem is still there
- bind problems: "it didnt work, it broke" is not very helpful (if you want help regarding this problem: describe it better, show the code you tried and the errors you got [and, as this has nothing to do with this feature request, you might better send me an email])
- Please use minimal examples that show the functionality of the extension you propose. In the case of your new renderer it would be better to not use the images in the pager options (e.g. just use pagers default values for it) and to not have a function that needs to be called but instead code that directly works without having to add any line of code. I think the way I did it for the new DataSource drivers in #4254 and #4379 can be seen as an example (altough one needs to define a DBTable object or specify a DSN).
Just a few suggestions that makes it easier for people that are interested in this request and especially for the package maintainer, too.
[2006-02-27 22:12 UTC] danielr at electroteque dot org
Hi i just got an email, what is the status of this ? Ill
fix it up if need be ?
[2006-02-28 12:47 UTC] danielr at electroteque dot org
ill take a look then, i didnt think i was going to be
maintaining this mostly a suggestion :)
[2006-03-02 16:41 UTC] danielr at electroteque dot org
This is kinda of one of the reasons i didnt get back in
time, I cant host the example, im on a crap host sorry,
it runs php 4.2 can u believe.
all the examples and renderer class is here
www.electroteque.org/pear/Structures_DataGrid.tar.gz
[2006-03-05 02:04 UTC] danielr at electroteque dot org
I was wondering if I could get a reply if possible , i
took time to make the example, even though knowing I
cant host it just yet :\
[2006-03-06 13:44 UTC] danielr at electroteque dot org
Ok i think im being messed around here, is this DG in
CVS ? I have the latest updated datagrid which is what i
have worked off , the code example in the tarball is
working ..
[2006-03-06 13:59 UTC] danielr at electroteque dot org
Ok thanks for ellaborating, are the updated renderers
and examples available in cvs ? Ill have to work from
them of course. There is one chunk of code i had to grab
from the HTMLTable renderer which dealt with the column
titles and sorting etc , maybe there should be a method
in the core classes for this ?
Ill have to download the CVS now and rework my stuff
please give me a few days thanks.
[2006-03-06 14:35 UTC] danielr at electroteque dot org
Ok that would be great thanks, when will that be ?
[2006-03-06 16:22 UTC] olivierg at php dot net
Daniel and Mark, I have started to work on the Smarty renderer last week, and found some lacks in the new driver interface.
The refactoring is not yet finished. I strongly recommend that you wait until the end of march before working on the Flexy renderer, or any other new one.
[2006-04-04 12:20 UTC] danielr at electroteque dot org
can someone let me know the status if possible
[2006-04-27 21:16 UTC] olivierg at php dot net
Okay, the refactoring (bug #5859) is quite finished. Now, we can talk about new drivers.
I've just had a look at http://www.electroteque.org/pear/Structures_DataGrid.tar.gz
Your work is quite interesting. I think you should look at the Smarty renderer in CVS. It's been rewritten.
Especially, to support the new Structures_DataGrid::fill() method, you must replace setFlexyObj() with setContainer(), and add a getContainer() method.
This will allow the user to do, for example :
$flexy = new HTML_Template_Flexy($options);
$datagrid->fill($flexy);
$flexy->compile('..');
Setting the template, as for Smarty, should be done by the user, out of the driver IMO.
You may also want to wait a few more weeks. Structures_DataGrid 0.7 will be out, and there should soon be a detailed section in the manual, explaining exactly how to write rendering drivers.
Last but not least : we are splitting drivers apart.
This means that :
- your new driver will be a separated package named Structures_DataGrid_Renderer_Flexy.
- we will certainly ask you to be the lead of this new package, and as such, you will have to maintain it, fix bugs, etc...
Is it ok with you ?
[2006-04-28 13:50 UTC] danielr at electroteque dot org
ok i checked out from cvs, can you give me the weekend
to go over it thanks heaps.
[2006-05-01 09:49 UTC] danielr at electroteque dot org
the docs havent been updated im assuming ill wait for
the release
[2006-06-23 16:43 UTC] danielr at electroteque dot org
Hi its been a few months now, is there an update
regarding the documentated changes, is this the renderer
to work from now, or is it still the old one
http://cvs.php.net/viewvc.cgi/pear/Structures_DataGrid/
DataGrid/Renderer/Smarty.php?revision=1.22&view=markup
[2006-06-23 17:03 UTC] olivierg at php dot net
The CVS version is the brand new Smarty renderer, and is also released as a separate driver :
http://pear.php.net/package/Structures_DataGrid_Renderer_Smarty
Feel free to build your flexy renderer by reading it.
[2006-06-26 04:44 UTC] danielr at electroteque dot org
Hi ive been trying to upgrade all my packages to get
structures datagrid installed. I ran the command pear
upgrade-all and it exited with version deps,
pear/Structures_DataGrid requires PEAR Installer
(version >= 1.4.9), installed version is 1.4.6
My PEAR version is 1.4.9 ?
I then ran with --alldeps and gave me this any ideas ?
iElectro:~ electroteque$ pear upgrade-all --alldeps
Console_Getopt: unrecognized option --alldeps
Where is the pear installer i dont get it ?
[2006-06-26 08:20 UTC] olivierg at php dot net
Try : pear upgrade pear
[2006-06-26 09:41 UTC] danielr at electroteque dot org
^XiElectro:~ electroteque$ pear upgrade pear
Skipping package "pear/PEAR", already installed as
version 1.4.9
No valid packages found
upgrade failed
sorry to hassle u, emails to pear general are being
bounced atm.
[2006-06-26 10:25 UTC] olivierg at php dot net
And what about :
pear upgrade -o structures_datagrid
pear install -o structures_datagrid_renderer_smarty
?
[2006-06-26 10:55 UTC] danielr at electroteque dot org
Ive downloaded the files manually, i cant be mucking
around with a broken installer, or the package file is
broken ?? :)
Can you explain how to add config settings for the
renderer, if this only allows for defaults ?
function Structures_DataGrid_Renderer_Smarty()
{
parent::Structures_DataGrid_Renderer();
$this->_addDefaultOptions(
array(
'selfPath' =>
$_SERVER['PHP_SELF'],
'convertEntities' => true,
'sortingResetsPaging' => true,
)
);
}
I have an issue with setting args for getPaging inside a
template file itself, as it would have to be duplicated
on each template file obviouslly ..
[2006-06-26 11:36 UTC] danielr at electroteque dot org
btw
iElectro:~ electroteque$ pear upgrade -o
structures_datagrid
pear/Structures_DataGrid requires PEAR Installer
(version >= 1.4.9), installed version is 1.4.6
No valid packages found
upgrade failed
Also there is no examples in cvs ??
http://cvs.php.net/viewvc.cgi/pear/Structures_DataGrid/
docs/examples/
[2006-06-26 12:02 UTC] danielr at electroteque dot org
Well where is the updated docs for renderer method
usage, im trying to do the renderer as we speak ?? :\
http://pear.php.net/manual/en/
package.structures.structures-datagrid.example-
advanced.php
This seems outdated also , im getting a depecated method
render here. Also I use the MDB2 dirver in DB Dataobject
and seems to be broken for the DO datasource, its adding
limits incorrectly and sorts are adding when not asked
to and no field is being presented here for the sort.
FROM producers
ORDER BY ASC
Pear Errors with the system
Info: MDB2 Error: syntax error
_doQuery: Could not execute statement[Native code: 1064]
[Native message: You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server
version for the right syntax to use near 'ASC LIMIT 0,
10' at line 7]
[2006-06-26 12:21 UTC] danielr at electroteque dot org
I think ill wait for oliver to reply as he was before,
ive been waiting for a while for months to do this and
was promised some documentation, the smarty render
doesnt have any comments on how to load the renderer
etc, and obviouslly things have changed so its not
exactly like my current renderer, im trying to track
things down as I go, firstly I have to use fill it
seems, Im assuming it dynamically adds properties to the
template object ?