PHP Class GridHandler, pkp-lib

Inheritance: extends PKPHandler
Exibir arquivo Open project: pkp/pkp-lib Class Usage Examples

Public Properties

Property Type Description
$_actions Grid actions. The first key represents the position of the action in the grid, the second key represents the action id.
$_columns The GridColumns of this grid.
$_data The grid's data source.
$_dataProvider GridDataProvider
$_emptyRowText empty row locale key
$_features The grid features.
$_footNote Grid foot note locale key
$_itemIterator The item iterator to be used for paging.
$_template The grid template.
$_title grid title locale key
$_urls The urls that will be used in JS handler.

Public Methods

Method Description
__construct ( $dataProvider = null ) Constructor.
addAction ( $action, $position = GRID_ACTION_POSITION_ABOVE ) Add an action.
addColumn ( $column ) Add a column.
authorize ( $request, &$args, $roleAssignments, $enforceRestrictedSite = true )
fetchCell ( &$args, $request ) : JSONMessage Render a cell and send it to the client
fetchGrid ( $args, $request ) : JSONMessage Render the entire grid controller and send it to the client.
fetchRow ( &$args, $request ) : JSONMessage Render a row and send it to the client. If the row no longer exists then inform the client.
fetchRows ( $args, $request ) : JSONMessage Fetch all grid rows from loaded data.
getActions ( $position = GRID_ACTION_POSITION_ABOVE ) : array Get all actions for a given position within the grid.
getColumn ( $columnId ) : GridColumn Retrieve a single column by id.
getColumns ( ) : array Get all columns.
getColumnsByFlag ( $flag ) : array Get columns by flag.
getColumnsCount ( $flag = null ) : integer Get columns number. If a flag is passed, the columns using it will not be counted.
getDataElementSequence ( &$gridDataElement ) : integer Override to return the data element sequence value.
getDataProvider ( ) : FilesGridDataProvider Get the data provider.
getEmptyRowText ( ) Get the no items locale key
getFeatures ( ) : array Get all grid attached features.
getFootNote ( ) : string Get the grid foot note.
getGridDataElements ( $request ) : array Get the grid data.
getGridRangeInfo ( $request, $rangeName, $contextData = null ) : DBResultRange Get grid range info.
getIsSubcomponent ( ) : boolean Override this method to return true if you want to use the grid within another component (e.g. to remove the title or change the layout accordingly).
getItemIterator ( ) : ItemIterator Get the item iterator that represents this grid data.
getJSHandler ( ) : string Get the js handler for this component.
getPublishChangeEvents ( ) : array Get "publish data changed" event list.
getRequestArg ( $key ) : mixed Get a single grid request parameter.
getRequestArgs ( ) : array Get the grid request parameters. These are the parameters that uniquely identify the data within a grid.
getRequestedRow ( $request, $args ) : GridRow Tries to identify the data element in the grids data source that corresponds to the requested row id.
getSelectName ( ) : string Get the select parameter name to store the selected files.
getTemplate ( ) : string Get the grid template.
getTitle ( ) : string Get the grid title.
getUrls ( ) : array Return all grid urls that will be used in JS handler.
hasColumn ( $columnId ) : boolean Checks whether a column exists.
hasGridDataElements ( $request ) : boolean Check whether the grid has rows.
initialize ( $request, $args = null )
isDataElementSelected ( $gridDataElement ) : boolean Returns the current selection state of the grid data element.
renderRow ( $request, $row ) : string Render the passed row and return its markup.
saveSequence ( $args, $request ) : JSONMessage Hook oportunity for grid features to request a save items sequence operation. If no grid feature that implements the saveSequence hook is attached to this grid, this operation will only return the data changed event json message.
setDataElementSequence ( $request, $rowId, &$gridDataElement, $newSequence ) Override to set the data element new sequence.
setEmptyRowText ( $emptyRowText ) Set the no items locale key
setFootNote ( $footNote ) Set the grid foot note.
setGridDataElements ( $data ) Set the grid data.
setTemplate ( $template ) Set the grid template.
setTitle ( $title ) Set the grid title.
setUrls ( $request, $extraUrls = [] ) Define the urls that will be used in JS handler.

Protected Methods

Method Description
callFeaturesHook ( $hookName, $args ) Call the passed hook in all attached features.
doSpecificFetchGridActions ( $args, $request, $templateMgr ) Override this method if your subclass needs to perform different actions than the ones implemented here.
getDataElementFromRequest ( $request, &$elementId ) : object Create a data element from a request. This is used to format new rows prior to their insertion or existing rows that have been edited but not saved.
getFilterForm ( ) : Form | string Returns a Form object or the path name of a filter template.
getFilterSelectionData ( $request ) : array Method that extracts the user's filter selection from the request either by instantiating the filter's Form object or by reading the request directly (if using a simple filter template only).
getRowDataElement ( $request, &$rowId ) : mixed Retrieve a single data element from the grid's data source corresponding to the given row id. If none is found then return null.
getRowInstance ( ) : GridRow Get a new instance of a grid row. May be overridden by subclasses if they want to provide a custom row definition.
getRowsSequence ( $request ) : array Return the sequence map of the current loaded grid items.
initFeatures ( $request, &$args ) : array Override to init grid features.
isFilterFormCollapsible ( ) : boolean Determine whether a filter form should be collapsible.
loadData ( $request, $filter ) : grid Implement this method to load data into the grid.
noAutocompleteResults ( ) : JSONMessage Returns a common 'no matches' result when subclasses find no results for AJAX autocomplete requests.
renderFilter ( $request, $filterData = [] ) : string Render the filter (a template or a Form).
renderGridBodyPartsInternally ( Request $request ) : array Method that renders tbodys to go in the grid main body.
renderRowInternally ( $request, $row ) : string Method that renders a single row.
renderRowsInternally ( $request, &$elements ) : array Cycle through the data and get generate the row HTML.
setFirstDataColumn ( ) Define the first column that will contain grid data.

Private Methods

Method Description
_addFeatures ( $features ) Add grid features.
_fixColumnWidths ( ) Method that grabs all the existing columns and makes sure the column widths add to exactly 100 N.B. We do some extra column fetching because PHP makes copies of arrays with foreach.
_getInitializedRowInstance ( $request, $elementId, &$element, $isModified = false ) : GridRow Instantiate a new row.
_renderCellInternally ( $request, $row, $column ) : string Method that renders a cell.

Method Details

__construct() public method

Constructor.
public __construct ( $dataProvider = null )
$dataProvider GridDataProvider An optional data provider for the grid. If no data provider is given then the grid assumes that child classes will override default method implementations.

addAction() public method

Add an action.
public addAction ( $action, $position = GRID_ACTION_POSITION_ABOVE )
$action Mixed a single action.
$position string The position of the action.

addColumn() public method

Add a column.
public addColumn ( $column )
$column mixed A single GridColumn instance.

authorize() public method

public authorize ( $request, &$args, $roleAssignments, $enforceRestrictedSite = true )

callFeaturesHook() protected method

Call the passed hook in all attached features.
protected callFeaturesHook ( $hookName, $args )
$hookName string
$args array Arguments provided by this handler.

doSpecificFetchGridActions() protected method

This method is called by GridHandler::fetchGrid()
protected doSpecificFetchGridActions ( $args, $request, $templateMgr )
$args array
$request Request

fetchCell() public method

Render a cell and send it to the client
public fetchCell ( &$args, $request ) : JSONMessage
$args array
$request Request
return JSONMessage JSON object

fetchGrid() public method

Render the entire grid controller and send it to the client.
public fetchGrid ( $args, $request ) : JSONMessage
$args array
$request Request
return JSONMessage JSON object

fetchRow() public method

Render a row and send it to the client. If the row no longer exists then inform the client.
public fetchRow ( &$args, $request ) : JSONMessage
$args array
$request Request
return JSONMessage JSON object.

fetchRows() public method

Fetch all grid rows from loaded data.
public fetchRows ( $args, $request ) : JSONMessage
$args Array
$request Request
return JSONMessage JSON object.

getActions() public method

Get all actions for a given position within the grid.
public getActions ( $position = GRID_ACTION_POSITION_ABOVE ) : array
$position string The position of the actions.
return array The LinkActions for the given position.

getColumn() public method

Retrieve a single column by id.
public getColumn ( $columnId ) : GridColumn
$columnId
return GridColumn

getColumns() public method

Get all columns.
public getColumns ( ) : array
return array An array of GridColumn instances.

getColumnsByFlag() public method

Get columns by flag.
public getColumnsByFlag ( $flag ) : array
$flag string
return array

getColumnsCount() public method

Get columns number. If a flag is passed, the columns using it will not be counted.
public getColumnsCount ( $flag = null ) : integer
$flag optional string
return integer

getDataElementFromRequest() protected method

Create a data element from a request. This is used to format new rows prior to their insertion or existing rows that have been edited but not saved.
protected getDataElementFromRequest ( $request, &$elementId ) : object
$request PKPRequest
$elementId int Reference to be filled with element ID (if one is to be used)
return object

getDataElementSequence() public method

Override to return the data element sequence value.
public getDataElementSequence ( &$gridDataElement ) : integer
$gridDataElement mixed
return integer

getDataProvider() public method

Get the data provider.
public getDataProvider ( ) : FilesGridDataProvider
return FilesGridDataProvider

getEmptyRowText() public method

Get the no items locale key
public getEmptyRowText ( )

getFeatures() public method

Get all grid attached features.
public getFeatures ( ) : array
return array

getFilterForm() protected method

Returns a Form object or the path name of a filter template.
protected getFilterForm ( ) : Form | string
return Form | string

getFilterSelectionData() protected method

Method that extracts the user's filter selection from the request either by instantiating the filter's Form object or by reading the request directly (if using a simple filter template only).
protected getFilterSelectionData ( $request ) : array
$request PKPRequest
return array

getFootNote() public method

Get the grid foot note.
public getFootNote ( ) : string
return string locale key

getGridDataElements() public method

Get the grid data.
public getGridDataElements ( $request ) : array
$request PKPRequest
return array

getGridRangeInfo() public method

Get grid range info.
public getGridRangeInfo ( $request, $rangeName, $contextData = null ) : DBResultRange
$request PKPRequest
$rangeName string The grid id.
$contextData mixed
return DBResultRange

getIsSubcomponent() public method

Override this method to return true if you want to use the grid within another component (e.g. to remove the title or change the layout accordingly).
public getIsSubcomponent ( ) : boolean
return boolean

getItemIterator() public method

Should only be used for retriving paging data. See #6498.
public getItemIterator ( ) : ItemIterator
return ItemIterator

getJSHandler() public method

Get the js handler for this component.
public getJSHandler ( ) : string
return string

getPublishChangeEvents() public method

Get "publish data changed" event list.
public getPublishChangeEvents ( ) : array
return array

getRequestArg() public method

Get a single grid request parameter.
See also: getRequestArgs()
public getRequestArg ( $key ) : mixed
$key string The name of the parameter to retrieve.
return mixed

getRequestArgs() public method

NB: You should make sure to authorize and/or validate parameters before you publish them through this interface. Callers will assume that data accessed through this method will not have to be sanitized. The default implementation tries to retrieve request parameters from a data provider if there is one.
public getRequestArgs ( ) : array
return array

getRequestedRow() public method

Raises a fatal error if such an element cannot be found.
public getRequestedRow ( $request, $args ) : GridRow
$request PKPRequest
$args array
return GridRow the requested grid row, already configured with id and data or null if the row could not been found.

getRowDataElement() protected method

Retrieve a single data element from the grid's data source corresponding to the given row id. If none is found then return null.
protected getRowDataElement ( $request, &$rowId ) : mixed
$rowId string The row ID; reference permits modification.
return mixed

getRowInstance() protected method

Get a new instance of a grid row. May be overridden by subclasses if they want to provide a custom row definition.
protected getRowInstance ( ) : GridRow
return GridRow

getRowsSequence() protected method

This is not the sequence value of the data represented by the row, it's just the mapping of the rows sequence, in the order that they are loaded. To handle grid items ordering, see OrderItemsFeature class.
protected getRowsSequence ( $request ) : array
$request PKPRequest
return array

getSelectName() public method

Get the select parameter name to store the selected files.
public getSelectName ( ) : string
return string

getTemplate() public method

Get the grid template.
public getTemplate ( ) : string
return string

getTitle() public method

Get the grid title.
public getTitle ( ) : string
return string locale key

getUrls() public method

Return all grid urls that will be used in JS handler.
public getUrls ( ) : array
return array

hasColumn() public method

Checks whether a column exists.
public hasColumn ( $columnId ) : boolean
$columnId
return boolean

hasGridDataElements() public method

Check whether the grid has rows.
public hasGridDataElements ( $request ) : boolean
return boolean

initFeatures() protected method

This method is called by GridHandler::initialize() method that use the returned array with the initialized features to add them to grid.
protected initFeatures ( $request, &$args ) : array
$request Request
$args array
return array Array with initialized grid features objects.

initialize() public method

See also: PKPHandler::initialize()
public initialize ( $request, $args = null )
$request PKPRequest
$args array optional

isDataElementSelected() public method

Returns the current selection state of the grid data element.
public isDataElementSelected ( $gridDataElement ) : boolean
$gridDataElement mixed
return boolean

isFilterFormCollapsible() protected method

Determine whether a filter form should be collapsible.
protected isFilterFormCollapsible ( ) : boolean
return boolean

loadData() protected method

Implement this method to load data into the grid.
protected loadData ( $request, $filter ) : grid
$request Request
$filter array An associative array with filter data as returned by getFilterSelectionData(). If no filter has been selected by the user then the array will be empty.
return grid data

noAutocompleteResults() protected method

Returns a common 'no matches' result when subclasses find no results for AJAX autocomplete requests.
protected noAutocompleteResults ( ) : JSONMessage
return JSONMessage JSON object

renderFilter() protected method

Render the filter (a template or a Form).
protected renderFilter ( $request, $filterData = [] ) : string
$request PKPRequest
$filterData Array Data to be used by the filter template.
return string

renderGridBodyPartsInternally() protected method

Method that renders tbodys to go in the grid main body.
protected renderGridBodyPartsInternally ( Request $request ) : array
$request Request
return array

renderRow() public method

Render the passed row and return its markup.
public renderRow ( $request, $row ) : string
$request PKPRequest
$row GridRow
return string

renderRowInternally() protected method

NB: You must have initialized the row before you call this method.
protected renderRowInternally ( $request, $row ) : string
$request PKPRequest
$row GridRow
return string the row HTML

renderRowsInternally() protected method

Cycle through the data and get generate the row HTML.
protected renderRowsInternally ( $request, &$elements ) : array
$request PKPRequest
$elements array The grid data elements to be rendered.
return array of HTML Strings for Grid Rows.

saveSequence() public method

Hook oportunity for grid features to request a save items sequence operation. If no grid feature that implements the saveSequence hook is attached to this grid, this operation will only return the data changed event json message.
public saveSequence ( $args, $request ) : JSONMessage
$args array
$request Request
return JSONMessage JSON object

setDataElementSequence() public method

Override to set the data element new sequence.
public setDataElementSequence ( $request, $rowId, &$gridDataElement, $newSequence )
$request PKPRequest
$rowId int
$gridDataElement mixed
$newSequence int

setEmptyRowText() public method

Set the no items locale key
public setEmptyRowText ( $emptyRowText )

setFirstDataColumn() protected method

Override this method to define a different column than the first one.
protected setFirstDataColumn ( )

setFootNote() public method

Set the grid foot note.
public setFootNote ( $footNote )
$footNote string locale key

setGridDataElements() public method

Set the grid data.
public setGridDataElements ( $data )
$data mixed an array or ItemIterator with element data

setTemplate() public method

Set the grid template.
public setTemplate ( $template )
$template string

setTitle() public method

Set the grid title.
public setTitle ( $title )
$title string locale key

setUrls() public method

Define the urls that will be used in JS handler.
public setUrls ( $request, $extraUrls = [] )
$request Request
$extraUrls array Optional extra urls.

Property Details

$_actions public_oe property

Grid actions. The first key represents the position of the action in the grid, the second key represents the action id.
public $_actions

$_columns public_oe property

The GridColumns of this grid.
public $_columns

$_data public_oe property

The grid's data source.
public $_data

$_dataProvider public_oe property

public GridDataProvider $_dataProvider
return GridDataProvider

$_emptyRowText public_oe property

empty row locale key
public $_emptyRowText

$_features public_oe property

The grid features.
public $_features

$_footNote public_oe property

Grid foot note locale key
public $_footNote

$_itemIterator public_oe property

The item iterator to be used for paging.
public $_itemIterator

$_template public_oe property

The grid template.
public $_template

$_title public_oe property

grid title locale key
public $_title

$_urls public_oe property

The urls that will be used in JS handler.
public $_urls