Structures_DataGrid_Renderer_Flexy
[ class tree: Structures_DataGrid_Renderer_Flexy ] [ index: Structures_DataGrid_Renderer_Flexy ] [ all elements ]

Class: Structures_DataGrid_Renderer_Flexy

Source Location: /Structures_DataGrid_Renderer_Flexy-0.1.4/Structures/DataGrid/Renderer/Flexy.php

Class Overview

Structures_DataGrid_Renderer
   |
   --Structures_DataGrid_Renderer_Flexy

Flexy Rendering Driver


Author(s):

Version:

  • Release: @package_version@

Copyright:

  • 1997-2005 The PHP Group

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 163]
Flexy Rendering Driver

SUPPORTED OPTIONS:

  • selfPath: (string) The complete path for sorting and paging links. (default: $_SERVER['PHP_SELF'])
  • sortingResetsPaging: (bool) Whether sorting HTTP queries reset paging.
  • convertEntities: (bool) Whether or not to convert html entities. This calls htmlspecialchars().
  • pagerOptions: (array) The custom options to be sent to the Pager renderer.
  • assocColumns: (bool) Whether or not to build the column header as an associate array.
  • formatter: (array) The callback array for a column header formatter method. (default: array($this,'defaultHeaderFormatter'))
  • columnNames: (array) The set of column names to use for the column header.
  • oddRowAttribute: (string) The css class to be used for odd row listings.
  • evenRowAttribute: (string) The css class to be used for the even row listings.
  • resultsFormat: (string) The format of the results message in sprintf format.
SUPPORTED OPERATION MODES:

  • Container Support: yes
  • Output Buffering: yes
  • Direct Rendering: no
  • Streaming: no
GENERAL NOTES:

This driver does not support the render() method, it only is able to be attached setting the container to a current Flexy instance. Options to the renderer must also be passed using the setOptions() method.

Flexy output is buffered using the DataGrid getOutput() method.

This driver assigns the following Flexy template variables:

  • columnSet: array of columns' labels and sorting links
  • columnHeader: object of columns' labels and sorting links
  • recordSet: associate array of records values
  • numberedSet: numbered array of records values
  • currentPage: current page (starting from 1)
  • recordLimit: number of rows per page
  • pagesNum: number of pages
  • columnsNum: number of columns
  • recordsNum: number of records in the current page
  • totalRecordsNum: total number of records
  • firstRecord: first record number (starting from 1)
  • lastRecord: last record number (starting from 1)
This driver also register a Smarty custom function named getPaging that can be called from Smarty templates with {getPaging} in order to print paging links. This function accepts any of the Pager::factory() options as parameters.

Dynamic Template example, featuring sorting and paging:

  1.  <!-- Show paging links using the custom getPaging function -->
  2.  {getPaging():h}
  3.  
  4.  <p>Showing records {firstRecordto {lastRecord}
  5.  from {totalRecordsNum}page {currentPageof {pagesNum}</p>
  6.  
  7.  <table cellspacing="0">
  8.     <!-- Build header -->
  9.     <tr>
  10.         <th>
  11.             {foreach:columnSet,column}
  12.                 <td><a href="{column[link]:h}">{column[label]:h}</a></td>
  13.             {end:}
  14.         </th>
  15.     </tr>
  16.  
  17.     <!-- Build body -->
  18.     <tr class="{getRowCSS()}" flexy:foreach="numberedSet,k,row">
  19.         {foreach:row,field}
  20.             <td>{field}</td>
  21.         {end:}
  22.     </tr>
  23.  </table>

Static Template example, featuring sorting and paging:

  1.  <table cellspacing="0">
  2.     <!-- Build header -->
  3.     <tr>
  4.         <th>
  5.             <td>
  6.                 <a href="{columnHeader.name[link]:h}">{columnHeader.field1[label]:h}</a>
  7.             </td>
  8.             <td>
  9.                <a href="{columnHeader.surname[link]:h}">{columnHeader.field2[label]:h}</a>
  10.             </td>
  11.         </th>
  12.     </tr>
  13.  
  14.     <!-- Build body -->
  15.     <tr class="{getRowCSS()}" flexy:foreach="recordSet,k,row">
  16.         <td>{row[field1]}</td>
  17.         <td>{row[field2]}</td>
  18.     </tr>
  19.  </table>

  1.  require_once 'HTML/Template/Flexy.php';
  2.  require_once 'Structures/DataGrid.php';
  3.  require_once 'Structures/DataGrid/Renderer/Flexy.php';
  4.  
  5.  $tpl = new HTML_Template_Flexy($config['HTML_Template_Flexy']);
  6.  $dg =new Structures_DataGrid($_GET['setPerPage'$_GET['setPerPage']
  7.                                                     : 10,$_GET['page']
  8.                                                     ? $_GET['page': 1);
  9.  $dg->bind($dataObject);
  10.  $renderer = new Structures_DataGrid_Renderer_Flexy();
  11.  $renderer->setContainer($tpl);
  12.  $renderer->setOptions($config['Structures_DataGrid']);
  13.  $dg->attachRenderer($renderer);
  14.  $this->tpl->compile($template);
  15.  echo $dg->getOutput();



[ Top ]


Class Variables

$columnHeader =

[line 181]

Column Header object

Type:   object


[ Top ]

$columnSet =

[line 187]

Column Set array

Type:   array


[ Top ]



Method Detail

Structures_DataGrid_Renderer_Flexy (Constructor)   [line 194]

Structures_DataGrid_Renderer_Flexy Structures_DataGrid_Renderer_Flexy( )

Constructor
  • Access: public

[ Top ]

buildBody   [line 370]

void buildBody( )

Handles building the body.

Re-iterates through the columns array to regenerate the dataset as an associate array $_assocRecords from a numbered array $_records, for ease of flexy template use.

  • Access: protected

[ Top ]

buildHeader   [line 318]

void buildHeader( &$columns, array $columns)

Builds the column header Determines if to build the columnSet array as associate or numbered.

Preformats the column header labels using the selected header formatter method. Generates sorting links for the labels. Cast the columnSet array to an object columnHeader for flexy template use.

  • Access: protected

Parameters:

array   $columns   —  The array of column fields and labels.
   &$columns   — 

[ Top ]

defaultCellFormatter   [line 485]

string defaultCellFormatter( string $value)

Default formatter for all cells
  • Return: Formatted cell value
  • Access: protected

Parameters:

string   $value   —  Cell value

[ Top ]

flatten   [line 522]

string flatten( )

Buffers the rendered datagrid
  • Return: The buffered rendered datagrid output.
  • Access: public

[ Top ]

getContainer   [line 277]

object Flexy &getContainer( )

Return the currently used Flexy object
  • Return: or PEAR_Error object
  • Access: public

[ Top ]

getPaging   [line 417]

string getPaging( )

Flexy custom function "getPaging"

Setup the pager renderer and send it the pagerOptions config. This is only meant to be called from a flexy template, using the expression: {getPaging():h}

  • Return: Paging HTML links
  • Access: public

[ Top ]

getPerPageSelectBox   [line 400]

string getPerPageSelectBox( )

Pager renderer per-page select menu

Setup the pager renderer and send it the pagerOptions config. This is only meant to be called from a flexy template, using the expression: {getPerPageSelectBox():h} FIXME: Is there a more efficient of doing this?

  • Return: Returns the per-page select box generated by the Pager Renderer
  • Access: public

[ Top ]

getResults   [line 451]

string getResults( [mixed $format = null])

Default Results Statistics

This is only meant to be called from a flexy template, using the expression: {getResults():h}

There are three ways to use this either:

For the default messsage or string format using the resultsFormat config option: {getResults():h}

Sending the format string, but only require total records and total pages {getResults(#You have %s results in %s pages#):h}

Sending the format string, but organising the results message {getResults(#Showing records %s to %s from %s, page %s of %s# ,firstRecord,lastRecord,totalRecordsNum,currentPage,pagesNum):h}

FIXME: Added check to match count of %s to number of arguments to prevent PHP Too Few Arguments Error, as unable to use @. This might need something more efficient.

  • Return: The results message or PEAR error on bad formatted string
  • Access: public

Parameters:

mixed   $format   —  The format of the results message in sprintf format

[ Top ]

getRowCSS   [line 537]

string getRowCSS( )

Switches the row css for displaying odd/even row colours.

FIXME: Is there a more efficient of doing this? Gets the odd/even values from the config settings oddRowAttribute and evenRowAttribute.

  • Return: the css class
  • Access: public

[ Top ]

init   [line 291]

void init( )

Initialize the Flexy container
  • Access: protected

[ Top ]

setContainer   [line 265]

bool setContainer( &$flexy, object $flexy)

Attach an already instantiated Flexy object
  • Return: true
  • Access: public

Parameters:

object   $flexy   —  Flexy object
   &$flexy   — 

[ Top ]

setOptions   [line 239]

void setOptions( mixed $options)

Set multiple options
  • Access: public

Parameters:

mixed   $options   —  An associative array of the form: array("option_name" => "option_value",...)

[ Top ]

_defaultHeaderFormatter   [line 511]

string _defaultHeaderFormatter( string $value)

Default header formatter
  • Return: Formatted cell value
  • Access: protected

Parameters:

string   $value   —  Cell value

[ Top ]

_formatHeaderCell   [line 499]

string _formatHeaderCell( string $value)

Header cell formatter
  • Return: Formatted cell value
  • Access: protected

Parameters:

string   $value   —  Cell value

[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:40:02 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.