Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like DataGrid often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use DataGrid, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
27 | class DataGrid extends Nette\Application\UI\Control |
||
28 | { |
||
29 | |||
30 | /** |
||
31 | * @var callable[] |
||
32 | */ |
||
33 | public $onRedraw; |
||
34 | |||
35 | /** |
||
36 | * @var callable[] |
||
37 | */ |
||
38 | public $onRender = []; |
||
39 | |||
40 | /** |
||
41 | * @var callable[] |
||
42 | */ |
||
43 | public $onColumnAdd; |
||
44 | |||
45 | /** |
||
46 | * @var string |
||
47 | */ |
||
48 | public static $icon_prefix = 'fa fa-'; |
||
49 | |||
50 | /** |
||
51 | * When set to TRUE, datagrid throws an exception |
||
52 | * when tring to get related entity within join and entity does not exist |
||
53 | * @var bool |
||
54 | */ |
||
55 | public $strict_entity_property = FALSE; |
||
56 | |||
57 | /** |
||
58 | * @var int |
||
59 | * @persistent |
||
60 | */ |
||
61 | public $page = 1; |
||
62 | |||
63 | /** |
||
64 | * @var int|string |
||
65 | * @persistent |
||
66 | */ |
||
67 | public $per_page; |
||
68 | |||
69 | /** |
||
70 | * @var array |
||
71 | * @persistent |
||
72 | */ |
||
73 | public $sort = []; |
||
74 | |||
75 | /** |
||
76 | * @var array |
||
77 | */ |
||
78 | public $default_sort = []; |
||
79 | |||
80 | /** |
||
81 | * @var array |
||
82 | */ |
||
83 | public $default_filter = []; |
||
84 | |||
85 | /** |
||
86 | * @var bool |
||
87 | */ |
||
88 | public $default_filter_use_on_reset = TRUE; |
||
89 | |||
90 | /** |
||
91 | * @var array |
||
92 | * @persistent |
||
93 | */ |
||
94 | public $filter = []; |
||
95 | |||
96 | /** |
||
97 | * @var callable|null |
||
98 | */ |
||
99 | protected $sort_callback = NULL; |
||
100 | |||
101 | /** |
||
102 | * @var bool |
||
103 | */ |
||
104 | protected $use_happy_components = TRUE; |
||
105 | |||
106 | /** |
||
107 | * @var callable |
||
108 | */ |
||
109 | protected $rowCallback; |
||
110 | |||
111 | /** |
||
112 | * @var array |
||
113 | */ |
||
114 | protected $items_per_page_list; |
||
115 | |||
116 | /** |
||
117 | * @var string |
||
118 | */ |
||
119 | protected $template_file; |
||
120 | |||
121 | /** |
||
122 | * @var Column\IColumn[] |
||
123 | */ |
||
124 | protected $columns = []; |
||
125 | |||
126 | /** |
||
127 | * @var Column\Action[] |
||
128 | */ |
||
129 | protected $actions = []; |
||
130 | |||
131 | /** |
||
132 | * @var GroupAction\GroupActionCollection |
||
133 | */ |
||
134 | protected $group_action_collection; |
||
135 | |||
136 | /** |
||
137 | * @var Filter\Filter[] |
||
138 | */ |
||
139 | protected $filters = []; |
||
140 | |||
141 | /** |
||
142 | * @var Export\Export[] |
||
143 | */ |
||
144 | protected $exports = []; |
||
145 | |||
146 | /** |
||
147 | * @var DataModel |
||
148 | */ |
||
149 | protected $dataModel; |
||
150 | |||
151 | /** |
||
152 | * @var DataFilter |
||
153 | */ |
||
154 | protected $dataFilter; |
||
155 | |||
156 | /** |
||
157 | * @var string |
||
158 | */ |
||
159 | protected $primary_key = 'id'; |
||
160 | |||
161 | /** |
||
162 | * @var bool |
||
163 | */ |
||
164 | protected $do_paginate = TRUE; |
||
165 | |||
166 | /** |
||
167 | * @var bool |
||
168 | */ |
||
169 | protected $csv_export = TRUE; |
||
170 | |||
171 | /** |
||
172 | * @var bool |
||
173 | */ |
||
174 | protected $csv_export_filtered = TRUE; |
||
175 | |||
176 | /** |
||
177 | * @var bool |
||
178 | */ |
||
179 | protected $sortable = FALSE; |
||
180 | |||
181 | /** |
||
182 | * @var string |
||
183 | */ |
||
184 | protected $sortable_handler = 'sort!'; |
||
185 | |||
186 | /** |
||
187 | * @var string |
||
188 | */ |
||
189 | protected $original_template; |
||
190 | |||
191 | /** |
||
192 | * @var array |
||
193 | */ |
||
194 | protected $redraw_item; |
||
195 | |||
196 | /** |
||
197 | * @var mixed |
||
198 | */ |
||
199 | protected $translator; |
||
200 | |||
201 | /** |
||
202 | * @var bool |
||
203 | */ |
||
204 | protected $force_filter_active; |
||
205 | |||
206 | /** |
||
207 | * @var callable |
||
208 | */ |
||
209 | protected $tree_view_children_callback; |
||
210 | |||
211 | /** |
||
212 | * @var callable |
||
213 | */ |
||
214 | protected $tree_view_has_children_callback; |
||
215 | |||
216 | /** |
||
217 | * @var string |
||
218 | */ |
||
219 | protected $tree_view_has_children_column; |
||
220 | |||
221 | /** |
||
222 | * @var bool |
||
223 | */ |
||
224 | protected $outer_filter_rendering = FALSE; |
||
225 | |||
226 | /** |
||
227 | * @var array |
||
228 | */ |
||
229 | protected $columns_export_order = []; |
||
230 | |||
231 | /** |
||
232 | * @var bool |
||
233 | */ |
||
234 | protected $remember_state = TRUE; |
||
235 | |||
236 | /** |
||
237 | * @var bool |
||
238 | */ |
||
239 | protected $refresh_url = TRUE; |
||
240 | |||
241 | /** |
||
242 | * @var Nette\Http\SessionSection |
||
243 | */ |
||
244 | protected $grid_session; |
||
245 | |||
246 | /** |
||
247 | * @var Column\ItemDetail |
||
248 | */ |
||
249 | protected $items_detail; |
||
250 | |||
251 | /** |
||
252 | * @var array |
||
253 | */ |
||
254 | protected $row_conditions = [ |
||
255 | 'group_action' => FALSE, |
||
256 | 'action' => [] |
||
257 | ]; |
||
258 | |||
259 | /** |
||
260 | * @var array |
||
261 | */ |
||
262 | protected $column_callbacks = []; |
||
263 | |||
264 | /** |
||
265 | * @var bool |
||
266 | */ |
||
267 | protected $can_hide_columns = FALSE; |
||
268 | |||
269 | /** |
||
270 | * @var array |
||
271 | */ |
||
272 | protected $columns_visibility = []; |
||
273 | |||
274 | /** |
||
275 | * @var InlineEdit |
||
276 | */ |
||
277 | protected $inlineEdit; |
||
278 | |||
279 | /** |
||
280 | * @var InlineEdit |
||
281 | */ |
||
282 | protected $inlineAdd; |
||
283 | |||
284 | /** |
||
285 | * @var bool |
||
286 | */ |
||
287 | protected $snippets_set = FALSE; |
||
288 | |||
289 | /** |
||
290 | * @var bool |
||
291 | */ |
||
292 | protected $some_column_default_hide = FALSE; |
||
293 | |||
294 | /** |
||
295 | * @var ColumnsSummary |
||
296 | */ |
||
297 | protected $columnsSummary; |
||
298 | |||
299 | |||
300 | /** |
||
301 | * @param Nette\ComponentModel\IContainer|NULL $parent |
||
302 | * @param string $name |
||
303 | */ |
||
304 | public function __construct(Nette\ComponentModel\IContainer $parent = NULL, $name = NULL) |
||
325 | |||
326 | |||
327 | /** |
||
328 | * {inheritDoc} |
||
329 | * @return void |
||
330 | */ |
||
331 | public function attached($presenter) |
||
344 | |||
345 | |||
346 | /******************************************************************************** |
||
347 | * RENDERING * |
||
348 | ********************************************************************************/ |
||
349 | |||
350 | |||
351 | /** |
||
352 | * Render template |
||
353 | * @return void |
||
354 | */ |
||
355 | public function render() |
||
435 | |||
436 | |||
437 | /******************************************************************************** |
||
438 | * ROW CALLBACK * |
||
439 | ********************************************************************************/ |
||
440 | |||
441 | |||
442 | /** |
||
443 | * Each row can be modified with user callback |
||
444 | * @param callable $callback |
||
445 | * @return static |
||
446 | */ |
||
447 | public function setRowCallback(callable $callback) |
||
453 | |||
454 | |||
455 | /******************************************************************************** |
||
456 | * DATA SOURCE * |
||
457 | ********************************************************************************/ |
||
458 | |||
459 | |||
460 | /** |
||
461 | * By default ID, you can change that |
||
462 | * @param string $primary_key |
||
463 | * @return static |
||
464 | */ |
||
465 | public function setPrimaryKey($primary_key) |
||
475 | |||
476 | |||
477 | /** |
||
478 | * Set Grid data source |
||
479 | * @param DataSource\IDataSource|array|\DibiFluent|Nette\Database\Table\Selection|\Doctrine\ORM\QueryBuilder $source |
||
480 | * @return static |
||
481 | */ |
||
482 | public function setDataSource($source) |
||
488 | |||
489 | |||
490 | /******************************************************************************** |
||
491 | * TEMPLATING * |
||
492 | ********************************************************************************/ |
||
493 | |||
494 | |||
495 | /** |
||
496 | * Set custom template file to render |
||
497 | * @param string $template_file |
||
498 | * @return static |
||
499 | */ |
||
500 | public function setTemplateFile($template_file) |
||
506 | |||
507 | |||
508 | /** |
||
509 | * Get DataGrid template file |
||
510 | * @return string |
||
511 | * @return static |
||
512 | */ |
||
513 | public function getTemplateFile() |
||
517 | |||
518 | |||
519 | /** |
||
520 | * Get DataGrid original template file |
||
521 | * @return string |
||
522 | */ |
||
523 | public function getOriginalTemplateFile() |
||
527 | |||
528 | |||
529 | /** |
||
530 | * Tell datagrid wheteher to use or not happy components |
||
531 | * @param boolean|NULL $use If not given, return value of static::$use_happy_components |
||
532 | * @return void|bool |
||
533 | */ |
||
534 | public function useHappyComponents($use = NULL) |
||
542 | |||
543 | |||
544 | /******************************************************************************** |
||
545 | * SORTING * |
||
546 | ********************************************************************************/ |
||
547 | |||
548 | |||
549 | /** |
||
550 | * Set default sorting |
||
551 | * @param array $sort |
||
552 | * @return static |
||
553 | */ |
||
554 | public function setDefaultSort($sort) |
||
566 | |||
567 | |||
568 | /** |
||
569 | * User may set default sorting, apply it |
||
570 | * @return void |
||
571 | */ |
||
572 | public function findDefaultSort() |
||
584 | |||
585 | |||
586 | /** |
||
587 | * Set grido to be sortable |
||
588 | * @param bool $sortable |
||
589 | * @return static |
||
590 | */ |
||
591 | public function setSortable($sortable = TRUE) |
||
601 | |||
602 | |||
603 | /** |
||
604 | * Set sortable handle |
||
605 | * @param string $handler |
||
606 | * @return static |
||
607 | */ |
||
608 | public function setSortableHandler($handler = 'sort!') |
||
614 | |||
615 | |||
616 | /** |
||
617 | * Tell whether DataGrid is sortable |
||
618 | * @return bool |
||
619 | */ |
||
620 | public function isSortable() |
||
624 | |||
625 | /** |
||
626 | * Return sortable handle name |
||
627 | * @return string |
||
628 | */ |
||
629 | public function getSortableHandler() |
||
633 | |||
634 | |||
635 | /******************************************************************************** |
||
636 | * TREE VIEW * |
||
637 | ********************************************************************************/ |
||
638 | |||
639 | |||
640 | /** |
||
641 | * Is tree view set? |
||
642 | * @return boolean |
||
643 | */ |
||
644 | public function isTreeView() |
||
648 | |||
649 | |||
650 | /** |
||
651 | * Setting tree view |
||
652 | * @param callable $get_children_callback |
||
653 | * @param string|callable $tree_view_has_children_column |
||
654 | * @return static |
||
655 | */ |
||
656 | public function setTreeView($get_children_callback, $tree_view_has_children_column = 'has_children') |
||
686 | |||
687 | |||
688 | /** |
||
689 | * Is tree view children callback set? |
||
690 | * @return boolean |
||
691 | */ |
||
692 | public function hasTreeViewChildrenCallback() |
||
696 | |||
697 | |||
698 | /** |
||
699 | * @param mixed $item |
||
700 | * @return boolean |
||
701 | */ |
||
702 | public function treeViewChildrenCallback($item) |
||
706 | |||
707 | |||
708 | /******************************************************************************** |
||
709 | * COLUMNS * |
||
710 | ********************************************************************************/ |
||
711 | |||
712 | |||
713 | /** |
||
714 | * Add text column with no other formating |
||
715 | * @param string $key |
||
716 | * @param string $name |
||
717 | * @param string|null $column |
||
718 | * @return Column\ColumnText |
||
719 | */ |
||
720 | public function addColumnText($key, $name, $column = NULL) |
||
727 | |||
728 | |||
729 | /** |
||
730 | * Add column with link |
||
731 | * @param string $key |
||
732 | * @param string $name |
||
733 | * @param string|null $column |
||
734 | * @return Column\ColumnLink |
||
735 | */ |
||
736 | public function addColumnLink($key, $name, $href = NULL, $column = NULL, array $params = NULL) |
||
748 | |||
749 | |||
750 | /** |
||
751 | * Add column with possible number formating |
||
752 | * @param string $key |
||
753 | * @param string $name |
||
754 | * @param string|null $column |
||
755 | * @return Column\ColumnNumber |
||
756 | */ |
||
757 | public function addColumnNumber($key, $name, $column = NULL) |
||
764 | |||
765 | |||
766 | /** |
||
767 | * Add column with date formating |
||
768 | * @param string $key |
||
769 | * @param string $name |
||
770 | * @param string|null $column |
||
771 | * @return Column\ColumnDateTime |
||
772 | */ |
||
773 | public function addColumnDateTime($key, $name, $column = NULL) |
||
780 | |||
781 | |||
782 | /** |
||
783 | * Add column status |
||
784 | * @param string $key |
||
785 | * @param string $name |
||
786 | * @param string|null $column |
||
787 | * @return Column\ColumnStatus |
||
788 | */ |
||
789 | public function addColumnStatus($key, $name, $column = NULL) |
||
796 | |||
797 | |||
798 | /** |
||
799 | * @param string $key |
||
800 | * @param Column\Column $column |
||
801 | * @return Column\Column |
||
802 | */ |
||
803 | protected function addColumn($key, Column\Column $column) |
||
814 | |||
815 | |||
816 | /** |
||
817 | * Return existing column |
||
818 | * @param string $key |
||
819 | * @return Column\Column |
||
820 | * @throws DataGridException |
||
821 | */ |
||
822 | public function getColumn($key) |
||
830 | |||
831 | |||
832 | /** |
||
833 | * Remove column |
||
834 | * @param string $key |
||
835 | * @return void |
||
836 | */ |
||
837 | public function removeColumn($key) |
||
841 | |||
842 | |||
843 | /** |
||
844 | * Check whether given key already exists in $this->columns |
||
845 | * @param string $key |
||
846 | * @throws DataGridException |
||
847 | */ |
||
848 | protected function addColumnCheck($key) |
||
854 | |||
855 | |||
856 | /******************************************************************************** |
||
857 | * ACTIONS * |
||
858 | ********************************************************************************/ |
||
859 | |||
860 | |||
861 | /** |
||
862 | * Create action |
||
863 | * @param string $key |
||
864 | * @param string $name |
||
865 | * @param string $href |
||
866 | * @param array|null $params |
||
867 | * @return Column\Action |
||
868 | */ |
||
869 | public function addAction($key, $name, $href = NULL, array $params = NULL) |
||
880 | |||
881 | |||
882 | /** |
||
883 | * Create action callback |
||
884 | * @param string $key |
||
885 | * @param string $name |
||
886 | * @return Column\Action |
||
887 | */ |
||
888 | public function addActionCallback($key, $name, $callback = NULL) |
||
905 | |||
906 | |||
907 | /** |
||
908 | * Get existing action |
||
909 | * @param string $key |
||
910 | * @return Column\Action |
||
911 | * @throws DataGridException |
||
912 | */ |
||
913 | public function getAction($key) |
||
921 | |||
922 | |||
923 | /** |
||
924 | * Remove action |
||
925 | * @param string $key |
||
926 | * @return void |
||
927 | */ |
||
928 | public function removeAction($key) |
||
932 | |||
933 | |||
934 | /** |
||
935 | * Check whether given key already exists in $this->filters |
||
936 | * @param string $key |
||
937 | * @throws DataGridException |
||
938 | */ |
||
939 | protected function addActionCheck($key) |
||
945 | |||
946 | |||
947 | /******************************************************************************** |
||
948 | * FILTERS * |
||
949 | ********************************************************************************/ |
||
950 | |||
951 | |||
952 | /** |
||
953 | * Add filter fot text search |
||
954 | * @param string $key |
||
955 | * @param string $name |
||
956 | * @param array|string $columns |
||
957 | * @return Filter\FilterText |
||
958 | * @throws DataGridException |
||
959 | */ |
||
960 | public function addFilterText($key, $name, $columns = NULL) |
||
972 | |||
973 | |||
974 | /** |
||
975 | * Add select box filter |
||
976 | * @param string $key |
||
977 | * @param string $name |
||
978 | * @param array $options |
||
979 | * @param string $column |
||
980 | * @return Filter\FilterSelect |
||
981 | * @throws DataGridException |
||
982 | */ |
||
983 | View Code Duplication | public function addFilterSelect($key, $name, array $options, $column = NULL) |
|
995 | |||
996 | |||
997 | /** |
||
998 | * Add multi select box filter |
||
999 | * @param string $key |
||
1000 | * @param string $name |
||
1001 | * @param array $options |
||
1002 | * @param string $column |
||
1003 | * @return Filter\FilterSelect |
||
1004 | * @throws DataGridException |
||
1005 | */ |
||
1006 | public function addFilterMultiSelect($key, $name, array $options, $column = NULL) |
||
1018 | |||
1019 | |||
1020 | /** |
||
1021 | * Add datepicker filter |
||
1022 | * @param string $key |
||
1023 | * @param string $name |
||
1024 | * @param string $column |
||
1025 | * @return Filter\FilterDate |
||
1026 | * @throws DataGridException |
||
1027 | */ |
||
1028 | public function addFilterDate($key, $name, $column = NULL) |
||
1040 | |||
1041 | |||
1042 | /** |
||
1043 | * Add range filter (from - to) |
||
1044 | * @param string $key |
||
1045 | * @param string $name |
||
1046 | * @param string $column |
||
1047 | * @return Filter\FilterRange |
||
1048 | * @throws DataGridException |
||
1049 | */ |
||
1050 | View Code Duplication | public function addFilterRange($key, $name, $column = NULL, $name_second = '-') |
|
1062 | |||
1063 | |||
1064 | /** |
||
1065 | * Add datepicker filter (from - to) |
||
1066 | * @param string $key |
||
1067 | * @param string $name |
||
1068 | * @param string $column |
||
1069 | * @return Filter\FilterDateRange |
||
1070 | * @throws DataGridException |
||
1071 | */ |
||
1072 | View Code Duplication | public function addFilterDateRange($key, $name, $column = NULL, $name_second = '-') |
|
1084 | |||
1085 | |||
1086 | /** |
||
1087 | * Check whether given key already exists in $this->filters |
||
1088 | * @param string $key |
||
1089 | * @throws DataGridException |
||
1090 | */ |
||
1091 | protected function addFilterCheck($key) |
||
1097 | |||
1098 | |||
1099 | /** |
||
1100 | * Fill array of Filter\Filter[] with values from $this->filter persistent parameter |
||
1101 | * Fill array of Column\Column[] with values from $this->sort persistent parameter |
||
1102 | * @return Filter\Filter[] $this->filters === Filter\Filter[] |
||
1103 | */ |
||
1104 | public function assableFilters() |
||
1132 | |||
1133 | |||
1134 | /** |
||
1135 | * Remove filter |
||
1136 | * @param string $key |
||
1137 | * @return void |
||
1138 | */ |
||
1139 | public function removeFilter($key) |
||
1143 | |||
1144 | |||
1145 | /** |
||
1146 | * Get defined filter |
||
1147 | * @param string $key |
||
1148 | * @return Filter\Filter |
||
1149 | */ |
||
1150 | public function getFilter($key) |
||
1158 | |||
1159 | |||
1160 | /******************************************************************************** |
||
1161 | * FILTERING * |
||
1162 | ********************************************************************************/ |
||
1163 | |||
1164 | |||
1165 | /** |
||
1166 | * Is filter active? |
||
1167 | * @return boolean |
||
1168 | */ |
||
1169 | public function isFilterActive() |
||
1175 | |||
1176 | |||
1177 | /** |
||
1178 | * Tell that filter is active from whatever reasons |
||
1179 | * return static |
||
1180 | */ |
||
1181 | public function setFilterActive() |
||
1187 | |||
1188 | |||
1189 | /** |
||
1190 | * Set filter values (force - overwrite user data) |
||
1191 | * @param array $filter |
||
1192 | * @return static |
||
1193 | */ |
||
1194 | public function setFilter(array $filter) |
||
1202 | |||
1203 | |||
1204 | /** |
||
1205 | * If we want to sent some initial filter |
||
1206 | * @param array $filter |
||
1207 | * @param bool $use_on_reset |
||
1208 | * @return static |
||
1209 | */ |
||
1210 | public function setDefaultFilter(array $default_filter, $use_on_reset = TRUE) |
||
1248 | |||
1249 | |||
1250 | /** |
||
1251 | * User may set default filter, find it |
||
1252 | * @return void |
||
1253 | */ |
||
1254 | public function findDefaultFilter() |
||
1272 | |||
1273 | |||
1274 | /** |
||
1275 | * FilterAndGroupAction form factory |
||
1276 | * @return Form |
||
1277 | */ |
||
1278 | public function createComponentFilter() |
||
1346 | |||
1347 | |||
1348 | /** |
||
1349 | * Set $this->filter values after filter form submitted |
||
1350 | * @param Form $form |
||
1351 | * @return void |
||
1352 | */ |
||
1353 | public function filterSucceeded(Form $form) |
||
1448 | |||
1449 | |||
1450 | /** |
||
1451 | * Should be datagrid filters rendered separately? |
||
1452 | * @param boolean $out |
||
1453 | * @return static |
||
1454 | */ |
||
1455 | public function setOuterFilterRendering($out = TRUE) |
||
1461 | |||
1462 | |||
1463 | /** |
||
1464 | * Are datagrid filters rendered separately? |
||
1465 | * @return boolean |
||
1466 | */ |
||
1467 | public function hasOuterFilterRendering() |
||
1471 | |||
1472 | |||
1473 | /** |
||
1474 | * Try to restore session stuff |
||
1475 | * @return void |
||
1476 | */ |
||
1477 | public function findSessionValues() |
||
1527 | |||
1528 | |||
1529 | /******************************************************************************** |
||
1530 | * EXPORTS * |
||
1531 | ********************************************************************************/ |
||
1532 | |||
1533 | |||
1534 | /** |
||
1535 | * Add export of type callback |
||
1536 | * @param string $text |
||
1537 | * @param callable $callback |
||
1538 | * @param boolean $filtered |
||
1539 | * @return Export\Export |
||
1540 | */ |
||
1541 | public function addExportCallback($text, $callback, $filtered = FALSE) |
||
1549 | |||
1550 | |||
1551 | /** |
||
1552 | * Add already implemented csv export |
||
1553 | * @param string $text |
||
1554 | * @param string $csv_file_name |
||
1555 | * @param string|null $output_encoding |
||
1556 | * @param string|null $delimiter |
||
1557 | * @return Export\Export |
||
1558 | */ |
||
1559 | public function addExportCsv($text, $csv_file_name, $output_encoding = NULL, $delimiter = NULL) |
||
1569 | |||
1570 | |||
1571 | /** |
||
1572 | * Add already implemented csv export, but for filtered data |
||
1573 | * @param string $text |
||
1574 | * @param string $csv_file_name |
||
1575 | * @param string|null $output_encoding |
||
1576 | * @param string|null $delimiter |
||
1577 | * @return Export\Export |
||
1578 | */ |
||
1579 | public function addExportCsvFiltered($text, $csv_file_name, $output_encoding = NULL, $delimiter = NULL) |
||
1589 | |||
1590 | |||
1591 | /** |
||
1592 | * Add export to array |
||
1593 | * @param Export\Export $export |
||
1594 | * @return Export\Export |
||
1595 | */ |
||
1596 | protected function addToExports(Export\Export $export) |
||
1604 | |||
1605 | |||
1606 | public function resetExportsLinks() |
||
1612 | |||
1613 | |||
1614 | /******************************************************************************** |
||
1615 | * GROUP ACTIONS * |
||
1616 | ********************************************************************************/ |
||
1617 | |||
1618 | |||
1619 | /** |
||
1620 | * Alias for add group select action |
||
1621 | * @param string $title |
||
1622 | * @param array $options |
||
1623 | * @return GroupAction\GroupAction |
||
1624 | */ |
||
1625 | public function addGroupAction($title, $options = []) |
||
1629 | |||
1630 | /** |
||
1631 | * Add group action (select box) |
||
1632 | * @param string $title |
||
1633 | * @param array $options |
||
1634 | * @return GroupAction\GroupAction |
||
1635 | */ |
||
1636 | public function addGroupSelectAction($title, $options = []) |
||
1640 | |||
1641 | /** |
||
1642 | * Add group action (text input) |
||
1643 | * @param string $title |
||
1644 | * @return GroupAction\GroupAction |
||
1645 | */ |
||
1646 | public function addGroupTextAction($title) |
||
1650 | |||
1651 | /** |
||
1652 | * Get collection of all group actions |
||
1653 | * @return GroupAction\GroupActionCollection |
||
1654 | */ |
||
1655 | public function getGroupActionCollection() |
||
1663 | |||
1664 | |||
1665 | /** |
||
1666 | * Has datagrid some group actions? |
||
1667 | * @return boolean |
||
1668 | */ |
||
1669 | public function hasGroupActions() |
||
1673 | |||
1674 | |||
1675 | /******************************************************************************** |
||
1676 | * HANDLERS * |
||
1677 | ********************************************************************************/ |
||
1678 | |||
1679 | |||
1680 | /** |
||
1681 | * Handler for changind page (just refresh site with page as persistent paramter set) |
||
1682 | * @param int $page |
||
1683 | * @return void |
||
1684 | */ |
||
1685 | public function handlePage($page) |
||
1695 | |||
1696 | |||
1697 | /** |
||
1698 | * Handler for sorting |
||
1699 | * @param array $sort |
||
1700 | * @return void |
||
1701 | */ |
||
1702 | public function handleSort(array $sort) |
||
1741 | |||
1742 | |||
1743 | /** |
||
1744 | * handler for reseting the filter |
||
1745 | * @return void |
||
1746 | */ |
||
1747 | public function handleResetFilter() |
||
1768 | |||
1769 | |||
1770 | /** |
||
1771 | * Handler for export |
||
1772 | * @param int $id Key for particular export class in array $this->exports |
||
1773 | * @return void |
||
1774 | */ |
||
1775 | public function handleExport($id) |
||
1823 | |||
1824 | |||
1825 | /** |
||
1826 | * Handler for getting children of parent item (e.g. category) |
||
1827 | * @param int $parent |
||
1828 | * @return void |
||
1829 | */ |
||
1830 | public function handleGetChildren($parent) |
||
1847 | |||
1848 | |||
1849 | /** |
||
1850 | * Handler for getting item detail |
||
1851 | * @param mixed $id |
||
1852 | * @return void |
||
1853 | */ |
||
1854 | public function handleGetItemDetail($id) |
||
1868 | |||
1869 | |||
1870 | /** |
||
1871 | * Handler for inline editing |
||
1872 | * @param mixed $id |
||
1873 | * @param mixed $key |
||
1874 | * @return void |
||
1875 | */ |
||
1876 | public function handleEdit($id, $key) |
||
1883 | |||
1884 | |||
1885 | /** |
||
1886 | * Redraw $this |
||
1887 | * @return void |
||
1888 | */ |
||
1889 | public function reload($snippets = []) |
||
1912 | |||
1913 | |||
1914 | /** |
||
1915 | * Handler for column status |
||
1916 | * @param string $id |
||
1917 | * @param string $key |
||
1918 | * @param string $value |
||
1919 | * @return void |
||
1920 | */ |
||
1921 | public function handleChangeStatus($id, $key, $value) |
||
1929 | |||
1930 | |||
1931 | /** |
||
1932 | * Redraw just one row via ajax |
||
1933 | * @param int $id |
||
1934 | * @param mixed $primary_where_column |
||
1935 | * @return void |
||
1936 | */ |
||
1937 | public function redrawItem($id, $primary_where_column = NULL) |
||
1948 | |||
1949 | |||
1950 | /** |
||
1951 | * Tell datagrid to display all columns |
||
1952 | * @return void |
||
1953 | */ |
||
1954 | public function handleShowAllColumns() |
||
1963 | |||
1964 | |||
1965 | /** |
||
1966 | * Tell datagrid to display default columns |
||
1967 | * @return void |
||
1968 | */ |
||
1969 | public function handleShowDefaultColumns() |
||
1978 | |||
1979 | |||
1980 | /** |
||
1981 | * Reveal particular column |
||
1982 | * @param string $column |
||
1983 | * @return void |
||
1984 | */ |
||
1985 | View Code Duplication | public function handleShowColumn($column) |
|
2004 | |||
2005 | |||
2006 | /** |
||
2007 | * Notice datagrid to not display particular columns |
||
2008 | * @param string $column |
||
2009 | * @return void |
||
2010 | */ |
||
2011 | View Code Duplication | public function handleHideColumn($column) |
|
2031 | |||
2032 | |||
2033 | public function handleActionCallback($__key, $__id) |
||
2043 | |||
2044 | |||
2045 | /******************************************************************************** |
||
2046 | * PAGINATION * |
||
2047 | ********************************************************************************/ |
||
2048 | |||
2049 | |||
2050 | /** |
||
2051 | * Set options of select "items_per_page" |
||
2052 | * @param array $items_per_page_list |
||
2053 | * @return static |
||
2054 | */ |
||
2055 | public function setItemsPerPageList(array $items_per_page_list, $include_all = TRUE) |
||
2065 | |||
2066 | |||
2067 | /** |
||
2068 | * Paginator factory |
||
2069 | * @return Components\DataGridPaginator\DataGridPaginator |
||
2070 | */ |
||
2071 | public function createComponentPaginator() |
||
2086 | |||
2087 | |||
2088 | /** |
||
2089 | * PerPage form factory |
||
2090 | * @return Form |
||
2091 | */ |
||
2092 | public function createComponentPerPage() |
||
2118 | |||
2119 | |||
2120 | /** |
||
2121 | * Get parameter per_page |
||
2122 | * @return int |
||
2123 | */ |
||
2124 | public function getPerPage() |
||
2136 | |||
2137 | |||
2138 | /** |
||
2139 | * Get associative array of items_per_page_list |
||
2140 | * @return array |
||
2141 | */ |
||
2142 | public function getItemsPerPageList() |
||
2160 | |||
2161 | |||
2162 | /** |
||
2163 | * Order Grid to "be paginated" |
||
2164 | * @param bool $do |
||
2165 | * @return static |
||
2166 | */ |
||
2167 | public function setPagination($do) |
||
2173 | |||
2174 | |||
2175 | /** |
||
2176 | * Tell whether Grid is paginated |
||
2177 | * @return bool |
||
2178 | */ |
||
2179 | public function isPaginated() |
||
2183 | |||
2184 | |||
2185 | /** |
||
2186 | * Return current paginator class |
||
2187 | * @return NULL|Components\DataGridPaginator\DataGridPaginator |
||
2188 | */ |
||
2189 | public function getPaginator() |
||
2197 | |||
2198 | |||
2199 | /******************************************************************************** |
||
2200 | * I18N * |
||
2201 | ********************************************************************************/ |
||
2202 | |||
2203 | |||
2204 | /** |
||
2205 | * Set datagrid translator |
||
2206 | * @param Nette\Localization\ITranslator $translator |
||
2207 | * @return static |
||
2208 | */ |
||
2209 | public function setTranslator(Nette\Localization\ITranslator $translator) |
||
2215 | |||
2216 | |||
2217 | /** |
||
2218 | * Get translator for datagrid |
||
2219 | * @return Nette\Localization\ITranslator |
||
2220 | */ |
||
2221 | public function getTranslator() |
||
2229 | |||
2230 | |||
2231 | /******************************************************************************** |
||
2232 | * COLUMNS ORDER * |
||
2233 | ********************************************************************************/ |
||
2234 | |||
2235 | |||
2236 | /** |
||
2237 | * Set order of datagrid columns |
||
2238 | * @param array $order |
||
2239 | * @return static |
||
2240 | */ |
||
2241 | public function setColumnsOrder($order) |
||
2259 | |||
2260 | |||
2261 | /** |
||
2262 | * Columns order may be different for export and normal grid |
||
2263 | * @param array $order |
||
2264 | */ |
||
2265 | public function setColumnsExportOrder($order) |
||
2269 | |||
2270 | |||
2271 | /******************************************************************************** |
||
2272 | * SESSION & URL * |
||
2273 | ********************************************************************************/ |
||
2274 | |||
2275 | |||
2276 | /** |
||
2277 | * Find some unique session key name |
||
2278 | * @return string |
||
2279 | */ |
||
2280 | public function getSessionSectionName() |
||
2284 | |||
2285 | |||
2286 | /** |
||
2287 | * Should datagrid remember its filters/pagination/etc using session? |
||
2288 | * @param bool $remember |
||
2289 | * @return static |
||
2290 | */ |
||
2291 | public function setRememberState($remember = TRUE) |
||
2297 | |||
2298 | |||
2299 | /** |
||
2300 | * Should datagrid refresh url using history API? |
||
2301 | * @param bool $refresh |
||
2302 | * @return static |
||
2303 | */ |
||
2304 | public function setRefreshUrl($refresh = TRUE) |
||
2311 | |||
2312 | |||
2313 | /** |
||
2314 | * Get session data if functionality is enabled |
||
2315 | * @param string $key |
||
2316 | * @return mixed |
||
2317 | */ |
||
2318 | public function getSessionData($key = NULL, $default_value = NULL) |
||
2326 | |||
2327 | |||
2328 | /** |
||
2329 | * Save session data - just if it is enabled |
||
2330 | * @param string $key |
||
2331 | * @param mixed $value |
||
2332 | * @return void |
||
2333 | */ |
||
2334 | public function saveSessionData($key, $value) |
||
2340 | |||
2341 | |||
2342 | /** |
||
2343 | * Delete session data |
||
2344 | * @return void |
||
2345 | */ |
||
2346 | public function deleteSesssionData($key) |
||
2350 | |||
2351 | |||
2352 | /******************************************************************************** |
||
2353 | * ITEM DETAIL * |
||
2354 | ********************************************************************************/ |
||
2355 | |||
2356 | |||
2357 | /** |
||
2358 | * Get items detail parameters |
||
2359 | * @return array |
||
2360 | */ |
||
2361 | public function getItemsDetail() |
||
2365 | |||
2366 | |||
2367 | /** |
||
2368 | * Items can have thair detail - toggled |
||
2369 | * @param mixed $detail callable|string|bool |
||
2370 | * @param bool|NULL $primary_where_column |
||
2371 | * @return Column\ItemDetail |
||
2372 | */ |
||
2373 | public function setItemsDetail($detail = TRUE, $primary_where_column = NULL) |
||
2412 | |||
2413 | |||
2414 | /** |
||
2415 | * @param callable $callable_set_container |
||
2416 | * @return static |
||
2417 | */ |
||
2418 | public function setItemsDetailForm(callable $callable_set_container) |
||
2430 | |||
2431 | |||
2432 | /** |
||
2433 | * @return Nette\Forms\Container|NULL |
||
2434 | */ |
||
2435 | public function getItemDetailForm() |
||
2443 | |||
2444 | |||
2445 | /******************************************************************************** |
||
2446 | * ROW PRIVILEGES * |
||
2447 | ********************************************************************************/ |
||
2448 | |||
2449 | |||
2450 | /** |
||
2451 | * @param callable $condition |
||
2452 | * @return void |
||
2453 | */ |
||
2454 | public function allowRowsGroupAction(callable $condition) |
||
2458 | |||
2459 | |||
2460 | /** |
||
2461 | * @param string $key |
||
2462 | * @param callable $condition |
||
2463 | * @return void |
||
2464 | */ |
||
2465 | public function allowRowsAction($key, callable $condition) |
||
2469 | |||
2470 | |||
2471 | /** |
||
2472 | * @param string $name |
||
2473 | * @param string|null $key |
||
2474 | * @return bool|callable |
||
2475 | */ |
||
2476 | public function getRowCondition($name, $key = NULL) |
||
2490 | |||
2491 | |||
2492 | /******************************************************************************** |
||
2493 | * COLUMN CALLBACK * |
||
2494 | ********************************************************************************/ |
||
2495 | |||
2496 | |||
2497 | /** |
||
2498 | * @param string $key |
||
2499 | * @param callable $callback |
||
2500 | * @return void |
||
2501 | */ |
||
2502 | public function addColumnCallback($key, callable $callback) |
||
2506 | |||
2507 | |||
2508 | /** |
||
2509 | * @param string $key |
||
2510 | * @return callable|null |
||
2511 | */ |
||
2512 | public function getColumnCallback($key) |
||
2516 | |||
2517 | |||
2518 | /******************************************************************************** |
||
2519 | * INLINE EDIT * |
||
2520 | ********************************************************************************/ |
||
2521 | |||
2522 | |||
2523 | /** |
||
2524 | * @return InlineEdit |
||
2525 | */ |
||
2526 | public function addInlineEdit($primary_where_column = NULL) |
||
2532 | |||
2533 | |||
2534 | /** |
||
2535 | * @return InlineEdit|null |
||
2536 | */ |
||
2537 | public function getInlineEdit() |
||
2541 | |||
2542 | |||
2543 | /** |
||
2544 | * @param mixed $id |
||
2545 | * @return void |
||
2546 | */ |
||
2547 | public function handleInlineEdit($id) |
||
2560 | |||
2561 | |||
2562 | /******************************************************************************** |
||
2563 | * INLINE ADD * |
||
2564 | ********************************************************************************/ |
||
2565 | |||
2566 | |||
2567 | /** |
||
2568 | * @return InlineEdit |
||
2569 | */ |
||
2570 | public function addInlineAdd() |
||
2580 | |||
2581 | |||
2582 | /** |
||
2583 | * @return InlineEdit|null |
||
2584 | */ |
||
2585 | public function getInlineAdd() |
||
2589 | |||
2590 | |||
2591 | /******************************************************************************** |
||
2592 | * HIDEABLE COLUMNS * |
||
2593 | ********************************************************************************/ |
||
2594 | |||
2595 | |||
2596 | /** |
||
2597 | * Can datagrid hide colums? |
||
2598 | * @return boolean |
||
2599 | */ |
||
2600 | public function canHideColumns() |
||
2604 | |||
2605 | |||
2606 | /** |
||
2607 | * Order Grid to set columns hideable. |
||
2608 | * @return static |
||
2609 | */ |
||
2610 | public function setColumnsHideable() |
||
2616 | |||
2617 | |||
2618 | /******************************************************************************** |
||
2619 | * COLUMNS SUMMARY * |
||
2620 | ********************************************************************************/ |
||
2621 | |||
2622 | |||
2623 | /** |
||
2624 | * Will datagrid show summary in the end? |
||
2625 | * @return bool |
||
2626 | */ |
||
2627 | public function hasColumnsSummary() |
||
2631 | |||
2632 | |||
2633 | /** |
||
2634 | * Set columns to be summarized in the end. |
||
2635 | * @param array $columns |
||
2636 | * @return ColumnsSummary |
||
2637 | */ |
||
2638 | public function setColumnsSummary(array $columns) |
||
2644 | |||
2645 | |||
2646 | /** |
||
2647 | * @return ColumnsSummary|NULL |
||
2648 | */ |
||
2649 | public function getColumnsSummary() |
||
2653 | |||
2654 | |||
2655 | /******************************************************************************** |
||
2656 | * INTERNAL * |
||
2657 | ********************************************************************************/ |
||
2658 | |||
2659 | |||
2660 | /** |
||
2661 | * Get count of columns |
||
2662 | * @return int |
||
2663 | */ |
||
2664 | public function getColumnsCount() |
||
2682 | |||
2683 | |||
2684 | /** |
||
2685 | * Get primary key of datagrid data source |
||
2686 | * @return string |
||
2687 | */ |
||
2688 | public function getPrimaryKey() |
||
2692 | |||
2693 | |||
2694 | /** |
||
2695 | * Get set of set columns |
||
2696 | * @return Column\IColumn[] |
||
2697 | */ |
||
2698 | public function getColumns() |
||
2730 | |||
2731 | |||
2732 | /** |
||
2733 | * @return PresenterComponent |
||
2734 | */ |
||
2735 | public function getParent() |
||
2747 | |||
2748 | |||
2749 | /** |
||
2750 | * Some of datagrid columns is hidden by default |
||
2751 | * @param bool $default_hide |
||
2752 | */ |
||
2753 | public function setSomeColumnDefaultHide($default_hide) |
||
2757 | |||
2758 | |||
2759 | /** |
||
2760 | * Are some of columns hidden bydefault? |
||
2761 | */ |
||
2762 | public function hasSomeColumnDefaultHide() |
||
2766 | |||
2767 | } |
||
2768 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.