2012-04-12 06:13:47 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2014-08-15 08:53:05 +02:00
|
|
|
* Adding this class to a {@link GridFieldConfig} of a {@link GridField} adds
|
2013-05-20 12:18:07 +02:00
|
|
|
* a footer bar to that field.
|
2012-04-12 06:13:47 +02:00
|
|
|
*
|
2014-08-15 08:53:05 +02:00
|
|
|
* The footer looks just like the {@link GridFieldPaginator} control, except
|
2013-05-20 12:18:07 +02:00
|
|
|
* without the pagination controls.
|
|
|
|
*
|
2014-08-15 08:53:05 +02:00
|
|
|
* It only display the "Viewing 1-8 of 8" status text and (optionally) a
|
2013-05-20 12:18:07 +02:00
|
|
|
* configurable status message.
|
|
|
|
*
|
2014-08-15 08:53:05 +02:00
|
|
|
* The purpose of this class is to have a footer that can round off
|
2013-05-20 12:18:07 +02:00
|
|
|
* {@link GridField} without having to use pagination.
|
2012-04-12 06:13:47 +02:00
|
|
|
*
|
2013-11-29 05:12:47 +01:00
|
|
|
* @package forms
|
2013-05-20 12:18:07 +02:00
|
|
|
* @subpackage fields-gridfield
|
2012-04-12 06:13:47 +02:00
|
|
|
*/
|
|
|
|
class GridFieldFooter implements GridField_HTMLProvider {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string - a message to display in the footer
|
|
|
|
*/
|
|
|
|
protected $message = null;
|
2014-11-13 01:48:02 +01:00
|
|
|
protected $showrecordcount;
|
2012-04-12 06:13:47 +02:00
|
|
|
|
|
|
|
/**
|
2018-04-11 10:12:38 +02:00
|
|
|
* @param string $message A message to display in the footer
|
|
|
|
* @param boolean $showrecordcount
|
2012-04-12 06:13:47 +02:00
|
|
|
*/
|
2014-11-13 01:48:02 +01:00
|
|
|
public function __construct($message = null, $showrecordcount = true) {
|
2013-05-20 12:18:07 +02:00
|
|
|
if($message) {
|
|
|
|
$this->message = $message;
|
|
|
|
}
|
2014-11-13 01:48:02 +01:00
|
|
|
$this->showrecordcount = $showrecordcount;
|
2012-04-12 06:13:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function getHTMLFragments($gridField) {
|
|
|
|
$count = $gridField->getList()->count();
|
|
|
|
|
|
|
|
$forTemplate = new ArrayData(array(
|
2014-11-13 01:48:02 +01:00
|
|
|
'ShowRecordCount' => $this->showrecordcount,
|
2012-04-12 06:13:47 +02:00
|
|
|
'Message' => $this->message,
|
|
|
|
'FirstShownRecord' => 1,
|
|
|
|
'LastShownRecord' => $count,
|
|
|
|
'NumRecords' => $count
|
|
|
|
));
|
|
|
|
|
|
|
|
return array(
|
2013-05-20 12:18:07 +02:00
|
|
|
'footer' => $forTemplate->renderWith(
|
2014-08-15 08:53:05 +02:00
|
|
|
'GridFieldFooter',
|
2013-05-20 12:18:07 +02:00
|
|
|
array(
|
|
|
|
'Colspan' => count($gridField->getColumns())
|
|
|
|
)
|
|
|
|
)
|
2012-04-12 06:13:47 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|