MINOR Updated docblocks for GridFieldPaginator

This commit is contained in:
Stig Lindqvist 2012-01-23 18:19:27 +01:00
parent ed889529b4
commit 07029138bf
1 changed files with 50 additions and 17 deletions

67
forms/gridfield/GridFieldPaginator.php Normal file → Executable file
View File

@ -1,35 +1,57 @@
<?php
/**
* GridFieldPaginator decorates the GridFieldPresenter with the possibility to
* paginate the GridField.
*
* @see GridField
* GridFieldPaginator paginates the gridfields list and adds controlls to the
* bottom of the gridfield.
*
* @package sapphire
* @subpackage fields-relational
*/
class GridFieldPaginator implements GridField_HTMLProvider, GridField_DataManipulator, GridField_ActionProvider {
/**
*
* @var int
*/
protected $currentPage = 1;
/**
*
* @var int
*/
protected $itemsPerPage = 25;
/**
* Which template to use for rendering
*
* @var string $itemClass
* @var string
*/
protected $itemClass = 'GridFieldPaginator_Row';
/**
*
* @param int $itemsPerPage - How many items should be displayed per page
*/
public function __construct($itemsPerPage=25) {
$this->itemsPerPage = $itemsPerPage;
}
/**
*
* @param GridField $gridField
* @return array
*/
public function getActions($gridField) {
return array('paginate');
}
/**
*
* @param GridField $gridField
* @param string $actionName
* @param string $arguments
* @param array $data
* @return void
*/
public function handleAction(GridField $gridField, $actionName, $arguments, $data) {
if($actionName !== 'paginate') {
return;
@ -38,17 +60,12 @@ class GridFieldPaginator implements GridField_HTMLProvider, GridField_DataManipu
$this->currentPage = $state->currentPage = (int)$arguments;
}
/** Duck check to see if list support methods we need to paginate */
protected function getListPaginatable(SS_List $list) {
// If no list yet, not paginatable
if (!$list) return false;
// Check for methods we use
if(!method_exists($list, 'getRange')) return false;
if(!method_exists($list, 'limit')) return false;
// Default it true
return true;
}
/**
*
* @param GridField $gridField
* @param SS_List $dataList
* @return SS_List
*/
public function getManipulatedData(GridField $gridField, SS_List $dataList) {
if(!$this->getListPaginatable($dataList)) {
return $dataList;
@ -60,6 +77,11 @@ class GridFieldPaginator implements GridField_HTMLProvider, GridField_DataManipu
return $dataList->getRange((int)$startRow, (int)$this->itemsPerPage);
}
/**
*
* @param GridField $gridField
* @return array
*/
public function getHTMLFragments($gridField) {
Requirements::javascript(SAPPHIRE_DIR.'/thirdparty/jquery-entwine/dist/jquery.entwine-dist.js');
Requirements::javascript(SAPPHIRE_DIR.'/javascript/GridField.js');
@ -87,4 +109,15 @@ class GridFieldPaginator implements GridField_HTMLProvider, GridField_DataManipu
'footer' => $forTemplate->renderWith('GridFieldPaginator_Row', array('Colspan'=>count($gridField->getColumns()))),
);
}
/** Duck check to see if list support methods we need to paginate */
protected function getListPaginatable(SS_List $list) {
// If no list yet, not paginatable
if (!$list) return false;
// Check for methods we use
if(!method_exists($list, 'getRange')) return false;
if(!method_exists($list, 'limit')) return false;
// Default it true
return true;
}
}