-
Notifications
You must be signed in to change notification settings - Fork 4
/
ListView.php
57 lines (51 loc) · 1.81 KB
/
ListView.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
namespace nkovacs\pagesizer;
use yii\helpers\ArrayHelper;
class ListView extends \yii\widgets\ListView
{
/**
* @var array the configuration for the page sizer widget. By default, [[LinkPageSizer]] will be
* used to render the page sizer. You can use a different widget class by configuring the "class" element.
*/
public $pageSizer = [];
/**
* @var string the layout that determines how different sections of the list view should be organized.
* The following tokens will be replaced with the corresponding section contents:
*
* - `{summary}`: the summary section. See [[renderSummary()]].
* - `{items}`: the list items. See [[renderItems()]].
* - `{sorter}`: the sorter. See [[renderSorter()]].
* - `{pager}`: the pager. See [[renderPager()]].
* - `{pagesizer}`: the page sizer. See [[renderPagesizer()]].
*/
public $layout = "{summary}\n{items}\n{pager}\n{pagesizer}";
/**
* @inheritdoc
*/
public function renderSection($name)
{
switch ($name) {
case "{pagesizer}":
return $this->renderPagesizer();
default:
return parent::renderSection($name);
}
}
/**
* Renders the page sizer.
* @return string the rendering result
*/
public function renderPagesizer()
{
$pagination = $this->dataProvider->getPagination();
if ($pagination === false || $this->dataProvider->getCount() <= 0) {
return '';
}
/* @var $class LinkPageSizer */
$pageSizer = $this->pageSizer;
$class = ArrayHelper::remove($pageSizer, 'class', LinkPageSizer::className());
$pageSizer['pagination'] = $pagination;
$pageSizer['view'] = $this->getView();
return $class::widget($pageSizer);
}
}