pclib  3.0.0
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...
 
 setSelection (orm\Selection $sel)
 Set Selection $sel 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, $templatePath='')
 Use default template for displaying database table content.
 
 getExportCsv ($options=[], $page=null)
 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...
 
 exportExcel ($fileName)
 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...
 
 setAttr ($id, $value, $value2=null)
 Set attribute globally for template elements. More...
 
 getBlock ($block)
 Return values of block $block. More...
 
 getValue ($id)
 Return value of element $id. More...
 
 deleteSession ()
 Remove object from session.
 
 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...
 
 addTag ($line)
 Add new element. More...
 
 addType ($name, $fn)
 Add new type of element handled by callback function $fn. More...
 
 setFields ($fields)
 Show only this $fields in template (using tag {grid.fields} or {form.fields}). More...
 
 htmlTag ($name, $attr=[], $content=null)
 Return html tag $name with attributes. 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...
 
 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.
 
 $filter = array()
 array filter - Values of current filter.
 
 $multiSort = false
 enable sorting by more than one column.
 
 $pager
 var GridPager
 
 $sortArray = array()
 Current sorting.
 
- Data Fields inherited from Tpl
 $name
 Name of the template.
 
 $elements = array()
 Array of elements loaded from <?elements ? > section.
 
 $values = array()
 Array of template values.
 
 $db
 var Db
 
 $router
 var Router
 
 $escapeHtmlFunction
 Function for escaping html in template values.
 
- Data Fields inherited from BaseObject
 $serviceLocator
 var function() Return service object when requested with service().
 

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...
 
 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.
 
 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...
 
 getRowNo ()
 Return row number of the current block.
 
 createFromTable ($tableName, $templatePath)
 Use default template for displaying database table content.
 
 compute ($id)
 Return computed value of element $id.
 
 getPopup ($id, $attr, $url)
 Generate javascript code for popup window. More...
 
 getUrl ($elem)
 Return url for the element (button, link) with completed parameters.
 
 formatDate ($dtstr, $fmt='')
 DATABASE DATE => HUMAN DATE (in date() format) More...
 
 formatStr ($s, $fmt)
 Format string $s according format $fmt.
 
 getItems ($id)
 Load lookup table for elements such as bind, select, check or radio. More...
 
- Protected Member Functions inherited from BaseObject
 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.
 
 $sumArray
 Summary fields (if any).
 
 $sql
 grid sql query.
 
 $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.
 
 $config = null
 Link to array of configuration parameters.
 
 $document
 Document array - It contains parsed template.
 
 $parser
 var TplParser
 
 $fields = []
 List of id's to be printed in {grid.fields} tag.
 
 $types = []
 Additional element type handlers.
 

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()

_out (   $block = null)
protected

Display datagrid.

Parameters
string$blockIf set, only block $block will be shown.

Reimplemented from Tpl.

◆ exportCsv()

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

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

Parameters
array$options
See also
getExportCsv()

◆ exportExcel()

exportExcel (   $fileName)

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

See also
getExportCsv()

◆ getDataArray()

getDataArray ( )
protected

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

See also
getvalues(), setarray()

◆ getExportCsv()

getExportCsv (   $options = [],
  $page = null 
)

Return content of the grid as csv-text.

Parameters
array$options[csv-separ: ';', csv-row-separ: "\n"]
Returns
string csv-text

◆ getQuery()

getQuery ( )
protected

Build grid query and return result (resource).

setquery() is required before calling this function.

◆ getValues()

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.

◆ invalidate()

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()

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.

Reimplemented from Tpl.

◆ print_Element()

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

Reimplemented from Tpl.

◆ print_Pager()

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()

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()

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.

Reimplemented from Tpl.

◆ setArray()

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()

setLength (   $length)
protected

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

Parameters
int$lengthNumber of rows

◆ setPage()

setPage (   $page)

Set active (selected) page.

Parameters
int$pagePage number

◆ setQuery()

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()

◆ setSelection()

setSelection ( orm\Selection  $sel)

Set Selection $sel which will be used as datasource for the grid.

Parameters
orm\Selection$sel

◆ setSort()

setSort (   $s)

Enable sorting.

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

Parameters
string$sfieldlist

◆ summary()

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()

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

Reimplemented from Tpl.


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