1 | <?php |
||
15 | class TableRenderer { |
||
16 | |||
17 | /** @var Request */ |
||
18 | private $_request; |
||
19 | |||
20 | /** |
||
21 | * TableRenderer constructor. |
||
22 | * @param Request $request |
||
23 | */ |
||
24 | 29 | public function __construct(Request $request) |
|
28 | |||
29 | /** |
||
30 | * Starts the table. |
||
31 | * |
||
32 | * @param null|string $classes |
||
33 | * @return string |
||
34 | */ |
||
35 | 29 | public function open(?string $classes = null) : string |
|
39 | |||
40 | /** |
||
41 | * Closes the table. |
||
42 | * |
||
43 | * @return string |
||
44 | */ |
||
45 | 29 | public function close() : string |
|
49 | |||
50 | /** |
||
51 | * Renders the column headers. |
||
52 | * |
||
53 | * @param array $headers |
||
54 | * @param array $formatters |
||
55 | * @return string |
||
56 | */ |
||
57 | 29 | public function renderHeaders(array $headers, array $formatters = []) : string |
|
70 | |||
71 | /** |
||
72 | * Displays the table body. |
||
73 | * |
||
74 | * @param Collection $data |
||
75 | * |
||
76 | * @param array $columns |
||
77 | * @return string |
||
78 | */ |
||
79 | 29 | public function renderBody(Collection $data, array $columns = []) : string |
|
89 | |||
90 | /** |
||
91 | * Displays a single row. |
||
92 | * |
||
93 | * @param Model $rowModel |
||
94 | * |
||
95 | * @param array $columns |
||
96 | * @return string |
||
97 | */ |
||
98 | 29 | private function _renderRow(Model $rowModel, array $columns) : string |
|
112 | |||
113 | /** |
||
114 | * Get all the mutated attributes which are needed. |
||
115 | * |
||
116 | * @param Model $model |
||
117 | * @param array $columns |
||
118 | * @return array |
||
119 | */ |
||
120 | 29 | private function _getMutatedAttributes(Model $model, array $columns = []) : array |
|
130 | |||
131 | /** |
||
132 | * Get all column names. |
||
133 | * |
||
134 | * @param array $columns |
||
135 | * @return array |
||
136 | */ |
||
137 | 29 | private function _getColumnNames(array $columns) : array |
|
147 | |||
148 | /** |
||
149 | * Get only the columns which are attributes from the base model. |
||
150 | * |
||
151 | * @param array $columns |
||
152 | * @return array |
||
153 | */ |
||
154 | 29 | private function _getColumnsWithoutRelations(array $columns) : array |
|
165 | |||
166 | /** |
||
167 | * @param Model $model |
||
168 | * @param Column $column |
||
169 | * @return string |
||
170 | */ |
||
171 | 3 | private function _getColumnValueFromRelation(Model $model, Column $column) : string |
|
183 | } |