1 | <?php |
||
27 | abstract class BaseListView extends Widget |
||
28 | { |
||
29 | /** |
||
30 | * @var array the HTML attributes for the container tag of the list view. |
||
31 | * The "tag" element specifies the tag name of the container element and defaults to "div". |
||
32 | * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. |
||
33 | */ |
||
34 | public $options = []; |
||
35 | /** |
||
36 | * @var \yii\data\DataProviderInterface the data provider for the view. This property is required. |
||
37 | */ |
||
38 | public $dataProvider; |
||
39 | /** |
||
40 | * @var array the configuration for the pager widget. By default, [[LinkPager]] will be |
||
41 | * used to render the pager. You can use a different widget class by configuring the "class" element. |
||
42 | * Note that the widget must support the `pagination` property which will be populated with the |
||
43 | * [[\yii\data\BaseDataProvider::pagination|pagination]] value of the [[dataProvider]]. |
||
44 | */ |
||
45 | public $pager = []; |
||
46 | /** |
||
47 | * @var array the configuration for the sorter widget. By default, [[LinkSorter]] will be |
||
48 | * used to render the sorter. You can use a different widget class by configuring the "class" element. |
||
49 | * Note that the widget must support the `sort` property which will be populated with the |
||
50 | * [[\yii\data\BaseDataProvider::sort|sort]] value of the [[dataProvider]]. |
||
51 | */ |
||
52 | public $sorter = []; |
||
53 | /** |
||
54 | * @var string the HTML content to be displayed as the summary of the list view. |
||
55 | * If you do not want to show the summary, you may set it with an empty string. |
||
56 | * |
||
57 | * The following tokens will be replaced with the corresponding values: |
||
58 | * |
||
59 | * - `{begin}`: the starting row number (1-based) currently being displayed |
||
60 | * - `{end}`: the ending row number (1-based) currently being displayed |
||
61 | * - `{count}`: the number of rows currently being displayed |
||
62 | * - `{totalCount}`: the total number of rows available |
||
63 | * - `{page}`: the page number (1-based) current being displayed |
||
64 | * - `{pageCount}`: the number of pages available |
||
65 | */ |
||
66 | public $summary; |
||
67 | /** |
||
68 | * @var array the HTML attributes for the summary of the list view. |
||
69 | * The "tag" element specifies the tag name of the summary element and defaults to "div". |
||
70 | * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. |
||
71 | */ |
||
72 | public $summaryOptions = ['class' => 'summary']; |
||
73 | /** |
||
74 | * @var bool whether to show an empty list view if [[dataProvider]] returns no data. |
||
75 | * The default value is false which displays an element according to the `emptyText` |
||
76 | * and `emptyTextOptions` properties. |
||
77 | */ |
||
78 | public $showOnEmpty = false; |
||
79 | /** |
||
80 | * @var string the HTML content to be displayed when [[dataProvider]] does not have any data. |
||
81 | */ |
||
82 | public $emptyText; |
||
83 | /** |
||
84 | * @var array the HTML attributes for the emptyText of the list view. |
||
85 | * The "tag" element specifies the tag name of the emptyText element and defaults to "div". |
||
86 | * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. |
||
87 | */ |
||
88 | public $emptyTextOptions = ['class' => 'empty']; |
||
89 | /** |
||
90 | * @var string the layout that determines how different sections of the list view should be organized. |
||
91 | * The following tokens will be replaced with the corresponding section contents: |
||
92 | * |
||
93 | * - `{summary}`: the summary section. See [[renderSummary()]]. |
||
94 | * - `{items}`: the list items. See [[renderItems()]]. |
||
95 | * - `{sorter}`: the sorter. See [[renderSorter()]]. |
||
96 | * - `{pager}`: the pager. See [[renderPager()]]. |
||
97 | */ |
||
98 | public $layout = "{summary}\n{items}\n{pager}"; |
||
99 | |||
100 | |||
101 | /** |
||
102 | * Renders the data models. |
||
103 | * @return string the rendering result. |
||
104 | */ |
||
105 | abstract public function renderItems(); |
||
106 | |||
107 | /** |
||
108 | * Initializes the view. |
||
109 | */ |
||
110 | 20 | public function init() |
|
122 | |||
123 | /** |
||
124 | * Runs the widget. |
||
125 | */ |
||
126 | 12 | public function run() |
|
142 | |||
143 | /** |
||
144 | * Renders a section of the specified name. |
||
145 | * If the named section is not supported, false will be returned. |
||
146 | * @param string $name the section name, e.g., `{summary}`, `{items}`. |
||
147 | * @return string|bool the rendering result of the section, or false if the named section is not supported. |
||
148 | */ |
||
149 | 11 | public function renderSection($name) |
|
164 | |||
165 | /** |
||
166 | * Renders the HTML content indicating that the list view has no data. |
||
167 | * @return string the rendering result |
||
168 | * @see emptyText |
||
169 | */ |
||
170 | 1 | public function renderEmpty() |
|
176 | |||
177 | /** |
||
178 | * Renders the summary text. |
||
179 | */ |
||
180 | 9 | public function renderSummary() |
|
231 | |||
232 | /** |
||
233 | * Renders the pager. |
||
234 | * @return string the rendering result |
||
235 | */ |
||
236 | 9 | public function renderPager() |
|
250 | |||
251 | /** |
||
252 | * Renders the sorter. |
||
253 | * @return string the rendering result |
||
254 | */ |
||
255 | 2 | public function renderSorter() |
|
269 | } |
||
270 |