Skip to content

Commit

Permalink
pkp#1923: Refactor GridCellProvider::__construct() to store an initia…
Browse files Browse the repository at this point in the history
…l PKPRequest object, then use this request object for other methods rather than passing it as a parameter
  • Loading branch information
ctgraham committed Feb 22, 2017
1 parent 6f107f9 commit 64e090d
Show file tree
Hide file tree
Showing 82 changed files with 170 additions and 421 deletions.
12 changes: 1 addition & 11 deletions classes/controllers/grid/ArrayGridCellProvider.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,13 @@
import('lib.pkp.classes.controllers.grid.GridCellProvider');

class ArrayGridCellProvider extends GridCellProvider {
/**
* Constructor
*/
function __construct() {
parent::__construct();
}

//
// Template methods from GridCellProvider
//
/**
* This implementation assumes a simple data element array that
* has column ids as keys.
* @see GridCellProvider::getTemplateVarsFromRowColumn()
* @param $row GridRow
* @param $column GridColumn
* @return array
* @copydoc GridCellProvider::getTemplateVarsFromRowColumn()
*/
function getTemplateVarsFromRowColumn($row, $column) {
$element =& $row->getData();
Expand Down
4 changes: 3 additions & 1 deletion classes/controllers/grid/CategoryGridHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ function __construct($dataProvider = null) {
parent::__construct($dataProvider);

import('lib.pkp.classes.controllers.grid.NullGridCellProvider');
// TODO: Where should the request come from?
$request = PKPApplication::getRequest();
$this->addColumn(new GridColumn('indent', null, null, null,
new NullGridCellProvider(), array('indent' => true, 'width' => 2)));
new NullGridCellProvider($request), array('indent' => true, 'width' => 2)));
}


Expand Down
10 changes: 1 addition & 9 deletions classes/controllers/grid/ColumnBasedGridCellProvider.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,11 @@
import('lib.pkp.classes.controllers.grid.GridCellProvider');

class ColumnBasedGridCellProvider extends GridCellProvider {
/**
* Constructor
*/
function __construct() {
parent::__construct();
}


//
// Implement protected template methods from GridCellProvider
//
/**
* @see GridCellProvider::getTemplateVarsFromRowColumn()
* @copydoc GridCellProvider::getTemplateVarsFromRowColumn()
*/
function getTemplateVarsFromRowColumn($row, $column) {
// Delegate to the column to provide template variables.
Expand Down
12 changes: 1 addition & 11 deletions classes/controllers/grid/DataObjectGridCellProvider.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@ class DataObjectGridCellProvider extends GridCellProvider {
/** @var string the locale to be retrieved. */
var $_locale = null;

/**
* Constructor
*/
function __construct() {
parent::__construct();
}

//
// Setters and Getters
//
Expand Down Expand Up @@ -57,10 +50,7 @@ function getLocale() {
* This implementation assumes an element that is a
* DataObject. It will retrieve an element in the
* configured locale.
* @see GridCellProvider::getTemplateVarsFromRowColumn()
* @param $row GridRow
* @param $column GridColumn
* @return array
* @copydoc GridCellProvider::getTemplateVarsFromRowColumn()
*/
function getTemplateVarsFromRowColumn($row, $column) {
$element = $row->getData();
Expand Down
9 changes: 4 additions & 5 deletions classes/controllers/grid/DateGridCellProvider.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ class DateGridCellProvider extends GridCellProvider {

/**
* Constructor
* @param $request PKPRequest
* @param $dataProvider DataProvider The object to wrap
* @param $format string See strftime
*/
function __construct($dataProvider, $format) {
parent::__construct();
function __construct($request, $dataProvider, $format) {
parent::__construct($request);
$this->_dataProvider = $dataProvider;
$this->_format = $format;
}
Expand All @@ -39,9 +40,7 @@ function __construct($dataProvider, $format) {
/**
* Fetch a value from the provided DataProvider (in constructor)
* and format it as a date.
* @param $row GridRow
* @param $column GridColumn
* @return array
* @copydoc GridCellProvider::getTemplateVarsFromRowColumn()
*/
function getTemplateVarsFromRowColumn($row, $column) {
$v = $this->_dataProvider->getTemplateVarsFromRowColumn($row, $column);
Expand Down
7 changes: 0 additions & 7 deletions classes/controllers/grid/GridCategoryRowCellProvider.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@
import('lib.pkp.classes.controllers.grid.GridCellProvider');

class GridCategoryRowCellProvider extends GridCellProvider {
/**
* Constructor
*/
function __construct() {
parent::__construct();
}

//
// Implemented methods from GridCellProvider.
//
Expand Down
19 changes: 12 additions & 7 deletions classes/controllers/grid/GridCellProvider.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@


class GridCellProvider {

/** @var PKPRequest the requesting context for this provider */
var $_request;

/**
* Constructor
* @param $request PKPRequest
*/
function __construct() {
function __construct($request) {
$this->_request = $request;
}

//
Expand All @@ -36,7 +42,7 @@ function __construct() {
* @param $column GridColumn
* @return string the rendered representation of the element for the given column
*/
function render($request, $row, $column) {
function render($row, $column) {
$columnId = $column->getId();
assert(!empty($columnId));

Expand All @@ -45,15 +51,15 @@ function render($request, $row, $column) {
$cellId = isset($rowId)?$rowId.'-'.$columnId:null;

// Assign values extracted from the element for the cell.
$templateMgr = TemplateManager::getManager($request);
$templateMgr = TemplateManager::getManager($this->_request);
$templateVars = $this->getTemplateVarsFromRowColumn($row, $column);
foreach ($templateVars as $varName => $varValue) {
$templateMgr->assign($varName, $varValue);
}
$templateMgr->assign(array(
'id' => $cellId,
'column' => $column,
'actions' => $this->getCellActions($request, $row, $column),
'actions' => $this->getCellActions($this->_request, $row, $column),
'flags' => $column->getFlags(),
'formLocales' => AppLocale::getSupportedFormLocales(),
));
Expand Down Expand Up @@ -86,14 +92,13 @@ function getTemplateVarsFromRowColumn($row, $column) {
* be row-specific actions in which case action instantiation
* should be delegated to the row.
*
* @param $request Request
* @param $row GridRow
* @param $column GridColumn
* @param $position int GRID_ACTION_POSITION_...
* @return array an array of LinkAction instances
*/
function getCellActions($request, $row, $column, $position = GRID_ACTION_POSITION_DEFAULT) {
return $column->getCellActions($request, $row, $position);
function getCellActions($row, $column, $position = GRID_ACTION_POSITION_DEFAULT) {
return $column->getCellActions($this->_request, $row, $position);
}
}

Expand Down
4 changes: 3 additions & 1 deletion classes/controllers/grid/GridColumn.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ function &getCellProvider() {
if (is_null(parent::getCellProvider())) {
// provide a sensible default cell provider
import('lib.pkp.classes.controllers.grid.ArrayGridCellProvider');
$cellProvider = new ArrayGridCellProvider();
// TODO: Where should the request come from?
$request = PKPApplication::getRequest();
$cellProvider = new ArrayGridCellProvider($request);
$this->setCellProvider($cellProvider);
}

Expand Down
2 changes: 1 addition & 1 deletion classes/controllers/grid/GridHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,7 @@ private function _renderCellInternally($request, $row, $column) {
$element =& $row->getData();
if ( is_null($element) && $row->getIsModified() ) {
import('lib.pkp.classes.controllers.grid.GridCellProvider');
$cellProvider = new GridCellProvider();
$cellProvider = new GridCellProvider($request);
return $cellProvider->render($request, $row, $column);
}

Expand Down
12 changes: 1 addition & 11 deletions classes/controllers/grid/LiteralGridCellProvider.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,13 @@
import('lib.pkp.classes.controllers.grid.GridCellProvider');

class LiteralGridCellProvider extends GridCellProvider {
/**
* Constructor
*/
function __construct() {
parent::__construct();
}

//
// Template methods from GridCellProvider
//
/**
* This implementation assumes a data element that is a literal value.
* If desired, the 'id' column can be used to present the row ID.
* @see GridCellProvider::getTemplateVarsFromRowColumn()
* @param $row GridRow
* @param $column GridColumn
* @return array
* @copydoc GridCellProvider::getTemplateVarsFromRowColumn()
*/
function getTemplateVarsFromRowColumn($row, $column) {
switch ($column->getId()) {
Expand Down
12 changes: 1 addition & 11 deletions classes/controllers/grid/MapGridCellProvider.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,13 @@
import('lib.pkp.classes.controllers.grid.GridCellProvider');

class MapGridCellProvider extends GridCellProvider {
/**
* Constructor
*/
function __construct() {
parent::__construct();
}

//
// Template methods from GridCellProvider
//
/**
* This implementation assumes a simple data element array that
* has column ids as keys.
* @see GridCellProvider::getTemplateVarsFromRowColumn()
* @param $row GridRow
* @param $column GridColumn
* @return array
* @copydoc GridCellProvider::getTemplateVarsFromRowColumn()
*/
function getTemplateVarsFromRowColumn($row, $column) {
$element =& $row->getData();
Expand Down
9 changes: 1 addition & 8 deletions classes/controllers/grid/NullGridCellProvider.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,13 @@
import('lib.pkp.classes.controllers.grid.GridCellProvider');

class NullGridCellProvider extends GridCellProvider {
/**
* Constructor
*/
function __construct() {
parent::__construct();
}

//
// Template methods from GridCellProvider
//
/**
* @see GridCellProvider::render()
*/
function render($request, $row, $column) {
function render($row, $column) {
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ function __construct($selectName) {
$this->_selectName = $selectName;

import('lib.pkp.classes.controllers.grid.ColumnBasedGridCellProvider');
$cellProvider = new ColumnBasedGridCellProvider();
// TODO: Where should the request come from?
$request = PKPApplication::getRequest();
$cellProvider = new ColumnBasedGridCellProvider($request);
parent::__construct('select', 'common.select', null, 'controllers/grid/gridRowSelectInput.tpl', $cellProvider,
array('width' => 3));
}
Expand Down
12 changes: 1 addition & 11 deletions classes/controllers/grid/filter/FilterGridCellProvider.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,14 @@
import('lib.pkp.classes.controllers.grid.GridCellProvider');

class FilterGridCellProvider extends GridCellProvider {
/**
* Constructor
*/
function __construct() {
parent::__construct();
}

//
// Template methods from GridCellProvider
//
/**
* This implementation assumes an element that is a
* Filter. It will display the filter name and information
* about filter parameters (if any).
* @see GridCellProvider::getTemplateVarsFromRowColumn()
* @param $row GridRow
* @param $column GridColumn
* @return array
* @copydoc GridCellProvider::getTemplateVarsFromRowColumn()
*/
function getTemplateVarsFromRowColumn($row, $column) {
$filter =& $row->getData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ function initialize($request) {
);

// Columns
$cellProvider = new FilterGridCellProvider();
$cellProvider = new FilterGridCellProvider($request);
$this->addColumn(
new GridColumn(
'displayName',
Expand Down
2 changes: 1 addition & 1 deletion classes/controllers/grid/plugins/PluginGridHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function initialize($request) {

// Columns
import('lib.pkp.controllers.grid.plugins.PluginGridCellProvider');
$pluginCellProvider = new PluginGridCellProvider();
$pluginCellProvider = new PluginGridCellProvider($request);
$this->addColumn(
new GridColumn('name',
'common.name',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ function initialize($request) {
);

// Columns
$cellProvider = new ReviewerGridCellProvider();
$cellProvider = new ReviewerGridCellProvider($request);
$this->addColumn(
new GridColumn(
'name',
Expand Down
13 changes: 1 addition & 12 deletions controllers/grid/admin/context/ContextGridCellProvider.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,7 @@

class ContextGridCellProvider extends GridCellProvider {
/**
* Constructor
*/
function __construct() {
parent::__construct();
}

/**
* Extracts variables for a given column from a data element
* so that they may be assigned to template before rendering.
* @param $row GridRow
* @param $column GridColumn
* @return array
* @copydoc GridCellProvider::getTemplateVarsFromRowColumn()
*/
function getTemplateVarsFromRowColumn($row, $column) {
$element = $row->getData();
Expand Down
2 changes: 1 addition & 1 deletion controllers/grid/admin/context/ContextGridHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function initialize($request) {
// Grid columns.
//
import('lib.pkp.controllers.grid.admin.context.ContextGridCellProvider');
$contextGridCellProvider = new ContextGridCellProvider();
$contextGridCellProvider = new ContextGridCellProvider($request);

// Context name.
$this->addColumn(
Expand Down
12 changes: 5 additions & 7 deletions controllers/grid/admin/systemInfo/InfoGridCellProvider.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,16 @@ class InfoGridCellProvider extends GridCellProvider {

/**
* Constructor
* @param $request PKPRequest
* @param $translate boolean
*/
function __construct($translate = false) {
parent::__construct();
function __construct($request, $translate = false) {
parent::__construct($request);
$this->_translate = $translate;
}

/**
* Extracts variables for a given column from a data element
* so that they may be assigned to template before rendering.
* @param $row GridRow
* @param $column GridColumn
* @return array
* @copydoc GridCellProvider::getTemplateVarsFromRowColumn()
*/
function getTemplateVarsFromRowColumn($row, $column) {
$element = $row->getData();
Expand Down
Loading

0 comments on commit 64e090d

Please sign in to comment.