pclib  2.3.2
Lightweight PHP framework
Public Member Functions | Static Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Grid Class Reference

Displaying tabular data in table layout. More...

Inheritance diagram for Grid:
Tpl BaseObject

Public Member Functions

 setPage ($page)
 Set active (selected) page. More...
 
 setQuery ($sql)
 Set sql query which will be used as datasource for the grid. More...
 
 setArray (array $dataArray, $totalLength=0)
 Set php array which will be used as datasource for the grid. More...
 
 summary ($field, $sql= '', $sumblock= 'summary')
 Enable summarization rows. More...
 
 setSort ($s)
 Enable sorting. More...
 
 loadSession ()
 Load grid object from session. More...
 
 saveSession ()
 Save grid object to session. More...
 
 print_Element ($id, $sub, $value)
 This function is called for each template tag when it is printed. More...
 
 print_Pager ($id, $sub)
 Print grid pager. More...
 
 print_Sort ($id, $sub)
 Print sort-link. More...
 
 create ($tableName)
 Use default template for displaying database table content.
 
 getExportCsv ($options=array())
 Return content of the grid as csv-text. More...
 
 exportCsv ($fileName, $options=array())
 Show download dialog for csv-file with content of the grid. More...
 
- Public Member Functions inherited from Tpl
 __construct ($path= '', $sessName= '')
 Load and parse template file. More...
 
 init ()
 Initialization - must be called after load()
 
 load ($path)
 Load template file. More...
 
 loadString ($s)
 Load string $s as template. More...
 
 out ($block=null)
 Display template populated with content. More...
 
 html ($block=null)
 Return html output of the template populated with content. More...
 
 enable ()
 Enable (show) or disable (hide) tag or block $name. More...
 
 disable ()
 Disable (hide) tag or block $name. More...
 
 set ($keystr, $value)
 Set attributes for template elements. More...
 
 getValue ($id)
 Return value of element $id. More...
 
 loadSession ()
 Load object from session.
 
 saveSession ()
 Save object to session.
 
 deleteSession ()
 Remove object from session.
 
 create ($tableName)
 Use default template for displaying database table content.
 
 compute ($id)
 Return computed value of element $id. More...
 
 print_Element ($id, $sub, $value)
 This function is called for each template tag when it is printed. More...
 
 print_Number ($id, $sub, $value)
 Print numeric $value. More...
 
 print_String ($id, $sub, $s)
 Print string $value. More...
 
 print_Bind ($id, $sub, $value)
 Bind $value to LABEL coming from datasource and print LABEL. More...
 
 print_Link ($id, $sub, $value)
 Create html link. More...
 
 print_Env ($id, $sub, $value)
 Print value from url (from _GET array). More...
 
 print_Class ($id, $sub, $value)
 Print all fields into template. More...
 
 print_Action ($id, $sub, $value)
 Call controller's method and include result into template. More...
 
 print_Block ($block)
 Print template block. More...
 
 getPopup ($id, $attr, $url)
 Generate javascript code for popup window. More...
 
 getItems ($id)
 Load lookup table for elements such as bind, select, check or radio. More...
 
- Public Member Functions inherited from BaseObject
 loadDefaults ($className=null)
 Load default parameters of class $className into object instance.
 
 setProperties (array $defaults)
 Set public properties of object from the array. More...
 
 addEvent ($name, $callback)
 Add event handler to $object->$name property. More...
 
 toArray ()
 Convert object to array. More...
 

Static Public Member Functions

static invalidate ($sessName)
 Invalidate grid $sessname. More...
 
- Static Public Member Functions inherited from BaseObject
static defaults ()
 Set or retireve default parameters of the object. More...
 

Data Fields

 $length = 0
 Number of rows of the grid. More...
 
 $filter = array()
 array filter - Values of current filter. More...
 
 $multiSort = false
 enable sorting by more than one column. More...
 
 $pager
 var GridPager
 
 $sortArray = array()
 Current sorting. More...
 
- Data Fields inherited from Tpl
 $onInit
 Occurs on template initialization. More...
 
 $onLoad
 Occurs after template is loaded and parsed. More...
 
 $onBeforeOut
 Occurs before output. More...
 
 $onAfterOut
 Occurs after output. More...
 
 $name
 Name of the template. More...
 
 $elements = array()
 Array of elements loaded from <?elements ? > section.
 
 $values = array()
 Array of template values. More...
 
 $db
 var Db
 
 $translator
 var Translator
 
 $router
 var Router
 
 $useXhtml = false
 Generate XHTML code. More...
 
 $escapeHtmlFunction
 Function for escaping html in template values. More...
 
- Data Fields inherited from BaseObject
 $onNewInstance
 Occurs when new instance of the class is created. More...
 
 $onMissingMethod
 Occurs when called method does not exist. More...
 
 $serviceLocator
 var function() Return service object when requested with service(). More...
 

Protected Member Functions

 _init ()
 Initialization - must be called after load()
 
 initPager ()
 Create and configure grid pager.
 
 getPager ()
 Return instance of GridPager.
 
 _out ($block=null)
 Display datagrid. More...
 
 sortUrl ($id)
 Return url for sortlink.
 
 trPrintElement ($elem)
 Implements {grid.labels} and {grid.items} placeholders. More...
 
 getVariable ($id)
 Get template variable tvar... More...
 
 getValues ()
 Load values for current page from database (fill tpl::values array). More...
 
 setLength ($length)
 Set grid->length (total number of rows). More...
 
 getDataArray ()
 Load values for current page from dataarray (array-based grid). More...
 
 getSummary ($block)
 Get summary row for summarization grid.
 
 applyFilter (array $dataArray)
 Apply filter on arraygrid. More...
 
 getQuery ()
 Build grid query and return result (resource). More...
 
 getBaseUrl ()
 get proper base url for grid sort and pager & other links
 
- Protected Member Functions inherited from Tpl
 getAttr ($id, $attr)
 Return attribute of element $id. More...
 
 getVariable ($id)
 Get template variable tvar... More...
 
 getRowNo ()
 Return row number of the current block. More...
 
 createFromTable ($tableName, $templatePath)
 Use default template for displaying database table content.
 
 trPrintElement ($elem)
 Print element in table layout. More...
 
 getUrl ($elem)
 Return url for the element (button, link) with completed parameters. More...
 
 formatDate ($dtstr, $fmt= '')
 DATABASE DATE => HUMAN DATE (in strftime() format) More...
 
 formatStr ($s, $fmt)
 Format string $s according format $fmt.
 
- Protected Member Functions inherited from BaseObject
 fireEvent ($name, array $args=array())
 Run all event handlers in $object->$name property. More...
 
 service ($service, $default=null)
 Try acquire $service and load it into property $this->$service. More...
 

Protected Attributes

 $dataArray
 Array of values for array-based grid. More...
 
 $sumArray
 Summary fields (if any). More...
 
 $sql
 grid sql query. More...
 
 $className = 'grid'
 Name of the 'class' element.
 
- Protected Attributes inherited from Tpl
 $sessName
 Name of the session variable where template values are stored. More...
 
 $app
 var App Link to application object. More...
 
 $config = null
 Link to array of configuration parameters. More...
 
 $document
 Document array - It contains parsed template. More...
 
 $parser
 var TplParser
 

Detailed Description

Displaying tabular data in table layout.

Features:

Class Grid implements following template tags:
class, sort, pager
See also Template tags implemented by class Grid

Member Function Documentation

_out (   $block = null)
protected

Display datagrid.

Parameters
string$blockIf set, only block $block will be shown.
applyFilter ( array  $dataArray)
protected

Apply filter on arraygrid.

exportCsv (   $fileName,
  $options = array() 
)

Show download dialog for csv-file with content of the grid.

Parameters
array$options
See also
getExportCsv()
getDataArray ( )
protected

Load values for current page from dataarray (array-based grid).

See also
getvalues(), setarray()
getExportCsv (   $options = array())

Return content of the grid as csv-text.

Parameters
array$options[templatePath: '', csv-separ: ';', csv-row-separ: "\r\n"]
Returns
string csv-text
getQuery ( )
protected

Build grid query and return result (resource).

setquery() is required before calling this function.

getValues ( )
protected

Load values for current page from database (fill tpl::values array).

tpl::values are not cleared, so you can add additional fields from the code.

getVariable (   $id)
protected

Get template variable tvar...

static invalidate (   $sessName)
static

Invalidate grid $sessname.

Update number of pages of session grid, if it is changed for example by adding/deleting rows in table.

loadSession ( )

Load grid object from session.

Called when $sessname in constructor is set. Do not call directly. "Session" grid is necessary, if you need remember current page, sorting and filter after page-reload.

print_Element (   $id,
  $sub,
  $value 
)

This function is called for each template tag when it is printed.

Template element handler
Get element definition from Tpl->elements and write element value from Tpl->values into template.
Note
This function comes in form print_*() where "*" is usually TAGNAME which can be used in <?elements ?> section of template.
Parameters
string$idname of template tag {ID}
string$submodificator (second part) of template tag name {ID.sub}
mixed$valuevalue of element going from Tpl->values array
print_Pager (   $id,
  $sub 
)

Print grid pager.

{pager} tag will show default pager, for modificators - see Template tags implemented by class Grid.

Template element handler
Get element definition from Tpl->elements and write element value from Tpl->values into template.
Note
This function comes in form print_*() where "*" is usually TAGNAME which can be used in <?elements ?> section of template.
Parameters
string$idname of template tag {ID}
string$submodificator (second part) of template tag name {ID.sub}
mixed$valuevalue of element going from Tpl->values array
print_Sort (   $id,
  $sub 
)

Print sort-link.

Template element handler
Get element definition from Tpl->elements and write element value from Tpl->values into template.
Note
This function comes in form print_*() where "*" is usually TAGNAME which can be used in <?elements ?> section of template.
Parameters
string$idname of template tag {ID}
string$submodificator (second part) of template tag name {ID.sub}
mixed$valuevalue of element going from Tpl->values array
saveSession ( )

Save grid object to session.

Called when $sessname in constructor is set. Do not call directly. "Session" grid is necessary, if you need remember current page, sorting and filter after page-reload.

setArray ( array  $dataArray,
  $totalLength = 0 
)

Set php array which will be used as datasource for the grid.

Parameters
string$dataArray- Array of rows: [$row1, $row2, ...].
string$totalLengthTotal number of rows (optional) (Use this, if you desire send to grid not all rows, but only one page at the time).
See also
setQuery()
setLength (   $length)
protected

Set grid->length (total number of rows).

Parameters
int$lengthNumber of rows
setPage (   $page)

Set active (selected) page.

Parameters
int$pagePage number
setQuery (   $sql)

Set sql query which will be used as datasource for the grid.

For info about SQL parameters and grid filtering see Dynamic SQL.

Parameters
string$sqlSql query. Only SELECT-queries are allowed.
See also
setArray()
setSort (   $s)

Enable sorting.

Example: $grid->setSort('field1,field2');

Parameters
string$sfieldlist
summary (   $field,
  $sql = '',
  $sumblock = 'summary' 
)

Enable summarization rows.

When $field value changes, summary block is pushed into grid output.

Parameters
string$fieldGROUP BY field
string$sqlSumarization query
string$sumblockName of the summary block (must exists in template)
trPrintElement (   $elem)
protected

Implements {grid.labels} and {grid.items} placeholders.

See also
Tpl::print_class()
Template element handler
Get element definition from Tpl->elements and write element value from Tpl->values into template.
Note
This function comes in form print_*() where "*" is usually TAGNAME which can be used in <?elements ?> section of template.
Parameters
string$idname of template tag {ID}
string$submodificator (second part) of template tag name {ID.sub}
mixed$valuevalue of element going from Tpl->values array

Field Documentation

$dataArray
protected

Array of values for array-based grid.

$filter = array()

array filter - Values of current filter.

$length = 0

Number of rows of the grid.

$multiSort = false

enable sorting by more than one column.

$sortArray = array()

Current sorting.

$sql
protected

grid sql query.

$sumArray
protected

Summary fields (if any).


The documentation for this class was generated from the following file: