We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
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 Crud 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 Crud, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
5 | class Crud |
||
6 | { |
||
7 | // -------------- |
||
8 | // CRUD variables |
||
9 | // -------------- |
||
10 | // These variables are passed to the CRUD views, inside the $crud variable. |
||
11 | // All variables are public, so they can be modified from your EntityCrudController. |
||
12 | // All functions and methods are also public, so they can be used in your EntityCrudController to modify these variables. |
||
13 | |||
14 | // TODO: translate $entity_name and $entity_name_plural by default, with english fallback |
||
15 | // TODO: code logic for using either Laravel Authorization or Entrust (whatever one chooses) for access |
||
16 | |||
17 | public $model = "\App\Models\Entity"; // what's the namespace for your entity's model |
||
18 | public $route; // what route have you defined for your entity? used for links. |
||
19 | public $entity_name = "entry"; // what name will show up on the buttons, in singural (ex: Add entity) |
||
20 | public $entity_name_plural = "entries"; // what name will show up on the buttons, in plural (ex: Delete 5 entities) |
||
21 | |||
22 | public $access = ['list', 'create', 'update', 'delete', /* 'reorder', 'show', 'details_row' */]; |
||
|
|||
23 | |||
24 | public $reorder = false; |
||
25 | public $reorder_label = false; |
||
26 | public $reorder_max_level = 3; |
||
27 | |||
28 | public $details_row = false; |
||
29 | |||
30 | public $columns = []; // Define the columns for the table view as an array; |
||
31 | public $create_fields = []; // Define the fields for the "Add new entry" view as an array; |
||
32 | public $update_fields = []; // Define the fields for the "Edit entry" view as an array; |
||
33 | |||
34 | public $query; |
||
35 | public $entry; |
||
36 | |||
37 | // TONE FIELDS - TODO: find out what he did with them, replicate or delete |
||
38 | public $field_types = []; |
||
39 | |||
40 | public $custom_buttons = []; |
||
41 | public $relations = []; |
||
42 | public $sort = []; |
||
43 | |||
44 | public $buttons = ['']; |
||
45 | |||
46 | |||
47 | |||
48 | // The following methods are used in CrudController or your EntityCrudController to manipulate the variables above. |
||
49 | |||
50 | |||
51 | /* |
||
52 | |-------------------------------------------------------------------------- |
||
53 | | CREATE |
||
54 | |-------------------------------------------------------------------------- |
||
55 | */ |
||
56 | |||
57 | /** |
||
58 | * Insert a row in the database. |
||
59 | * |
||
60 | * @param [Request] All input values to be inserted. |
||
61 | * @return [Eloquent Collection] |
||
62 | */ |
||
63 | public function create($data) |
||
73 | |||
74 | |||
75 | /** |
||
76 | * Get all fields needed for the ADD NEW ENTRY form. |
||
77 | * |
||
78 | * @return [array] The fields with attributes and fake attributes. |
||
79 | */ |
||
80 | public function getCreateFields() |
||
84 | |||
85 | /** |
||
86 | * Get all fields with relation set (model key set on field) |
||
87 | * |
||
88 | * @param [string: create/update/both] |
||
89 | * @return [array] The fields with model key set. |
||
90 | */ |
||
91 | public function getRelationFields($form = 'create') |
||
123 | |||
124 | |||
125 | public function syncPivot($model, $data, $form = 'create') |
||
147 | |||
148 | |||
149 | |||
150 | /** |
||
151 | * Adds a required => true attribute to each field, so that the required asterisc will show up in the create/update forms. |
||
152 | * TODO: make this work, by editing the $this->fields variable and all fields. |
||
153 | * |
||
154 | * @param [string or array of strings] |
||
155 | */ |
||
156 | public function setRequiredFields($fields, $form = 'both') |
||
160 | |||
161 | /** |
||
162 | * Adds a required => true attribute to this field, so that the required asteris will show up in the create/update forms. |
||
163 | * |
||
164 | * @param [string] |
||
165 | */ |
||
166 | public function setRequiredField($field, $form = 'both') |
||
170 | |||
171 | /** |
||
172 | * Get all fields that have the required attribute. |
||
173 | * TODO: make this work after making setRequiredFields() work. |
||
174 | * |
||
175 | * @return [array] |
||
176 | */ |
||
177 | public function getRequiredFields($form = 'both') |
||
181 | |||
182 | |||
183 | /* |
||
184 | |-------------------------------------------------------------------------- |
||
185 | | READ |
||
186 | |-------------------------------------------------------------------------- |
||
187 | */ |
||
188 | |||
189 | /** |
||
190 | * Find and retrieve an entry in the database or fail. |
||
191 | * |
||
192 | * @param [int] The id of the row in the db to fetch. |
||
193 | * @return [Eloquent Collection] The row in the db. |
||
194 | */ |
||
195 | public function getEntry($id) |
||
200 | |||
201 | |||
202 | /** |
||
203 | * Get all entries from the database. |
||
204 | * |
||
205 | * @return [Collection of your model] |
||
206 | */ |
||
207 | public function getEntries() |
||
218 | |||
219 | |||
220 | /** |
||
221 | * Get the fields for the create or update forms. |
||
222 | * |
||
223 | * @param [form] create / update / both - defaults to 'both' |
||
224 | * @param [integer] the ID of the entity to be edited in the Update form |
||
225 | * @return [array] all the fields that need to be shown and their information |
||
226 | */ |
||
227 | public function getFields($form, $id = false) |
||
243 | |||
244 | /** |
||
245 | * Enable the DETAILS ROW functionality: |
||
246 | * |
||
247 | * In the table view, show a plus sign next to each entry. |
||
248 | * When clicking that plus sign, an AJAX call will bring whatever content you want from the EntityCrudController::showDetailsRow($id) and show it to the user. |
||
249 | */ |
||
250 | public function enableDetailsRow() |
||
254 | |||
255 | /** |
||
256 | * Disable the DETAILS ROW functionality: |
||
257 | */ |
||
258 | public function disableDetailsRow() |
||
262 | |||
263 | |||
264 | |||
265 | /* |
||
266 | |-------------------------------------------------------------------------- |
||
267 | | UPDATE |
||
268 | |-------------------------------------------------------------------------- |
||
269 | */ |
||
270 | |||
271 | /** |
||
272 | * Update a row in the database. |
||
273 | * |
||
274 | * @param [Int] The entity's id |
||
275 | * @param [Request] All inputs to be updated. |
||
276 | * @return [Eloquent Collection] |
||
277 | */ |
||
278 | public function update($id, $data) |
||
287 | |||
288 | |||
289 | /** |
||
290 | * Get all fields needed for the EDIT ENTRY form. |
||
291 | * |
||
292 | * @param [integer] The id of the entry that is being edited. |
||
293 | * @return [array] The fields with attributes, fake attributes and values. |
||
294 | */ |
||
295 | public function getUpdateFields($id) |
||
326 | |||
327 | |||
328 | |||
329 | |||
330 | /* |
||
331 | |-------------------------------------------------------------------------- |
||
332 | | DELETE |
||
333 | |-------------------------------------------------------------------------- |
||
334 | */ |
||
335 | |||
336 | /** |
||
337 | * Delete a row from the database. |
||
338 | * |
||
339 | * @param [int] The id of the item to be deleted. |
||
340 | * @return [bool] Deletion confirmation. |
||
341 | * |
||
342 | * TODO: should this delete items with relations to it too? |
||
343 | */ |
||
344 | public function delete($id) |
||
348 | |||
349 | |||
350 | |||
351 | |||
352 | /* |
||
353 | |-------------------------------------------------------------------------- |
||
354 | | REORDER |
||
355 | |-------------------------------------------------------------------------- |
||
356 | */ |
||
357 | |||
358 | |||
359 | /** |
||
360 | * Change the order and parents of the given elements, according to the NestedSortable AJAX call. |
||
361 | * |
||
362 | * @param [Request] The entire request from the NestedSortable AJAX Call. |
||
363 | * @return [integer] The number of items whose position in the tree has been changed. |
||
364 | */ |
||
365 | public function updateTreeOrder($request) |
||
384 | |||
385 | |||
386 | /** |
||
387 | * Enable the Reorder functionality in the CRUD Panel for users that have the been given access to 'reorder' using: |
||
388 | * $this->crud->allowAccess('reorder'); |
||
389 | * |
||
390 | * @param [string] Column name that will be shown on the labels. |
||
391 | * @param [integer] Maximum hierarchy level to which the elements can be nested (1 = no nesting, just reordering). |
||
392 | */ |
||
393 | public function enableReorder($label = 'name', $max_level = 1) |
||
399 | |||
400 | /** |
||
401 | * Disable the Reorder functionality in the CRUD Panel for all users. |
||
402 | * |
||
403 | */ |
||
404 | public function disableReorder() |
||
408 | |||
409 | /** |
||
410 | * Check if the Reorder functionality is enabled or not. |
||
411 | * |
||
412 | * @return boolean |
||
413 | */ |
||
414 | public function isReorderEnabled() |
||
418 | |||
419 | |||
420 | |||
421 | /* |
||
422 | |-------------------------------------------------------------------------- |
||
423 | | CRUD ACCESS |
||
424 | |-------------------------------------------------------------------------- |
||
425 | */ |
||
426 | |||
427 | public function allowAccess($access) |
||
432 | |||
433 | public function denyAccess($access) |
||
438 | |||
439 | /** |
||
440 | * Check if a permission is enabled for a Crud Panel. Return false if not. |
||
441 | * |
||
442 | * @param [string] Permission. |
||
443 | * @return boolean |
||
444 | */ |
||
445 | public function hasAccess($permission) |
||
453 | |||
454 | /** |
||
455 | * Check if a permission is enabled for a Crud Panel. Fail if not. |
||
456 | * |
||
457 | * @param [string] Permission. |
||
458 | * @return boolean |
||
459 | */ |
||
460 | public function hasAccessOrFail($permission) |
||
467 | |||
468 | |||
469 | |||
470 | /* |
||
471 | |-------------------------------------------------------------------------- |
||
472 | | CRUD MANIPULATION |
||
473 | |-------------------------------------------------------------------------- |
||
474 | */ |
||
475 | |||
476 | |||
477 | |||
478 | // ------------------------------------------------------ |
||
479 | // BASICS - model, route, entity_name, entity_name_plural |
||
480 | // ------------------------------------------------------ |
||
481 | |||
482 | /** |
||
483 | * This function binds the CRUD to its corresponding Model (which extends Eloquent). |
||
484 | * All Create-Read-Update-Delete operations are done using that Eloquent Collection. |
||
485 | * |
||
486 | * @param [string] Full model namespace. Ex: App\Models\Article |
||
487 | */ |
||
488 | public function setModel($model_namespace) |
||
497 | |||
498 | /** |
||
499 | * Get the corresponding Eloquent Model for the CrudController, as defined with the setModel() function; |
||
500 | * |
||
501 | * @return [Eloquent Collection] |
||
502 | */ |
||
503 | public function getModel() |
||
507 | |||
508 | /** |
||
509 | * Set the route for this CRUD. |
||
510 | * Ex: admin/article |
||
511 | * |
||
512 | * @param [string] Route name. |
||
513 | * @param [array] Parameters. |
||
514 | */ |
||
515 | public function setRoute($route) |
||
520 | |||
521 | /** |
||
522 | * Set the route for this CRUD using the route name. |
||
523 | * Ex: admin.article |
||
524 | * |
||
525 | * @param [string] Route name. |
||
526 | * @param [array] Parameters. |
||
527 | */ |
||
528 | public function setRouteName($route, $parameters = []) |
||
537 | |||
538 | /** |
||
539 | * Get the current CrudController route. |
||
540 | * |
||
541 | * Can be defined in the CrudController with: |
||
542 | * - $this->crud->setRoute('admin/article') |
||
543 | * - $this->crud->setRouteName('admin.article') |
||
544 | * - $this->crud->route = "admin/article" |
||
545 | * |
||
546 | * @return [string] |
||
547 | */ |
||
548 | public function getRoute() |
||
552 | |||
553 | /** |
||
554 | * Set the entity name in singular and plural. |
||
555 | * Used all over the CRUD interface (header, add button, reorder button, breadcrumbs). |
||
556 | * |
||
557 | * @param [string] Entity name, in singular. Ex: article |
||
558 | * @param [string] Entity name, in plural. Ex: articles |
||
559 | */ |
||
560 | public function setEntityNameStrings($singular, $plural) { |
||
564 | |||
565 | |||
566 | |||
567 | |||
568 | // ------------ |
||
569 | // COLUMNS |
||
570 | // ------------ |
||
571 | |||
572 | /** |
||
573 | * Add a bunch of column names and their details to the CRUD object. |
||
574 | * |
||
575 | * @param [array or multi-dimensional array] |
||
576 | */ |
||
577 | public function setColumns($columns) |
||
611 | |||
612 | /** |
||
613 | * Add a column at the end of to the CRUD object's "columns" array. |
||
614 | * |
||
615 | * @param [string or array] |
||
616 | */ |
||
617 | public function addColumn($column) |
||
627 | |||
628 | /** |
||
629 | * Add multiple columns at the end of the CRUD object's "columns" array. |
||
630 | * |
||
631 | * @param [array of columns] |
||
632 | */ |
||
633 | public function addColumns($columns) |
||
641 | |||
642 | /** |
||
643 | * Add the default column type to the given Column, inferring the type from the database column type. |
||
644 | * |
||
645 | * @param [column array] |
||
646 | */ |
||
647 | public function addDefaultTypeToColumn($column) |
||
657 | |||
658 | /** |
||
659 | * If a field or column array is missing the "label" attribute, an ugly error would be show. |
||
660 | * So we add the field Name as a label - it's better than nothing. |
||
661 | * |
||
662 | * @param [field or column] |
||
663 | */ |
||
664 | public function addDefaultLabel($array) { |
||
672 | |||
673 | /** |
||
674 | * Remove multiple columns from the CRUD object using their names. |
||
675 | * |
||
676 | * @param [column array] |
||
677 | */ |
||
678 | public function removeColumns($columns) |
||
682 | |||
683 | /** |
||
684 | * Remove a column from the CRUD object using its name. |
||
685 | * |
||
686 | * @param [column array] |
||
687 | */ |
||
688 | public function removeColumn($column) |
||
692 | |||
693 | /** |
||
694 | * Change attributes for multiple columns. |
||
695 | * |
||
696 | * @param [columns arrays] |
||
697 | * @param [attributes and values array] |
||
698 | */ |
||
699 | public function setColumnsDetails($columns, $attributes) |
||
703 | |||
704 | /** |
||
705 | * Change attributes for a certain column. |
||
706 | * |
||
707 | * @param [string] Column name. |
||
708 | * @param [attributes and values array] |
||
709 | */ |
||
710 | public function setColumnDetails($column, $attributes) |
||
714 | |||
715 | |||
716 | /** |
||
717 | * Order the columns in a certain way. |
||
718 | * |
||
719 | * @param [string] Column name. |
||
720 | * @param [attributes and values array] |
||
721 | */ |
||
722 | public function setColumnOrder($columns) |
||
726 | |||
727 | // ALIAS of setColumnOrder($columns) |
||
728 | public function setColumnsOrder($columns) { $this->setColumnOrder($columns); } |
||
729 | |||
730 | |||
731 | // ------------ |
||
732 | // FIELDS |
||
733 | // ------------ |
||
734 | |||
735 | /** |
||
736 | * Add a field to the create/update form or both. |
||
737 | * @param [string] $name Field name (the column name in the db in most cases) |
||
738 | * @param [array] $options Field-type-specific information. |
||
739 | * @param string $form The form to add the field to (create/update/both) |
||
740 | */ |
||
741 | public function addField($field, $form='both') |
||
778 | |||
779 | public function addFields($fields, $form='both') |
||
787 | |||
788 | /** |
||
789 | * Remove a certain field from the create/update/both forms by its name. |
||
790 | * @param string $name Field name (as defined with the addField() procedure) |
||
791 | * @param string $form update/create/both |
||
792 | */ |
||
793 | public function removeField($name, $form='both') |
||
810 | |||
811 | /** |
||
812 | * Remove many fields from the create/update/both forms by their name. |
||
813 | * @param array $array_of_names A simple array of the names of the fields to be removed. |
||
814 | * @param string $form update/create/both |
||
815 | */ |
||
816 | public function removeFields($array_of_names, $form='both') |
||
824 | |||
825 | // TODO: $this->crud->replaceField('name', 'update/create/both'); |
||
826 | |||
827 | // TODO: $this->crud->setRequiredFields(['field_1', 'field_2'], 'update/create/both'); |
||
828 | // TODO: $this->crud->setRequiredField('field_1', 'update/create/both'); |
||
829 | // TODO: $this->crud->getRequiredFields(); |
||
830 | |||
831 | // TODO: $this->crud->setFieldOrder(['field_1', 'field_2', 'field_3'], 'update/create/both'); |
||
832 | |||
833 | |||
834 | /** |
||
835 | * Check if field is the first of its type in the given fields array. |
||
836 | * It's used in each field_type.blade.php to determine wether to push the css and js content or not (we only need to push the js and css for a field the first time it's loaded in the form, not any subsequent times). |
||
837 | * |
||
838 | * @param array $field The current field being tested if it's the first of its type. |
||
839 | * @param array $fields_array All the fields in that particular form. |
||
840 | * @return bool true/false |
||
841 | */ |
||
842 | public function checkIfFieldIsFirstOfItsType($field, $fields_array) { |
||
848 | |||
849 | |||
850 | /** |
||
851 | * Order the fields in a certain way. |
||
852 | * |
||
853 | * @param [string] Column name. |
||
854 | * @param [attributes and values array] |
||
855 | */ |
||
856 | public function setFieldOrder($fields) |
||
860 | |||
861 | // ALIAS of setFieldOrder($fields) |
||
862 | public function setFieldsOrder($fields) { $this->setFieldOrder($fields); } |
||
863 | |||
864 | |||
865 | // ---------------- |
||
866 | // ADVANCED QUERIES |
||
867 | // ---------------- |
||
868 | |||
869 | |||
870 | /** |
||
871 | * Add another clause to the query (for ex, a WHERE clause). |
||
872 | * |
||
873 | * Examples: |
||
874 | * // $this->crud->addClause('active'); |
||
875 | * $this->crud->addClause('type', 'car'); |
||
876 | * $this->crud->addClause('where', 'name', '==', 'car'); |
||
877 | * $this->crud->addClause('whereName', 'car'); |
||
878 | * $this->crud->addClause('whereHas', 'posts', function($query) { |
||
879 | * $query->activePosts(); |
||
880 | * }); |
||
881 | * |
||
882 | * @param [type] |
||
883 | */ |
||
884 | public function addClause($function) |
||
888 | |||
889 | /** |
||
890 | * Order the results of the query in a certain way. |
||
891 | * |
||
892 | * @param [type] |
||
893 | * @param string |
||
894 | * @return [type] |
||
895 | */ |
||
896 | public function orderBy($field, $order = 'asc') |
||
900 | |||
901 | /** |
||
902 | * Group the results of the query in a certain way. |
||
903 | * |
||
904 | * @param [type] |
||
905 | * @return [type] |
||
906 | */ |
||
907 | public function groupBy($field) |
||
911 | |||
912 | /** |
||
913 | * Limit the number of results in the query. |
||
914 | * |
||
915 | * @param [number] |
||
916 | * @return [type] |
||
917 | */ |
||
918 | public function limit($number) |
||
922 | |||
923 | |||
924 | |||
925 | // ------------ |
||
926 | // BUTTONS |
||
927 | // ------------ |
||
928 | |||
929 | // TODO: $this->crud->setButtons(); // default includes edit and delete, with their name, icon, permission, link and class (btn-default) |
||
930 | // TODO: $this->crud->addButton(); |
||
931 | // TODO: $this->crud->removeButton(); |
||
932 | // TODO: $this->crud->replaceButton(); |
||
933 | |||
934 | |||
935 | |||
936 | // ------------------------------------------------------ |
||
937 | // AUTO-SET-FIELDS-AND-COLUMNS FUNCTIONALITY |
||
938 | // ------------------------------------------------------ |
||
939 | |||
940 | |||
941 | /** |
||
942 | * For a simple CRUD Panel, there should be no need to add/define the fields. |
||
943 | * The public columns in the database will be converted to be fields. |
||
944 | * |
||
945 | */ |
||
946 | public function setFromDb() |
||
975 | |||
976 | |||
977 | /** |
||
978 | * Get all columns from the database for that table. |
||
979 | * |
||
980 | * @return [array] |
||
981 | */ |
||
982 | public function getDbColumnTypes() |
||
991 | |||
992 | |||
993 | /** |
||
994 | * Intuit a field type, judging from the database column type. |
||
995 | * |
||
996 | * @param [string] Field name. |
||
997 | * @return [string] Fielt type. |
||
998 | */ |
||
999 | public function getFieldTypeFromDbColumnType($field) |
||
1053 | |||
1054 | |||
1055 | /** |
||
1056 | * Turn a database column name or PHP variable into a pretty label to be shown to the user. |
||
1057 | * |
||
1058 | * @param [string] |
||
1059 | * @return [string] |
||
1060 | */ |
||
1061 | public function makeLabel($value) |
||
1065 | |||
1066 | |||
1067 | /** |
||
1068 | * Get the database column names, in order to figure out what fields/columns to show in the auto-fields-and-columns functionality. |
||
1069 | * |
||
1070 | * @return [array] Database column names as an array. |
||
1071 | */ |
||
1072 | public function getDbColumnsNames() |
||
1083 | |||
1084 | |||
1085 | |||
1086 | |||
1087 | |||
1088 | |||
1089 | |||
1090 | // ----------------- |
||
1091 | // Commodity methods |
||
1092 | // ----------------- |
||
1093 | |||
1094 | /** |
||
1095 | * Refactor the request array to something that can be passed to the model's create or update function. |
||
1096 | * The resulting array will only include the fields that are stored in the database and their values, |
||
1097 | * plus the '_token' and 'redirect_after_save' variables. |
||
1098 | * |
||
1099 | * @param Request $request - everything that was sent from the form, usually \Request::all() |
||
1100 | * @param String $form - create/update - to determine what fields should be compacted |
||
1101 | * @return array |
||
1102 | */ |
||
1103 | public function compactFakeFields($request, $form = 'create') |
||
1153 | |||
1154 | |||
1155 | /** |
||
1156 | * Returns an array of database columns names, that are used to store fake values. |
||
1157 | * Returns ['extras'] if no columns have been found. |
||
1158 | * |
||
1159 | */ |
||
1160 | public function getFakeColumnsAsArray($form = 'create') |
||
1199 | |||
1200 | |||
1201 | |||
1202 | |||
1203 | |||
1204 | |||
1205 | |||
1206 | |||
1207 | // ---------------------------------- |
||
1208 | // Miscellaneous functions or methods |
||
1209 | // ---------------------------------- |
||
1210 | |||
1211 | |||
1212 | /** |
||
1213 | * Return the first element in an array that has the given 'type' attribute. |
||
1214 | * @param string $type |
||
1215 | * @param array $array |
||
1216 | * @return array |
||
1217 | */ |
||
1218 | public function getFirstOfItsTypeInArray($type, $array) |
||
1224 | |||
1225 | |||
1226 | |||
1227 | |||
1228 | |||
1229 | |||
1230 | |||
1231 | |||
1232 | |||
1233 | |||
1234 | |||
1235 | // ------------ |
||
1236 | // TONE FUNCTIONS - UNDOCUMENTED, UNTESTED, SOME MAY BE USED IN THIS FILE |
||
1237 | // ------------ |
||
1238 | // |
||
1239 | // TODO: |
||
1240 | // - figure out if they are really needed |
||
1241 | // - comments inside the function to explain how they work |
||
1242 | // - write docblock for them |
||
1243 | // - place in the correct section above (CREATE, READ, UPDATE, DELETE, ACCESS, MANIPULATION) |
||
1244 | |||
1245 | |||
1246 | |||
1247 | public function addButton($button) |
||
1251 | |||
1252 | public function buttons() |
||
1256 | |||
1257 | public function addCustomButton($button) |
||
1261 | |||
1262 | public function customButtons() |
||
1266 | |||
1267 | public function showButtons() |
||
1271 | |||
1272 | public function initButtons() |
||
1281 | |||
1282 | public function removeButtons($buttons) |
||
1291 | |||
1292 | |||
1293 | |||
1294 | |||
1295 | |||
1296 | |||
1297 | |||
1298 | |||
1299 | public function getColumns() |
||
1303 | |||
1304 | public function orderColumns($order) |
||
1308 | |||
1309 | |||
1310 | |||
1311 | |||
1312 | |||
1313 | |||
1314 | public function setFields($fields) |
||
1318 | |||
1319 | // [name, label, value, default, type, required, hint, values[id => value], attributes[class, id, data-, for editor: data-config="basic|medium|full"], callback => [$this, 'methodName'], callback_create => [$this, 'methodName'], callback_edit => [$this, 'methodName'], callback_view => [$this, 'methodName']] |
||
1320 | // public function addField($field) |
||
1321 | // { |
||
1322 | // return $this->add('fields', $field); |
||
1323 | // } |
||
1324 | |||
1325 | public function updateFields($fields, $attributes) |
||
1329 | |||
1330 | // public function removeFields($fields) |
||
1331 | // { |
||
1332 | // $this->fields = $this->remove('fields', $fields); |
||
1333 | // $this->removeColumns($fields); |
||
1334 | // } |
||
1335 | |||
1336 | public function setCreateFields($fields) |
||
1340 | |||
1341 | public function addCreateField($field) |
||
1345 | |||
1346 | public function setUpdateFields($fields) |
||
1350 | |||
1351 | public function addUpdateField($field) |
||
1355 | |||
1356 | public function fields() |
||
1378 | |||
1379 | public function orderFields($order) |
||
1383 | |||
1384 | |||
1385 | // public function syncField($field) |
||
1386 | // { |
||
1387 | // if (array_key_exists('name', (array)$field)) |
||
1388 | // return array_merge(['type' => $this->getFieldTypeFromDbColumnType($field['name']), 'value' => '', 'default' => null, 'values' => [], 'attributes' => []], $field); |
||
1389 | |||
1390 | // return false; |
||
1391 | // } |
||
1392 | |||
1393 | |||
1394 | |||
1395 | |||
1396 | |||
1397 | // iti pune valorile pe field-uri la EDIT |
||
1398 | public function addFieldsValue() |
||
1411 | |||
1412 | // public function add($entity, $field) |
||
1413 | // { |
||
1414 | // return array_filter($this->{$entity}[] = $this->syncField($field)); |
||
1415 | // } |
||
1416 | |||
1417 | public function addMultiple($entity, $field) |
||
1421 | |||
1422 | public function sync($type, $fields, $attributes) |
||
1433 | |||
1434 | |||
1435 | |||
1436 | // public function remove($entity, $fields) |
||
1437 | // { |
||
1438 | // return array_values(array_filter($this->{$entity}, function($field) use ($fields) { return !in_array($field['name'], (array)$fields);})); |
||
1439 | // } |
||
1440 | |||
1441 | public function setSort($items, $order) |
||
1445 | |||
1446 | public function sort($items) |
||
1462 | |||
1463 | |||
1464 | |||
1465 | |||
1466 | |||
1467 | // cred ca ia valorile din tabela de legatura ca sa ti le afiseze in select |
||
1468 | public function getRelationValues($model, $field, $where = [], $order = []) |
||
1479 | |||
1480 | // face un fel de merge intre ce ii dai si ce e in CRUD |
||
1481 | public function syncRelations($entity) |
||
1488 | |||
1489 | |||
1490 | |||
1491 | } |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.