We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
1 | <?php |
||
28 | class CrudPanel |
||
29 | { |
||
30 | use Create, Read, Search, Update, Delete, Errors, Reorder, Access, Columns, Fields, Query, Buttons, AutoSet, FakeFields, FakeColumns, ViewsAndRestoresRevisions, AutoFocus, Filters, Tabs, Views, RequiredFields; |
||
31 | |||
32 | // -------------- |
||
33 | // CRUD variables |
||
34 | // -------------- |
||
35 | // These variables are passed to the CRUD views, inside the $crud variable. |
||
36 | // All variables are public, so they can be modified from your EntityCrudController. |
||
37 | // All functions and methods are also public, so they can be used in your EntityCrudController to modify these variables. |
||
38 | |||
39 | // TODO: translate $entity_name and $entity_name_plural by default, with english fallback |
||
40 | |||
41 | public $model = "\App\Models\Entity"; // what's the namespace for your entity's model |
||
42 | public $route; // what route have you defined for your entity? used for links. |
||
43 | public $entity_name = 'entry'; // what name will show up on the buttons, in singural (ex: Add entity) |
||
44 | public $entity_name_plural = 'entries'; // what name will show up on the buttons, in plural (ex: Delete 5 entities) |
||
45 | public $request; |
||
46 | |||
47 | public $access = ['list', 'create', 'update', 'delete'/* 'revisions', reorder', 'show', 'details_row' */]; |
||
48 | |||
49 | public $reorder = false; |
||
50 | public $reorder_label = false; |
||
51 | public $reorder_max_level = 3; |
||
52 | |||
53 | public $details_row = false; |
||
54 | public $export_buttons = false; |
||
55 | |||
56 | public $columns = []; // Define the columns for the table view as an array; |
||
57 | public $create_fields = []; // Define the fields for the "Add new entry" view as an array; |
||
58 | public $update_fields = []; // Define the fields for the "Edit entry" view as an array; |
||
59 | |||
60 | public $query; |
||
61 | public $entry; |
||
62 | public $buttons; |
||
63 | public $db_column_types = []; |
||
64 | public $default_page_length = false; |
||
65 | public $page_length_menu = false; |
||
66 | |||
67 | // TONE FIELDS - TODO: find out what he did with them, replicate or delete |
||
68 | public $sort = []; |
||
69 | |||
70 | // The following methods are used in CrudController or your EntityCrudController to manipulate the variables above. |
||
71 | 159 | ||
72 | public function __construct() |
||
77 | |||
78 | // ------------------------------------------------------ |
||
79 | // BASICS - model, route, entity_name, entity_name_plural |
||
80 | // ------------------------------------------------------ |
||
81 | |||
82 | /** |
||
83 | * This function binds the CRUD to its corresponding Model (which extends Eloquent). |
||
84 | * All Create-Read-Update-Delete operations are done using that Eloquent Collection. |
||
85 | * |
||
86 | * @param string $model_namespace Full model namespace. Ex: App\Models\Article] |
||
87 | * |
||
88 | * @throws \Exception in case the model does not exist |
||
89 | 159 | */ |
|
90 | public function setModel($model_namespace) |
||
100 | |||
101 | /** |
||
102 | * Get the corresponding Eloquent Model for the CrudController, as defined with the setModel() function;. |
||
103 | * |
||
104 | * @return [Eloquent Collection] |
||
105 | 159 | */ |
|
106 | public function getModel() |
||
110 | |||
111 | /** |
||
112 | * Get the database connection, as specified in the .env file or overwritten by the property on the model. |
||
113 | 3 | */ |
|
114 | private function getSchema() |
||
118 | |||
119 | /** |
||
120 | * Set the route for this CRUD. |
||
121 | * Ex: admin/article. |
||
122 | * |
||
123 | * @param [string] Route name. |
||
124 | * @param [array] Parameters. |
||
125 | */ |
||
126 | public function setRoute($route) |
||
130 | |||
131 | /** |
||
132 | * Set the route for this CRUD using the route name. |
||
133 | * Ex: admin.article. |
||
134 | * |
||
135 | * @param [string] Route name. |
||
136 | * @param [array] Parameters. |
||
137 | 1 | */ |
|
138 | public function setRouteName($route, $parameters = []) |
||
149 | |||
150 | /** |
||
151 | * Get the current CrudController route. |
||
152 | * |
||
153 | * Can be defined in the CrudController with: |
||
154 | * - $this->crud->setRoute(config('backpack.base.route_prefix').'/article') |
||
155 | * - $this->crud->setRouteName(config('backpack.base.route_prefix').'.article') |
||
156 | * - $this->crud->route = config('backpack.base.route_prefix')."/article" |
||
157 | * |
||
158 | * @return [string] |
||
159 | */ |
||
160 | public function getRoute() |
||
164 | |||
165 | /** |
||
166 | * Set the entity name in singular and plural. |
||
167 | * Used all over the CRUD interface (header, add button, reorder button, breadcrumbs). |
||
168 | * |
||
169 | * @param [string] Entity name, in singular. Ex: article |
||
170 | * @param [string] Entity name, in plural. Ex: articles |
||
171 | */ |
||
172 | public function setEntityNameStrings($singular, $plural) |
||
177 | |||
178 | // ----------------------------------------------- |
||
179 | // ACTIONS - the current operation being processed |
||
180 | // ----------------------------------------------- |
||
181 | |||
182 | /** |
||
183 | * Get the action being performed by the controller, |
||
184 | * including middleware names, route name, method name, |
||
185 | * namespace, prefix, etc. |
||
186 | * |
||
187 | * @return string The EntityCrudController route action array. |
||
188 | */ |
||
189 | public function getAction() |
||
193 | 2 | ||
194 | /** |
||
195 | * Get the full name of the controller method |
||
196 | * currently being called (including namespace). |
||
197 | * |
||
198 | * @return string The EntityCrudController full method name with namespace. |
||
199 | */ |
||
200 | public function getActionName() |
||
204 | |||
205 | /** |
||
206 | * Get the name of the controller method |
||
207 | * currently being called. |
||
208 | * |
||
209 | * @return string The EntityCrudController method name. |
||
210 | */ |
||
211 | public function getActionMethod() |
||
215 | |||
216 | /** |
||
217 | * Check if the controller method being called |
||
218 | * matches a given string. |
||
219 | * |
||
220 | * @param string $methodName Name of the method (ex: index, create, update) |
||
221 | * @return bool Whether the condition is met or not. |
||
222 | */ |
||
223 | public function actionIs($methodName) |
||
227 | |||
228 | // ---------------------------------- |
||
229 | // Miscellaneous functions or methods |
||
230 | // ---------------------------------- |
||
231 | |||
232 | /** |
||
233 | * Return the first element in an array that has the given 'type' attribute. |
||
234 | * |
||
235 | * @param string $type |
||
236 | * @param array $array |
||
237 | * |
||
238 | * @return array |
||
239 | */ |
||
240 | public function getFirstOfItsTypeInArray($type, $array) |
||
246 | |||
247 | // ------------ |
||
248 | // TONE FUNCTIONS - UNDOCUMENTED, UNTESTED, SOME MAY BE USED IN THIS FILE |
||
249 | // ------------ |
||
250 | // |
||
251 | // TODO: |
||
252 | // - figure out if they are really needed |
||
253 | // - comments inside the function to explain how they work |
||
254 | // - write docblock for them |
||
255 | // - place in the correct section above (CREATE, READ, UPDATE, DELETE, ACCESS, MANIPULATION) |
||
256 | |||
257 | public function sync($type, $fields, $attributes) |
||
269 | 9 | ||
270 | /** |
||
271 | 9 | * @deprecated No longer used by internal code and not recommended. |
|
272 | 9 | */ |
|
273 | public function setSort($items, $order) |
||
277 | |||
278 | /** |
||
279 | 9 | * @deprecated No longer used by internal code and not recommended. |
|
280 | 9 | */ |
|
281 | 9 | public function sort($items) |
|
299 | |||
300 | /** |
||
301 | * Get the Eloquent Model name from the given relation definition string. |
||
302 | * |
||
303 | * @example For a given string 'company' and a relation between App/Models/User and App/Models/Company, defined by a |
||
304 | * company() method on the user model, the 'App/Models/Company' string will be returned. |
||
305 | * |
||
306 | * @example For a given string 'company.address' and a relation between App/Models/User, App/Models/Company and |
||
307 | * App/Models/Address defined by a company() method on the user model and an address() method on the |
||
308 | * company model, the 'App/Models/Address' string will be returned. |
||
309 | * |
||
310 | * @param string $relationString Relation string. A dot notation can be used to chain multiple relations. |
||
311 | * @param int $length Optionally specify the number of relations to omit from the start of the relation string. If |
||
312 | * the provided length is negative, then that many relations will be omitted from the end of the relation |
||
313 | * string. |
||
314 | * @param \Illuminate\Database\Eloquent\Model $model Optionally specify a different model than the one in the crud object. |
||
315 | * |
||
316 | * @return string Relation model name. |
||
317 | */ |
||
318 | public function getRelationModel($relationString, $length = null, $model = null) |
||
336 | |||
337 | /** |
||
338 | * Get the given attribute from a model or models resulting from the specified relation string (eg: the list of streets from |
||
339 | * the many addresses of the company of a given user). |
||
340 | * |
||
341 | * @param \Illuminate\Database\Eloquent\Model $model Model (eg: user). |
||
342 | * @param string $relationString Model relation. Can be a string representing the name of a relation method in the given |
||
343 | * Model or one from a different Model through multiple relations. A dot notation can be used to specify |
||
344 | * multiple relations (eg: user.company.address). |
||
345 | * @param string $attribute The attribute from the relation model (eg: the street attribute from the address model). |
||
346 | * |
||
347 | * @return array An array containing a list of attributes from the resulting model. |
||
348 | */ |
||
349 | public function getModelAttributeFromRelation($model, $relationString, $attribute) |
||
361 | |||
362 | /** |
||
363 | * Traverse the tree of relations for the given model, defined by the given relation string, and return the ending |
||
364 | * associated model instance or instances. |
||
365 | * |
||
366 | * @param \Illuminate\Database\Eloquent\Model $model The CRUD model. |
||
367 | * @param string $relationString Relation string. A dot notation can be used to chain multiple relations. |
||
368 | * @return array An array of the associated model instances defined by the relation string. |
||
369 | */ |
||
370 | private function getRelationModelInstances($model, $relationString) |
||
397 | } |
||
398 |
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
.