We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
1 | <?php |
||
25 | class CrudPanel |
||
26 | { |
||
27 | use Create, Read, Update, Delete, Errors, Reorder, Access, Columns, Fields, Query, Buttons, AutoSet, FakeFields, FakeColumns, ViewsAndRestoresRevisions, AutoFocus, Filters, Tabs, Views; |
||
28 | |||
29 | // -------------- |
||
30 | // CRUD variables |
||
31 | // -------------- |
||
32 | // These variables are passed to the CRUD views, inside the $crud variable. |
||
33 | // All variables are public, so they can be modified from your EntityCrudController. |
||
34 | // All functions and methods are also public, so they can be used in your EntityCrudController to modify these variables. |
||
35 | |||
36 | // TODO: translate $entity_name and $entity_name_plural by default, with english fallback |
||
37 | |||
38 | public $model = "\App\Models\Entity"; // what's the namespace for your entity's model |
||
39 | public $route; // what route have you defined for your entity? used for links. |
||
40 | public $entity_name = 'entry'; // what name will show up on the buttons, in singural (ex: Add entity) |
||
41 | public $entity_name_plural = 'entries'; // what name will show up on the buttons, in plural (ex: Delete 5 entities) |
||
42 | public $request; |
||
43 | |||
44 | public $access = ['list', 'create', 'update', 'delete'/* 'revisions', reorder', 'show', 'details_row' */]; |
||
45 | |||
46 | public $reorder = false; |
||
47 | public $reorder_label = false; |
||
48 | public $reorder_max_level = 3; |
||
49 | |||
50 | public $details_row = false; |
||
51 | public $ajax_table = false; |
||
52 | public $export_buttons = false; |
||
53 | |||
54 | public $columns = []; // Define the columns for the table view as an array; |
||
55 | public $create_fields = []; // Define the fields for the "Add new entry" view as an array; |
||
56 | public $update_fields = []; // Define the fields for the "Edit entry" view as an array; |
||
57 | |||
58 | public $query; |
||
59 | public $entry; |
||
60 | public $buttons; |
||
61 | public $db_column_types = []; |
||
62 | public $default_page_length = false; |
||
63 | |||
64 | // TONE FIELDS - TODO: find out what he did with them, replicate or delete |
||
65 | public $sort = []; |
||
66 | |||
67 | // The following methods are used in CrudController or your EntityCrudController to manipulate the variables above. |
||
68 | |||
69 | public function __construct() |
||
70 | { |
||
71 | $this->setErrorDefaults(); |
||
72 | $this->initButtons(); |
||
73 | } |
||
74 | |||
75 | // ------------------------------------------------------ |
||
76 | // BASICS - model, route, entity_name, entity_name_plural |
||
77 | // ------------------------------------------------------ |
||
78 | |||
79 | /** |
||
80 | * This function binds the CRUD to its corresponding Model (which extends Eloquent). |
||
81 | * All Create-Read-Update-Delete operations are done using that Eloquent Collection. |
||
82 | * |
||
83 | * @param [string] Full model namespace. Ex: App\Models\Article |
||
84 | */ |
||
85 | public function setModel($model_namespace) |
||
86 | { |
||
87 | if (! class_exists($model_namespace)) { |
||
88 | throw new \Exception('This model does not exist.', 404); |
||
89 | } |
||
90 | |||
91 | $this->model = new $model_namespace(); |
||
92 | $this->query = $this->model->select('*'); |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * Get the corresponding Eloquent Model for the CrudController, as defined with the setModel() function;. |
||
97 | * |
||
98 | * @return [Eloquent Collection] |
||
99 | */ |
||
100 | public function getModel() |
||
101 | { |
||
102 | return $this->model; |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * Set the route for this CRUD. |
||
107 | * Ex: admin/article. |
||
108 | * |
||
109 | * @param [string] Route name. |
||
110 | * @param [array] Parameters. |
||
111 | */ |
||
112 | public function setRoute($route) |
||
113 | { |
||
114 | $this->route = $route; |
||
115 | } |
||
116 | |||
117 | /** |
||
118 | * Set the route for this CRUD using the route name. |
||
119 | * Ex: admin.article. |
||
120 | * |
||
121 | * @param [string] Route name. |
||
122 | * @param [array] Parameters. |
||
123 | */ |
||
124 | public function setRouteName($route, $parameters = []) |
||
135 | |||
136 | /** |
||
137 | * Get the current CrudController route. |
||
138 | * |
||
139 | * Can be defined in the CrudController with: |
||
140 | * - $this->crud->setRoute(config('backpack.base.route_prefix').'/article') |
||
141 | * - $this->crud->setRouteName(config('backpack.base.route_prefix').'.article') |
||
142 | * - $this->crud->route = config('backpack.base.route_prefix')."/article" |
||
143 | * |
||
144 | * @return [string] |
||
145 | */ |
||
146 | public function getRoute() |
||
150 | |||
151 | /** |
||
152 | * Set the entity name in singular and plural. |
||
153 | * Used all over the CRUD interface (header, add button, reorder button, breadcrumbs). |
||
154 | * |
||
155 | * @param [string] Entity name, in singular. Ex: article |
||
156 | * @param [string] Entity name, in plural. Ex: articles |
||
157 | */ |
||
158 | public function setEntityNameStrings($singular, $plural) |
||
163 | |||
164 | // ---------------------------------- |
||
165 | // Miscellaneous functions or methods |
||
166 | // ---------------------------------- |
||
167 | |||
168 | /** |
||
169 | * Return the first element in an array that has the given 'type' attribute. |
||
170 | * |
||
171 | * @param string $type |
||
172 | * @param array $array |
||
173 | * |
||
174 | * @return array |
||
175 | */ |
||
176 | public function getFirstOfItsTypeInArray($type, $array) |
||
182 | |||
183 | // ------------ |
||
184 | // TONE FUNCTIONS - UNDOCUMENTED, UNTESTED, SOME MAY BE USED IN THIS FILE |
||
185 | // ------------ |
||
186 | // |
||
187 | // TODO: |
||
188 | // - figure out if they are really needed |
||
189 | // - comments inside the function to explain how they work |
||
190 | // - write docblock for them |
||
191 | // - place in the correct section above (CREATE, READ, UPDATE, DELETE, ACCESS, MANIPULATION) |
||
192 | |||
193 | public function sync($type, $fields, $attributes) |
||
205 | |||
206 | public function setSort($items, $order) |
||
210 | |||
211 | public function sort($items) |
||
229 | |||
230 | /** |
||
231 | * Get the Eloquent Model name from the given relation definition string. |
||
232 | * |
||
233 | * @example For a given string 'company' and a relation between App/Models/User and App/Models/Company, defined by a |
||
234 | * company() method on the user model, the 'App/Models/Company' string will be returned. |
||
235 | * |
||
236 | * @example For a given string 'company.address' and a relation between App/Models/User, App/Models/Company and |
||
237 | * App/Models/Address defined by a company() method on the user model and an address() method on the |
||
238 | * company model, the 'App/Models/Address' string will be returned. |
||
239 | * |
||
240 | * @param $relationString String Relation string. A dot notation can be used to chain multiple relations. |
||
241 | * |
||
242 | * @return string relation model name |
||
243 | */ |
||
244 | private function getRelationModel($relationString) |
||
252 | } |
||
253 |
This check marks property names that have not been written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes
databaseConnectionString
.