cvs: pear /Structures_DataGrid/DataGrid/Renderer XUL.php
| From: | Olivier Guilyardi | Date: | Mon, 27 Feb 2006 22:47:21 +0000 |
| Subject: | cvs: pear /Structures_DataGrid/DataGrid/Renderer XUL.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-38713@lists.php.net to get a copy of this message | ||
olivierg Mon Feb 27 22:47:21 2006 UTC
Modified files:
/pear/Structures_DataGrid/DataGrid/Renderer XUL.php
Log:
Splitted the main body generation into subroutines, in conformance with the driver interface and
the container paradigm
http://cvs.php.net/viewcvs.cgi/pear/Structures_DataGrid/DataGrid/Renderer/XUL.php?r1=1.15&r2=1.16&diff_format=u
Index: pear/Structures_DataGrid/DataGrid/Renderer/XUL.php
diff -u pear/Structures_DataGrid/DataGrid/Renderer/XUL.php:1.15
pear/Structures_DataGrid/DataGrid/Renderer/XUL.php:1.16
--- pear/Structures_DataGrid/DataGrid/Renderer/XUL.php:1.15 Sat Feb 25 18:02:36 2006
+++ pear/Structures_DataGrid/DataGrid/Renderer/XUL.php Mon Feb 27 22:47:21 2006
@@ -18,7 +18,7 @@
// | Mark Wiesemann <wiesemann@php.net> |
// +----------------------------------------------------------------------+
//
-// $Id: XUL.php,v 1.15 2006/02/25 18:02:36 wiesemann Exp $
+// $Id: XUL.php,v 1.16 2006/02/27 22:47:21 olivierg Exp $
require_once 'Structures/DataGrid/Renderer/Common.php';
//require_once 'XML/XUL.php';
@@ -40,7 +40,7 @@
* - selfPath: (string) The complete path for sorting and paging links
* (default: $_SERVER['PHP_SELF'])
*
- * @version $Revision: 1.15 $
+ * @version $Revision: 1.16 $
* @author Andrew S. Nagy <asnagy@webitecture.org>
* @author Olivier Guilyardi <olivier@samalyse.com>
* @author Mark Wiesemann <wiesemann@php.net>
@@ -51,11 +51,17 @@
*/
class Structures_DataGrid_Renderer_XUL extends Structures_DataGrid_Renderer_Common
{
-
+ /**
+ * Whether the container is user-provided or not
+ * @var bool
+ * @access protected
+ */
+ var $_isCustomContainer;
+
/**
* Constructor
*
- * Build default values
+ * Initialize default options
*
* @access public
*/
@@ -72,14 +78,40 @@
}
/**
- * Initialize a string for the XUL XML code if it is not already existing
+ * Generate the XML declaration and initialize the XUL datagrid, if needed
*
+ * A user may provide a custom container by means of the setContainer()
+ * method (or equivalent). If so, this custom container should already
+ * contains XML, XUL window and listbox declarations similar/equivalent
+ * to the ones generated by this method.
+ *
* @access protected
*/
function init()
{
if (is_null($this->_container)) {
- $this->_container = '';
+
+ $this->_isCustomContainer = false;
+
+ // Define XML
+ $this->_container = XML_Util::getXMLDeclaration() . "\n";
+
+ // Define Stylesheets
+ foreach ($this->_options['css'] as $css) {
+ $this->_container .= "<?xml-stylesheet href=\"$css\" " .
+
"type=\"text/css\"?>\n";
+ }
+
+ // Define Window Element
+ $this->_container .=
+ "<window title=\"{$this->_options['title']}\" "
.
+ "xmlns=\"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul\">\n";
+
+ // Define Listbox Element
+ $this->_container .= "<listbox rows=\"" . $this->_pageLimit .
"\">\n";
+
+ } else {
+ $this->_isCustomContainer = true;
}
}
@@ -106,34 +138,14 @@
}
/**
- * Handles building the body of the table
+ * Build the <listhead> grid header
*
* @access protected
* @return void
*/
- function buildBody()
+ function buildHeader()
{
- // Define XML
- $xul = XML_Util::getXMLDeclaration() . "\n";
-
- // Define Stylesheets
- foreach ($this->_options['css'] as $css) {
- $xul .= "<?xml-stylesheet href=\"$css\"
type=\"text/css\"?>\n";
- }
-
- // Define Window Element
- $xul .= "<window title=\"{$this->_options['title']}\" "
.
- "xmlns=\"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul\">\n";
-
- // Define Listbox Element
- $xul .= "<listbox rows=\"" . $this->_pageLimit .
"\">\n";
-
- // FIXME: move header building into buildHeader()
- // => Problem: Where have the above XML tags (and the related closing
- // tags) to go? (flatten()?)
-
- // Build Grid Header
- $xul .= " <listhead>\n";
+ $this->_container .= " <listhead>\n";
for ($col = 0; $col < $this->_columnsNum; $col++) {
$field = $this->_columns[$col]['field'];
$label = $this->_columns[$col]['label'];
@@ -164,32 +176,49 @@
'?' . $this->_requestPrefix . 'orderBy=' . $field .
"&" . $this->_requestPrefix .
"direction=$dirArg';";
$label = XML_Util::replaceEntities($label);
- $xul .= ' <listheader label="' . $label . '" ' .
+ $this->_container .= ' <listheader label="' . $label .
'" ' .
"sortDirection=\"$dirCur\" oncommand=\"$onClick\"
/>\n";
}
- $xul .= " </listhead>\n";
-
- // Build Grid Body
+ $this->_container .= " </listhead>\n";
+ }
+
+ /**
+ * Handles building the body of the table
+ *
+ * @access protected
+ * @return void
+ */
+ function buildBody()
+ {
for ($row = 0; $row < $this->_recordsNum; $row++) {
- $xul .= " <listitem>\n";
+ $this->_container .= " <listitem>\n";
for ($col = 0; $col < $this->_columnsNum; $col++) {
$value = $this->_records[$row][$col];
// FIXME: 'ä' is displayed as '?' ==> encoding is required!
- $xul .= ' ' .
+ $this->_container .= ' ' .
XML_Util::createTag('listcell',
array('label' => $value)) .
"\n";
}
- $xul .= " </listitem>\n";
+ $this->_container .= " </listitem>\n";
}
- $xul .= "</listbox>\n";
- $xul .= "</window>\n";
-
- $this->_container .= $xul;
}
/**
+ * Close the XUL listbox and window, if needed
+ *
+ * @access protected
+ */
+ function finalize()
+ {
+ if (!$this->_isCustomContainer) {
+ $this->_container .= "</listbox>\n";
+ $this->_container .= "</window>\n";
+ }
+ }
+
+ /**
* Returns the XUL for the DataGrid
*
* @access public
@@ -208,10 +237,19 @@
*/
function flatten()
{
- header('Content-type: application/vnd.mozilla.xul+xml');
return $this->_container;
}
+ /**
+ * Render to the standard output
+ *
+ * @access public
+ */
+ function render()
+ {
+ header('Content-type: application/vnd.mozilla.xul+xml');
+ parent::render();
+ }
}
?>