We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
@@ -4,12 +4,9 @@ |
||
4 | 4 | use Illuminate\Routing\Controller as BaseController; |
5 | 5 | use Illuminate\Foundation\Validation\ValidatesRequests; |
6 | 6 | use Illuminate\Http\Request; |
7 | -use Crypt; |
|
8 | -use Illuminate\Support\Facades\Form as Form; |
|
9 | 7 | use Alert; |
10 | 8 | |
11 | 9 | // VALIDATION: change the requests to match your own file names if you need form validation |
12 | -use Backpack\CRUD\app\Http\Requests\CrudRequest as StoreRequest; |
|
13 | 10 | use Backpack\CRUD\app\Http\Requests\CrudRequest as UpdateRequest; |
14 | 11 | |
15 | 12 | class CrudController extends BaseController { |
@@ -14,579 +14,579 @@ |
||
14 | 14 | |
15 | 15 | class CrudController extends BaseController { |
16 | 16 | |
17 | - use DispatchesJobs, ValidatesRequests; |
|
18 | - |
|
19 | - public $data = array(); |
|
20 | - public $crud = array( |
|
21 | - "model" => "\App\Models\Entity", |
|
22 | - "entity_name" => "entry", |
|
23 | - "entity_name_plural" => "entries", |
|
24 | - "view_table_permission" => true, |
|
25 | - "add_permission" => true, |
|
26 | - "edit_permission" => true, |
|
27 | - "delete_permission" => true, |
|
28 | - "reorder_permission" => true, |
|
29 | - "reorder_max_level" => 3, |
|
30 | - "details_row" => false, |
|
31 | - ); |
|
32 | - |
|
33 | - public function __construct() |
|
34 | - { |
|
35 | - $this->data['crud'] = $this->crud; |
|
36 | - } |
|
37 | - |
|
38 | - /** |
|
39 | - * Display all rows in the database for this entity. |
|
40 | - * |
|
41 | - * @return Response |
|
42 | - */ |
|
43 | - public function index() |
|
44 | - { |
|
45 | - // SECURITY: |
|
46 | - // if view_table_permission is false, abort |
|
47 | - if (isset($this->crud['view_table_permission']) && !$this->crud['view_table_permission']) { |
|
48 | - abort(403, 'Not allowed.'); |
|
49 | - } |
|
50 | - |
|
51 | - // get all results for that entity |
|
52 | - $model = $this->crud['model']; |
|
53 | - if (property_exists($model, 'translatable')) |
|
54 | - { |
|
55 | - $this->data['entries'] = $model::where('translation_lang', \Lang::locale())->get(); |
|
56 | - } else |
|
57 | - { |
|
58 | - $this->data['entries'] = $model::all(); |
|
59 | - } |
|
60 | - |
|
61 | - // add the fake fields for each entry |
|
62 | - foreach ($this->data['entries'] as $key => $entry) { |
|
63 | - $entry->addFakes($this->getFakeColumnsAsArray()); |
|
64 | - } |
|
65 | - |
|
66 | - $this->prepareColumns(); |
|
67 | - $this->data['crud'] = $this->crud; |
|
68 | - $this->data['title'] = ucfirst($this->crud['entity_name_plural']); |
|
69 | - |
|
70 | - // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package |
|
71 | - return view('crud::list', $this->data); |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * Show the form for creating inserting a new row. |
|
77 | - * |
|
78 | - * @return Response |
|
79 | - */ |
|
80 | - public function create() |
|
81 | - { |
|
82 | - // SECURITY: |
|
83 | - // if add_permission is false, abort |
|
84 | - if (isset($this->crud['add_permission']) && !$this->crud['add_permission']) { |
|
85 | - abort(403, 'Not allowed.'); |
|
86 | - } |
|
87 | - |
|
88 | - // get the fields you need to show |
|
89 | - if (isset($this->data['crud']['create_fields'])) |
|
90 | - { |
|
91 | - $this->crud['fields'] = $this->data['crud']['create_fields']; |
|
92 | - } |
|
93 | - |
|
94 | - // prepare the fields you need to show |
|
95 | - $this->prepareFields(); |
|
96 | - $this->data['crud'] = $this->crud; |
|
97 | - $this->data['title'] = trans('backpack::crud.add').' '.$this->crud['entity_name']; |
|
98 | - |
|
99 | - // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package |
|
100 | - return view('crud::create', $this->data); |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * Store a newly created resource in the database. |
|
106 | - * |
|
107 | - * @param StoreRequest $request - type injection used for validation using Requests |
|
108 | - * @return \Illuminate\Http\RedirectResponse |
|
109 | - */ |
|
110 | - public function storeCrud(StoreRequest $request = null) |
|
111 | - { |
|
112 | - // SECURITY: |
|
113 | - // if add_permission is false, abort |
|
114 | - if (isset($this->crud['add_permission']) && !$this->crud['add_permission']) { |
|
115 | - abort(403, 'Not allowed.'); |
|
116 | - } |
|
117 | - |
|
118 | - // compress the fake fields into one field |
|
119 | - $model = $this->crud['model']; |
|
120 | - $values_to_store = $this->compactFakeFields(\Request::all()); |
|
121 | - $item = $model::create($values_to_store); |
|
122 | - |
|
123 | - // if it's a relationship with a pivot table, also sync that |
|
124 | - $this->prepareFields(); |
|
125 | - foreach ($this->crud['fields'] as $k => $field) { |
|
126 | - if (isset($field['pivot']) && $field['pivot'] == true && \Request::has($field['name'])) |
|
127 | - { |
|
128 | - $model::find($item->id)->$field['name']()->attach(\Request::input($field['name'])); |
|
129 | - } |
|
130 | - } |
|
131 | - |
|
132 | - // show a success message |
|
133 | - \Alert::success(trans('backpack::crud.insert_success'))->flash(); |
|
134 | - |
|
135 | - // redirect the user where he chose to be redirected |
|
136 | - switch (\Request::input('redirect_after_save')) { |
|
137 | - case 'current_item_edit': |
|
138 | - return \Redirect::to($this->crud['route'].'/'.$item->id.'/edit'); |
|
139 | - |
|
140 | - default: |
|
141 | - return \Redirect::to(\Request::input('redirect_after_save')); |
|
142 | - } |
|
143 | - } |
|
144 | - |
|
145 | - |
|
146 | - /** |
|
147 | - * Show the form for editing the specified resource. |
|
148 | - * |
|
149 | - * @param int $id |
|
150 | - * @return Response |
|
151 | - */ |
|
152 | - public function edit($id) |
|
153 | - { |
|
154 | - // SECURITY: |
|
155 | - // if edit_permission is false, abort |
|
156 | - if (isset($this->crud['edit_permission']) && !$this->crud['edit_permission']) { |
|
157 | - abort(403, 'Not allowed.'); |
|
158 | - } |
|
159 | - |
|
160 | - // get the info for that entry |
|
161 | - $model = $this->crud['model']; |
|
162 | - $this->data['entry'] = $model::find($id); |
|
163 | - $this->data['entry']->addFakes($this->getFakeColumnsAsArray()); |
|
164 | - |
|
165 | - if (isset($this->data['crud']['update_fields'])) |
|
166 | - { |
|
167 | - $this->crud['fields'] = $this->data['crud']['update_fields']; |
|
168 | - } |
|
169 | - |
|
170 | - // prepare the fields you need to show and prepopulate the values |
|
171 | - $this->prepareFields($this->data['entry']); |
|
172 | - $this->data['crud'] = $this->crud; |
|
173 | - $this->data['title'] = trans('backpack::crud.edit').' '.$this->crud['entity_name']; |
|
174 | - |
|
175 | - // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package |
|
176 | - return view('crud::edit', $this->data); |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - /** |
|
181 | - * Update the specified resource in the database. |
|
182 | - * |
|
183 | - * @param UpdateRequest $request - type injection used for validation using Requests |
|
184 | - * @return \Illuminate\Http\RedirectResponse |
|
185 | - */ |
|
186 | - public function updateCrud(UpdateRequest $request = null) |
|
187 | - { |
|
188 | - // if edit_permission is false, abort |
|
189 | - if (isset($this->crud['edit_permission']) && !$this->crud['edit_permission']) { |
|
190 | - abort(403, 'Not allowed.'); |
|
191 | - } |
|
192 | - |
|
193 | - $model = $this->crud['model']; |
|
194 | - $this->prepareFields($model::find(\Request::input('id'))); |
|
195 | - |
|
196 | - $model::find(\Request::input('id'))->update($this->compactFakeFields(\Request::all())); |
|
197 | - |
|
198 | - // if it's a relationship with a pivot table, also sync that |
|
199 | - foreach ($this->crud['fields'] as $k => $field) { |
|
200 | - if (isset($field['pivot']) && $field['pivot'] == true && \Request::has($field['name'])) |
|
201 | - { |
|
202 | - $model::find(\Request::input('id'))->$field['name']()->sync(\Request::input($field['name'])); |
|
203 | - } |
|
204 | - } |
|
205 | - |
|
206 | - // show a success message |
|
207 | - \Alert::success(trans('backpack::crud.update_success'))->flash(); |
|
208 | - |
|
209 | - return \Redirect::to($this->crud['route']); |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - /** |
|
214 | - * Display the specified resource. |
|
215 | - * |
|
216 | - * @param int $id |
|
217 | - * @return Response |
|
218 | - */ |
|
219 | - public function show($id) |
|
220 | - { |
|
221 | - // get the info for that entry |
|
222 | - $model = $this->crud['model']; |
|
223 | - $this->data['entry'] = $model::find($id); |
|
224 | - $this->data['entry']->addFakes($this->getFakeColumnsAsArray()); |
|
225 | - $this->data['crud'] = $this->crud; |
|
226 | - $this->data['title'] = trans('backpack::crud.preview').' '.$this->crud['entity_name']; |
|
227 | - |
|
228 | - // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package |
|
229 | - return view('crud::show', $this->data); |
|
230 | - } |
|
231 | - |
|
232 | - |
|
233 | - /** |
|
234 | - * Remove the specified resource from storage. |
|
235 | - * |
|
236 | - * @param int $id |
|
237 | - * @return string |
|
238 | - */ |
|
239 | - public function destroy($id) |
|
240 | - { |
|
241 | - // SECURITY: |
|
242 | - // if delete_permission is false, abort |
|
243 | - if (isset($this->crud['delete_permission']) && !$this->crud['delete_permission']) { |
|
244 | - abort(403, trans('backpack::crud.unauthorized_access')); |
|
245 | - } |
|
246 | - |
|
247 | - $model = $this->crud['model']; |
|
248 | - $item = $model::find($id); |
|
249 | - $item->delete(); |
|
250 | - |
|
251 | - return 'true'; |
|
252 | - } |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * Reorder the items in the database using the Nested Set pattern. |
|
257 | - * |
|
258 | - * Database columns needed: id, parent_id, lft, rgt, depth, name/title |
|
259 | - * |
|
260 | - * @return Response |
|
261 | - */ |
|
262 | - public function reorder($lang = false) |
|
263 | - { |
|
264 | - // if reorder_table_permission is false, abort |
|
265 | - if (isset($this->crud['reorder_permission']) && !$this->crud['reorder_permission']) { |
|
266 | - abort(403, 'Not allowed.'); |
|
267 | - } |
|
268 | - |
|
269 | - if ($lang == false) |
|
270 | - { |
|
271 | - $lang = \Lang::locale(); |
|
272 | - } |
|
273 | - |
|
274 | - // get all results for that entity |
|
275 | - $model = $this->crud['model']; |
|
276 | - if (property_exists($model, 'translatable')) |
|
277 | - { |
|
278 | - $this->data['entries'] = $model::where('translation_lang', $lang)->get(); |
|
279 | - $this->data['languages'] = \Backpack\LangFileManager\app\Models\Language::all(); |
|
280 | - $this->data['active_language'] = $lang; |
|
281 | - } else |
|
282 | - { |
|
283 | - $this->data['entries'] = $model::all(); |
|
284 | - } |
|
285 | - $this->data['crud'] = $this->crud; |
|
286 | - $this->data['title'] = trans('backpack::crud.reorder').' '.$this->crud['entity_name']; |
|
287 | - |
|
288 | - // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package |
|
289 | - return view('crud::reorder', $this->data); |
|
290 | - } |
|
291 | - |
|
292 | - |
|
293 | - /** |
|
294 | - * Save the new order, using the Nested Set pattern. |
|
295 | - * |
|
296 | - * Database columns needed: id, parent_id, lft, rgt, depth, name/title |
|
297 | - * |
|
298 | - * @return |
|
299 | - */ |
|
300 | - public function saveReorder() |
|
301 | - { |
|
302 | - // if reorder_table_permission is false, abort |
|
303 | - if (isset($this->crud['reorder_permission']) && !$this->crud['reorder_permission']) { |
|
304 | - abort(403, 'Not allowed.'); |
|
305 | - } |
|
306 | - |
|
307 | - $model = $this->crud['model']; |
|
308 | - $count = 0; |
|
309 | - $all_entries = \Request::input('tree'); |
|
310 | - |
|
311 | - if (count($all_entries)) { |
|
312 | - foreach ($all_entries as $key => $entry) { |
|
313 | - if ($entry['item_id'] != "" && $entry['item_id'] != null) { |
|
314 | - $item = $model::find($entry['item_id']); |
|
315 | - $item->parent_id = $entry['parent_id']; |
|
316 | - $item->depth = $entry['depth']; |
|
317 | - $item->lft = $entry['left']; |
|
318 | - $item->rgt = $entry['right']; |
|
319 | - $item->save(); |
|
320 | - |
|
321 | - $count++; |
|
322 | - } |
|
323 | - } |
|
324 | - } else |
|
325 | - { |
|
326 | - return false; |
|
327 | - } |
|
328 | - |
|
329 | - return 'success for '.$count." items"; |
|
330 | - } |
|
331 | - |
|
332 | - |
|
333 | - /** |
|
334 | - * Used with AJAX in the list view (datatables) to show extra information about that row that didn't fit in the table. |
|
335 | - * It defaults to showing all connected translations and their CRUD buttons. |
|
336 | - * |
|
337 | - * It's enabled by: |
|
338 | - * - setting the $crud['details_row'] variable to true; |
|
339 | - * - adding the details route for the entity; ex: Route::get('page/{id}/details', 'PageCrudController@showDetailsRow'); |
|
340 | - */ |
|
341 | - public function showDetailsRow($id) |
|
342 | - { |
|
343 | - // get the info for that entry |
|
344 | - $model = $this->crud['model']; |
|
345 | - $this->data['entry'] = $model::find($id); |
|
346 | - $this->data['entry']->addFakes($this->getFakeColumnsAsArray()); |
|
347 | - $this->data['original_entry'] = $this->data['entry']; |
|
348 | - $this->data['crud'] = $this->crud; |
|
349 | - |
|
350 | - if (property_exists($model, 'translatable')) |
|
351 | - { |
|
352 | - $this->data['translations'] = $this->data['entry']->translations(); |
|
353 | - |
|
354 | - // create a list of languages the item is not translated in |
|
355 | - $this->data['languages'] = \Backpack\LangFileManager\app\Models\Language::all(); |
|
356 | - $this->data['languages_already_translated_in'] = $this->data['entry']->translationLanguages(); |
|
357 | - $this->data['languages_to_translate_in'] = $this->data['languages']->diff($this->data['languages_already_translated_in']); |
|
358 | - $this->data['languages_to_translate_in'] = $this->data['languages_to_translate_in']->reject(function($item) { |
|
359 | - return $item->abbr == \Lang::locale(); |
|
360 | - }); |
|
361 | - } |
|
362 | - |
|
363 | - // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package |
|
364 | - return view('crud::details_row', $this->data); |
|
365 | - } |
|
366 | - |
|
367 | - |
|
368 | - /** |
|
369 | - * Duplicate an existing item into another language and open it for editing. |
|
370 | - */ |
|
371 | - public function translateItem($id, $lang) |
|
372 | - { |
|
373 | - $model = $this->crud['model']; |
|
374 | - $this->data['entry'] = $model::find($id); |
|
375 | - // check if there isn't a translation already |
|
376 | - $existing_translation = $this->data['entry']->translation($lang); |
|
377 | - |
|
378 | - if ($existing_translation) |
|
379 | - { |
|
380 | - $new_entry = $existing_translation; |
|
381 | - } else |
|
382 | - { |
|
383 | - // get the info for that entry |
|
384 | - $new_entry_attributes = $this->data['entry']->getAttributes(); |
|
385 | - $new_entry_attributes['translation_lang'] = $lang; |
|
386 | - $new_entry_attributes['translation_of'] = $id; |
|
387 | - $new_entry_attributes = array_except($new_entry_attributes, 'id'); |
|
388 | - |
|
389 | - $new_entry = $model::create($new_entry_attributes); |
|
390 | - } |
|
391 | - |
|
392 | - // redirect to the edit form for that translation |
|
393 | - return redirect(str_replace($id, $new_entry->id, str_replace('translate/'.$lang, 'edit', \Request::url()))); |
|
394 | - } |
|
395 | - |
|
396 | - |
|
397 | - |
|
398 | - /** |
|
399 | - * COMMODITY FUNCTIONS |
|
400 | - */ |
|
401 | - |
|
402 | - |
|
403 | - /** |
|
404 | - * Refactor the request array to something that can be passed to the model's create or update function. |
|
405 | - * The resulting array will only include the fields that are stored in the database and their values, |
|
406 | - * plus the '_token' and 'redirect_after_save' variables. |
|
407 | - * |
|
408 | - * @param Request $request - everything that was sent from the form, usually \Request::all() |
|
409 | - * @return array |
|
410 | - */ |
|
411 | - protected function compactFakeFields($request) { |
|
412 | - |
|
413 | - $this->prepareFields(); |
|
414 | - |
|
415 | - $fake_field_columns_to_encode = []; |
|
416 | - |
|
417 | - // go through each defined field |
|
418 | - foreach ($this->crud['fields'] as $k => $field) { |
|
419 | - // if it's a fake field |
|
420 | - if (isset($this->crud['fields'][$k]['fake']) && $this->crud['fields'][$k]['fake'] == true) { |
|
421 | - // add it to the request in its appropriate variable - the one defined, if defined |
|
422 | - if (isset($this->crud['fields'][$k]['store_in'])) { |
|
423 | - $request[$this->crud['fields'][$k]['store_in']][$this->crud['fields'][$k]['name']] = $request[$this->crud['fields'][$k]['name']]; |
|
424 | - |
|
425 | - $remove_fake_field = array_pull($request, $this->crud['fields'][$k]['name']); |
|
426 | - if (!in_array($this->crud['fields'][$k]['store_in'], $fake_field_columns_to_encode, true)) { |
|
427 | - array_push($fake_field_columns_to_encode, $this->crud['fields'][$k]['store_in']); |
|
428 | - } |
|
429 | - } else //otherwise in the one defined in the $crud variable |
|
430 | - { |
|
431 | - $request['extras'][$this->crud['fields'][$k]['name']] = $request[$this->crud['fields'][$k]['name']]; |
|
432 | - |
|
433 | - $remove_fake_field = array_pull($request, $this->crud['fields'][$k]['name']); |
|
434 | - if (!in_array('extras', $fake_field_columns_to_encode, true)) { |
|
435 | - array_push($fake_field_columns_to_encode, 'extras'); |
|
436 | - } |
|
437 | - } |
|
438 | - } |
|
439 | - } |
|
440 | - |
|
441 | - // json_encode all fake_value columns in the database, so they can be properly stored and interpreted |
|
442 | - if (count($fake_field_columns_to_encode)) { |
|
443 | - foreach ($fake_field_columns_to_encode as $key => $value) { |
|
444 | - $request[$value] = json_encode($request[$value]); |
|
445 | - } |
|
446 | - } |
|
447 | - |
|
448 | - // if there are no fake fields defined, this will just return the original Request in full |
|
449 | - // since no modifications or additions have been made to $request |
|
450 | - return $request; |
|
451 | - } |
|
452 | - |
|
453 | - |
|
454 | - /** |
|
455 | - * Returns an array of database columns names, that are used to store fake values. |
|
456 | - * Returns ['extras'] if no columns have been found. |
|
457 | - * |
|
458 | - */ |
|
459 | - protected function getFakeColumnsAsArray() { |
|
460 | - |
|
461 | - $this->prepareFields(); |
|
462 | - |
|
463 | - $fake_field_columns_to_encode = []; |
|
464 | - |
|
465 | - foreach ($this->crud['fields'] as $k => $field) { |
|
466 | - // if it's a fake field |
|
467 | - if (isset($this->crud['fields'][$k]['fake']) && $this->crud['fields'][$k]['fake'] == true) { |
|
468 | - // add it to the request in its appropriate variable - the one defined, if defined |
|
469 | - if (isset($this->crud['fields'][$k]['store_in'])) { |
|
470 | - if (!in_array($this->crud['fields'][$k]['store_in'], $fake_field_columns_to_encode, true)) { |
|
471 | - array_push($fake_field_columns_to_encode, $this->crud['fields'][$k]['store_in']); |
|
472 | - } |
|
473 | - } else //otherwise in the one defined in the $crud variable |
|
474 | - { |
|
475 | - if (!in_array('extras', $fake_field_columns_to_encode, true)) { |
|
476 | - array_push($fake_field_columns_to_encode, 'extras'); |
|
477 | - } |
|
478 | - } |
|
479 | - } |
|
480 | - } |
|
481 | - |
|
482 | - if (!count($fake_field_columns_to_encode)) { |
|
483 | - return ['extras']; |
|
484 | - } |
|
485 | - |
|
486 | - return $fake_field_columns_to_encode; |
|
487 | - } |
|
488 | - |
|
489 | - |
|
490 | - // If it's not an array of array and it's a simple array, create a proper array of arrays for it |
|
491 | - protected function prepareColumns() |
|
492 | - { |
|
493 | - // if the columns aren't set, we can't show this page |
|
494 | - // TODO: instead of dying, show the columns defined as visible on the model |
|
495 | - if (!isset($this->crud['columns'])) |
|
496 | - { |
|
497 | - abort(500, "CRUD columns are not defined."); |
|
498 | - } |
|
499 | - |
|
500 | - // if the columns are defined as a string, transform it to a proper array |
|
501 | - if (!is_array($this->crud['columns'])) |
|
502 | - { |
|
503 | - $current_columns_array = explode(",", $this->crud['columns']); |
|
504 | - $proper_columns_array = array(); |
|
505 | - |
|
506 | - foreach ($current_columns_array as $key => $col) { |
|
507 | - $proper_columns_array[] = [ |
|
508 | - 'name' => $col, |
|
509 | - 'label' => ucfirst($col) //TODO: also replace _ with space |
|
510 | - ]; |
|
511 | - } |
|
512 | - |
|
513 | - $this->crud['columns'] = $proper_columns_array; |
|
514 | - } |
|
515 | - } |
|
516 | - |
|
517 | - /** |
|
518 | - * Prepare the fields to be shown, stored, updated or created. |
|
519 | - * |
|
520 | - * Makes sure $this->crud['fields'] is in the proper format (array of arrays); |
|
521 | - * Makes sure $this->crud['fields'] also contains the id of the current item; |
|
522 | - * Makes sure $this->crud['fields'] also contains the values for each field; |
|
523 | - * |
|
524 | - */ |
|
525 | - protected function prepareFields($entry = false) |
|
526 | - { |
|
527 | - // if the fields have been defined separately for create and update, use that |
|
528 | - if (!isset($this->crud['fields'])) |
|
529 | - { |
|
530 | - if (isset($this->crud['create_fields'])) |
|
531 | - { |
|
532 | - $this->crud['fields'] = $this->crud['create_fields']; |
|
533 | - } elseif (isset($this->crud['update_fields'])) |
|
534 | - { |
|
535 | - $this->crud['fields'] = $this->crud['update_fields']; |
|
536 | - } |
|
537 | - } |
|
538 | - |
|
539 | - // PREREQUISITES CHECK: |
|
540 | - // if the fields aren't set, trigger error |
|
541 | - if (!isset($this->crud['fields'])) |
|
542 | - { |
|
543 | - abort(500, "The CRUD fields are not defined."); |
|
544 | - } |
|
545 | - |
|
546 | - // if the fields are defined as a string, transform it to a proper array |
|
547 | - if (!is_array($this->crud['fields'])) |
|
548 | - { |
|
549 | - $current_fields_array = explode(",", $this->crud['fields']); |
|
550 | - $proper_fields_array = array(); |
|
551 | - |
|
552 | - foreach ($current_fields_array as $key => $field) { |
|
553 | - $proper_fields_array[] = [ |
|
554 | - 'name' => $field, |
|
555 | - 'label' => ucfirst($field), // TODO: also replace _ with space |
|
556 | - 'type' => 'text' // TODO: choose different types of fields depending on the MySQL column type |
|
557 | - ]; |
|
558 | - } |
|
559 | - |
|
560 | - $this->crud['fields'] = $proper_fields_array; |
|
561 | - } |
|
562 | - |
|
563 | - // if no field type is defined, assume the "text" field type |
|
564 | - foreach ($this->crud['fields'] as $k => $field) { |
|
565 | - if (!isset($this->crud['fields'][$k]['type'])) { |
|
566 | - $this->crud['fields'][$k]['type'] = 'text'; |
|
567 | - } |
|
568 | - } |
|
569 | - |
|
570 | - // if an entry was passed, we're preparing for the update form, not create |
|
571 | - if ($entry) { |
|
572 | - // put the values in the same 'fields' variable |
|
573 | - $fields = $this->crud['fields']; |
|
574 | - |
|
575 | - foreach ($fields as $k => $field) { |
|
576 | - // set the value |
|
577 | - if (!isset($this->crud['fields'][$k]['value'])) |
|
578 | - { |
|
579 | - $this->crud['fields'][$k]['value'] = $entry->$field['name']; |
|
580 | - } |
|
581 | - } |
|
582 | - |
|
583 | - // always have a hidden input for the entry id |
|
584 | - $this->crud['fields'][] = array( |
|
585 | - 'name' => 'id', |
|
586 | - 'value' => $entry->id, |
|
587 | - 'type' => 'hidden' |
|
588 | - ); |
|
589 | - } |
|
590 | - } |
|
17 | + use DispatchesJobs, ValidatesRequests; |
|
18 | + |
|
19 | + public $data = array(); |
|
20 | + public $crud = array( |
|
21 | + "model" => "\App\Models\Entity", |
|
22 | + "entity_name" => "entry", |
|
23 | + "entity_name_plural" => "entries", |
|
24 | + "view_table_permission" => true, |
|
25 | + "add_permission" => true, |
|
26 | + "edit_permission" => true, |
|
27 | + "delete_permission" => true, |
|
28 | + "reorder_permission" => true, |
|
29 | + "reorder_max_level" => 3, |
|
30 | + "details_row" => false, |
|
31 | + ); |
|
32 | + |
|
33 | + public function __construct() |
|
34 | + { |
|
35 | + $this->data['crud'] = $this->crud; |
|
36 | + } |
|
37 | + |
|
38 | + /** |
|
39 | + * Display all rows in the database for this entity. |
|
40 | + * |
|
41 | + * @return Response |
|
42 | + */ |
|
43 | + public function index() |
|
44 | + { |
|
45 | + // SECURITY: |
|
46 | + // if view_table_permission is false, abort |
|
47 | + if (isset($this->crud['view_table_permission']) && !$this->crud['view_table_permission']) { |
|
48 | + abort(403, 'Not allowed.'); |
|
49 | + } |
|
50 | + |
|
51 | + // get all results for that entity |
|
52 | + $model = $this->crud['model']; |
|
53 | + if (property_exists($model, 'translatable')) |
|
54 | + { |
|
55 | + $this->data['entries'] = $model::where('translation_lang', \Lang::locale())->get(); |
|
56 | + } else |
|
57 | + { |
|
58 | + $this->data['entries'] = $model::all(); |
|
59 | + } |
|
60 | + |
|
61 | + // add the fake fields for each entry |
|
62 | + foreach ($this->data['entries'] as $key => $entry) { |
|
63 | + $entry->addFakes($this->getFakeColumnsAsArray()); |
|
64 | + } |
|
65 | + |
|
66 | + $this->prepareColumns(); |
|
67 | + $this->data['crud'] = $this->crud; |
|
68 | + $this->data['title'] = ucfirst($this->crud['entity_name_plural']); |
|
69 | + |
|
70 | + // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package |
|
71 | + return view('crud::list', $this->data); |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * Show the form for creating inserting a new row. |
|
77 | + * |
|
78 | + * @return Response |
|
79 | + */ |
|
80 | + public function create() |
|
81 | + { |
|
82 | + // SECURITY: |
|
83 | + // if add_permission is false, abort |
|
84 | + if (isset($this->crud['add_permission']) && !$this->crud['add_permission']) { |
|
85 | + abort(403, 'Not allowed.'); |
|
86 | + } |
|
87 | + |
|
88 | + // get the fields you need to show |
|
89 | + if (isset($this->data['crud']['create_fields'])) |
|
90 | + { |
|
91 | + $this->crud['fields'] = $this->data['crud']['create_fields']; |
|
92 | + } |
|
93 | + |
|
94 | + // prepare the fields you need to show |
|
95 | + $this->prepareFields(); |
|
96 | + $this->data['crud'] = $this->crud; |
|
97 | + $this->data['title'] = trans('backpack::crud.add').' '.$this->crud['entity_name']; |
|
98 | + |
|
99 | + // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package |
|
100 | + return view('crud::create', $this->data); |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * Store a newly created resource in the database. |
|
106 | + * |
|
107 | + * @param StoreRequest $request - type injection used for validation using Requests |
|
108 | + * @return \Illuminate\Http\RedirectResponse |
|
109 | + */ |
|
110 | + public function storeCrud(StoreRequest $request = null) |
|
111 | + { |
|
112 | + // SECURITY: |
|
113 | + // if add_permission is false, abort |
|
114 | + if (isset($this->crud['add_permission']) && !$this->crud['add_permission']) { |
|
115 | + abort(403, 'Not allowed.'); |
|
116 | + } |
|
117 | + |
|
118 | + // compress the fake fields into one field |
|
119 | + $model = $this->crud['model']; |
|
120 | + $values_to_store = $this->compactFakeFields(\Request::all()); |
|
121 | + $item = $model::create($values_to_store); |
|
122 | + |
|
123 | + // if it's a relationship with a pivot table, also sync that |
|
124 | + $this->prepareFields(); |
|
125 | + foreach ($this->crud['fields'] as $k => $field) { |
|
126 | + if (isset($field['pivot']) && $field['pivot'] == true && \Request::has($field['name'])) |
|
127 | + { |
|
128 | + $model::find($item->id)->$field['name']()->attach(\Request::input($field['name'])); |
|
129 | + } |
|
130 | + } |
|
131 | + |
|
132 | + // show a success message |
|
133 | + \Alert::success(trans('backpack::crud.insert_success'))->flash(); |
|
134 | + |
|
135 | + // redirect the user where he chose to be redirected |
|
136 | + switch (\Request::input('redirect_after_save')) { |
|
137 | + case 'current_item_edit': |
|
138 | + return \Redirect::to($this->crud['route'].'/'.$item->id.'/edit'); |
|
139 | + |
|
140 | + default: |
|
141 | + return \Redirect::to(\Request::input('redirect_after_save')); |
|
142 | + } |
|
143 | + } |
|
144 | + |
|
145 | + |
|
146 | + /** |
|
147 | + * Show the form for editing the specified resource. |
|
148 | + * |
|
149 | + * @param int $id |
|
150 | + * @return Response |
|
151 | + */ |
|
152 | + public function edit($id) |
|
153 | + { |
|
154 | + // SECURITY: |
|
155 | + // if edit_permission is false, abort |
|
156 | + if (isset($this->crud['edit_permission']) && !$this->crud['edit_permission']) { |
|
157 | + abort(403, 'Not allowed.'); |
|
158 | + } |
|
159 | + |
|
160 | + // get the info for that entry |
|
161 | + $model = $this->crud['model']; |
|
162 | + $this->data['entry'] = $model::find($id); |
|
163 | + $this->data['entry']->addFakes($this->getFakeColumnsAsArray()); |
|
164 | + |
|
165 | + if (isset($this->data['crud']['update_fields'])) |
|
166 | + { |
|
167 | + $this->crud['fields'] = $this->data['crud']['update_fields']; |
|
168 | + } |
|
169 | + |
|
170 | + // prepare the fields you need to show and prepopulate the values |
|
171 | + $this->prepareFields($this->data['entry']); |
|
172 | + $this->data['crud'] = $this->crud; |
|
173 | + $this->data['title'] = trans('backpack::crud.edit').' '.$this->crud['entity_name']; |
|
174 | + |
|
175 | + // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package |
|
176 | + return view('crud::edit', $this->data); |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + /** |
|
181 | + * Update the specified resource in the database. |
|
182 | + * |
|
183 | + * @param UpdateRequest $request - type injection used for validation using Requests |
|
184 | + * @return \Illuminate\Http\RedirectResponse |
|
185 | + */ |
|
186 | + public function updateCrud(UpdateRequest $request = null) |
|
187 | + { |
|
188 | + // if edit_permission is false, abort |
|
189 | + if (isset($this->crud['edit_permission']) && !$this->crud['edit_permission']) { |
|
190 | + abort(403, 'Not allowed.'); |
|
191 | + } |
|
192 | + |
|
193 | + $model = $this->crud['model']; |
|
194 | + $this->prepareFields($model::find(\Request::input('id'))); |
|
195 | + |
|
196 | + $model::find(\Request::input('id'))->update($this->compactFakeFields(\Request::all())); |
|
197 | + |
|
198 | + // if it's a relationship with a pivot table, also sync that |
|
199 | + foreach ($this->crud['fields'] as $k => $field) { |
|
200 | + if (isset($field['pivot']) && $field['pivot'] == true && \Request::has($field['name'])) |
|
201 | + { |
|
202 | + $model::find(\Request::input('id'))->$field['name']()->sync(\Request::input($field['name'])); |
|
203 | + } |
|
204 | + } |
|
205 | + |
|
206 | + // show a success message |
|
207 | + \Alert::success(trans('backpack::crud.update_success'))->flash(); |
|
208 | + |
|
209 | + return \Redirect::to($this->crud['route']); |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + /** |
|
214 | + * Display the specified resource. |
|
215 | + * |
|
216 | + * @param int $id |
|
217 | + * @return Response |
|
218 | + */ |
|
219 | + public function show($id) |
|
220 | + { |
|
221 | + // get the info for that entry |
|
222 | + $model = $this->crud['model']; |
|
223 | + $this->data['entry'] = $model::find($id); |
|
224 | + $this->data['entry']->addFakes($this->getFakeColumnsAsArray()); |
|
225 | + $this->data['crud'] = $this->crud; |
|
226 | + $this->data['title'] = trans('backpack::crud.preview').' '.$this->crud['entity_name']; |
|
227 | + |
|
228 | + // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package |
|
229 | + return view('crud::show', $this->data); |
|
230 | + } |
|
231 | + |
|
232 | + |
|
233 | + /** |
|
234 | + * Remove the specified resource from storage. |
|
235 | + * |
|
236 | + * @param int $id |
|
237 | + * @return string |
|
238 | + */ |
|
239 | + public function destroy($id) |
|
240 | + { |
|
241 | + // SECURITY: |
|
242 | + // if delete_permission is false, abort |
|
243 | + if (isset($this->crud['delete_permission']) && !$this->crud['delete_permission']) { |
|
244 | + abort(403, trans('backpack::crud.unauthorized_access')); |
|
245 | + } |
|
246 | + |
|
247 | + $model = $this->crud['model']; |
|
248 | + $item = $model::find($id); |
|
249 | + $item->delete(); |
|
250 | + |
|
251 | + return 'true'; |
|
252 | + } |
|
253 | + |
|
254 | + |
|
255 | + /** |
|
256 | + * Reorder the items in the database using the Nested Set pattern. |
|
257 | + * |
|
258 | + * Database columns needed: id, parent_id, lft, rgt, depth, name/title |
|
259 | + * |
|
260 | + * @return Response |
|
261 | + */ |
|
262 | + public function reorder($lang = false) |
|
263 | + { |
|
264 | + // if reorder_table_permission is false, abort |
|
265 | + if (isset($this->crud['reorder_permission']) && !$this->crud['reorder_permission']) { |
|
266 | + abort(403, 'Not allowed.'); |
|
267 | + } |
|
268 | + |
|
269 | + if ($lang == false) |
|
270 | + { |
|
271 | + $lang = \Lang::locale(); |
|
272 | + } |
|
273 | + |
|
274 | + // get all results for that entity |
|
275 | + $model = $this->crud['model']; |
|
276 | + if (property_exists($model, 'translatable')) |
|
277 | + { |
|
278 | + $this->data['entries'] = $model::where('translation_lang', $lang)->get(); |
|
279 | + $this->data['languages'] = \Backpack\LangFileManager\app\Models\Language::all(); |
|
280 | + $this->data['active_language'] = $lang; |
|
281 | + } else |
|
282 | + { |
|
283 | + $this->data['entries'] = $model::all(); |
|
284 | + } |
|
285 | + $this->data['crud'] = $this->crud; |
|
286 | + $this->data['title'] = trans('backpack::crud.reorder').' '.$this->crud['entity_name']; |
|
287 | + |
|
288 | + // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package |
|
289 | + return view('crud::reorder', $this->data); |
|
290 | + } |
|
291 | + |
|
292 | + |
|
293 | + /** |
|
294 | + * Save the new order, using the Nested Set pattern. |
|
295 | + * |
|
296 | + * Database columns needed: id, parent_id, lft, rgt, depth, name/title |
|
297 | + * |
|
298 | + * @return |
|
299 | + */ |
|
300 | + public function saveReorder() |
|
301 | + { |
|
302 | + // if reorder_table_permission is false, abort |
|
303 | + if (isset($this->crud['reorder_permission']) && !$this->crud['reorder_permission']) { |
|
304 | + abort(403, 'Not allowed.'); |
|
305 | + } |
|
306 | + |
|
307 | + $model = $this->crud['model']; |
|
308 | + $count = 0; |
|
309 | + $all_entries = \Request::input('tree'); |
|
310 | + |
|
311 | + if (count($all_entries)) { |
|
312 | + foreach ($all_entries as $key => $entry) { |
|
313 | + if ($entry['item_id'] != "" && $entry['item_id'] != null) { |
|
314 | + $item = $model::find($entry['item_id']); |
|
315 | + $item->parent_id = $entry['parent_id']; |
|
316 | + $item->depth = $entry['depth']; |
|
317 | + $item->lft = $entry['left']; |
|
318 | + $item->rgt = $entry['right']; |
|
319 | + $item->save(); |
|
320 | + |
|
321 | + $count++; |
|
322 | + } |
|
323 | + } |
|
324 | + } else |
|
325 | + { |
|
326 | + return false; |
|
327 | + } |
|
328 | + |
|
329 | + return 'success for '.$count." items"; |
|
330 | + } |
|
331 | + |
|
332 | + |
|
333 | + /** |
|
334 | + * Used with AJAX in the list view (datatables) to show extra information about that row that didn't fit in the table. |
|
335 | + * It defaults to showing all connected translations and their CRUD buttons. |
|
336 | + * |
|
337 | + * It's enabled by: |
|
338 | + * - setting the $crud['details_row'] variable to true; |
|
339 | + * - adding the details route for the entity; ex: Route::get('page/{id}/details', 'PageCrudController@showDetailsRow'); |
|
340 | + */ |
|
341 | + public function showDetailsRow($id) |
|
342 | + { |
|
343 | + // get the info for that entry |
|
344 | + $model = $this->crud['model']; |
|
345 | + $this->data['entry'] = $model::find($id); |
|
346 | + $this->data['entry']->addFakes($this->getFakeColumnsAsArray()); |
|
347 | + $this->data['original_entry'] = $this->data['entry']; |
|
348 | + $this->data['crud'] = $this->crud; |
|
349 | + |
|
350 | + if (property_exists($model, 'translatable')) |
|
351 | + { |
|
352 | + $this->data['translations'] = $this->data['entry']->translations(); |
|
353 | + |
|
354 | + // create a list of languages the item is not translated in |
|
355 | + $this->data['languages'] = \Backpack\LangFileManager\app\Models\Language::all(); |
|
356 | + $this->data['languages_already_translated_in'] = $this->data['entry']->translationLanguages(); |
|
357 | + $this->data['languages_to_translate_in'] = $this->data['languages']->diff($this->data['languages_already_translated_in']); |
|
358 | + $this->data['languages_to_translate_in'] = $this->data['languages_to_translate_in']->reject(function($item) { |
|
359 | + return $item->abbr == \Lang::locale(); |
|
360 | + }); |
|
361 | + } |
|
362 | + |
|
363 | + // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package |
|
364 | + return view('crud::details_row', $this->data); |
|
365 | + } |
|
366 | + |
|
367 | + |
|
368 | + /** |
|
369 | + * Duplicate an existing item into another language and open it for editing. |
|
370 | + */ |
|
371 | + public function translateItem($id, $lang) |
|
372 | + { |
|
373 | + $model = $this->crud['model']; |
|
374 | + $this->data['entry'] = $model::find($id); |
|
375 | + // check if there isn't a translation already |
|
376 | + $existing_translation = $this->data['entry']->translation($lang); |
|
377 | + |
|
378 | + if ($existing_translation) |
|
379 | + { |
|
380 | + $new_entry = $existing_translation; |
|
381 | + } else |
|
382 | + { |
|
383 | + // get the info for that entry |
|
384 | + $new_entry_attributes = $this->data['entry']->getAttributes(); |
|
385 | + $new_entry_attributes['translation_lang'] = $lang; |
|
386 | + $new_entry_attributes['translation_of'] = $id; |
|
387 | + $new_entry_attributes = array_except($new_entry_attributes, 'id'); |
|
388 | + |
|
389 | + $new_entry = $model::create($new_entry_attributes); |
|
390 | + } |
|
391 | + |
|
392 | + // redirect to the edit form for that translation |
|
393 | + return redirect(str_replace($id, $new_entry->id, str_replace('translate/'.$lang, 'edit', \Request::url()))); |
|
394 | + } |
|
395 | + |
|
396 | + |
|
397 | + |
|
398 | + /** |
|
399 | + * COMMODITY FUNCTIONS |
|
400 | + */ |
|
401 | + |
|
402 | + |
|
403 | + /** |
|
404 | + * Refactor the request array to something that can be passed to the model's create or update function. |
|
405 | + * The resulting array will only include the fields that are stored in the database and their values, |
|
406 | + * plus the '_token' and 'redirect_after_save' variables. |
|
407 | + * |
|
408 | + * @param Request $request - everything that was sent from the form, usually \Request::all() |
|
409 | + * @return array |
|
410 | + */ |
|
411 | + protected function compactFakeFields($request) { |
|
412 | + |
|
413 | + $this->prepareFields(); |
|
414 | + |
|
415 | + $fake_field_columns_to_encode = []; |
|
416 | + |
|
417 | + // go through each defined field |
|
418 | + foreach ($this->crud['fields'] as $k => $field) { |
|
419 | + // if it's a fake field |
|
420 | + if (isset($this->crud['fields'][$k]['fake']) && $this->crud['fields'][$k]['fake'] == true) { |
|
421 | + // add it to the request in its appropriate variable - the one defined, if defined |
|
422 | + if (isset($this->crud['fields'][$k]['store_in'])) { |
|
423 | + $request[$this->crud['fields'][$k]['store_in']][$this->crud['fields'][$k]['name']] = $request[$this->crud['fields'][$k]['name']]; |
|
424 | + |
|
425 | + $remove_fake_field = array_pull($request, $this->crud['fields'][$k]['name']); |
|
426 | + if (!in_array($this->crud['fields'][$k]['store_in'], $fake_field_columns_to_encode, true)) { |
|
427 | + array_push($fake_field_columns_to_encode, $this->crud['fields'][$k]['store_in']); |
|
428 | + } |
|
429 | + } else //otherwise in the one defined in the $crud variable |
|
430 | + { |
|
431 | + $request['extras'][$this->crud['fields'][$k]['name']] = $request[$this->crud['fields'][$k]['name']]; |
|
432 | + |
|
433 | + $remove_fake_field = array_pull($request, $this->crud['fields'][$k]['name']); |
|
434 | + if (!in_array('extras', $fake_field_columns_to_encode, true)) { |
|
435 | + array_push($fake_field_columns_to_encode, 'extras'); |
|
436 | + } |
|
437 | + } |
|
438 | + } |
|
439 | + } |
|
440 | + |
|
441 | + // json_encode all fake_value columns in the database, so they can be properly stored and interpreted |
|
442 | + if (count($fake_field_columns_to_encode)) { |
|
443 | + foreach ($fake_field_columns_to_encode as $key => $value) { |
|
444 | + $request[$value] = json_encode($request[$value]); |
|
445 | + } |
|
446 | + } |
|
447 | + |
|
448 | + // if there are no fake fields defined, this will just return the original Request in full |
|
449 | + // since no modifications or additions have been made to $request |
|
450 | + return $request; |
|
451 | + } |
|
452 | + |
|
453 | + |
|
454 | + /** |
|
455 | + * Returns an array of database columns names, that are used to store fake values. |
|
456 | + * Returns ['extras'] if no columns have been found. |
|
457 | + * |
|
458 | + */ |
|
459 | + protected function getFakeColumnsAsArray() { |
|
460 | + |
|
461 | + $this->prepareFields(); |
|
462 | + |
|
463 | + $fake_field_columns_to_encode = []; |
|
464 | + |
|
465 | + foreach ($this->crud['fields'] as $k => $field) { |
|
466 | + // if it's a fake field |
|
467 | + if (isset($this->crud['fields'][$k]['fake']) && $this->crud['fields'][$k]['fake'] == true) { |
|
468 | + // add it to the request in its appropriate variable - the one defined, if defined |
|
469 | + if (isset($this->crud['fields'][$k]['store_in'])) { |
|
470 | + if (!in_array($this->crud['fields'][$k]['store_in'], $fake_field_columns_to_encode, true)) { |
|
471 | + array_push($fake_field_columns_to_encode, $this->crud['fields'][$k]['store_in']); |
|
472 | + } |
|
473 | + } else //otherwise in the one defined in the $crud variable |
|
474 | + { |
|
475 | + if (!in_array('extras', $fake_field_columns_to_encode, true)) { |
|
476 | + array_push($fake_field_columns_to_encode, 'extras'); |
|
477 | + } |
|
478 | + } |
|
479 | + } |
|
480 | + } |
|
481 | + |
|
482 | + if (!count($fake_field_columns_to_encode)) { |
|
483 | + return ['extras']; |
|
484 | + } |
|
485 | + |
|
486 | + return $fake_field_columns_to_encode; |
|
487 | + } |
|
488 | + |
|
489 | + |
|
490 | + // If it's not an array of array and it's a simple array, create a proper array of arrays for it |
|
491 | + protected function prepareColumns() |
|
492 | + { |
|
493 | + // if the columns aren't set, we can't show this page |
|
494 | + // TODO: instead of dying, show the columns defined as visible on the model |
|
495 | + if (!isset($this->crud['columns'])) |
|
496 | + { |
|
497 | + abort(500, "CRUD columns are not defined."); |
|
498 | + } |
|
499 | + |
|
500 | + // if the columns are defined as a string, transform it to a proper array |
|
501 | + if (!is_array($this->crud['columns'])) |
|
502 | + { |
|
503 | + $current_columns_array = explode(",", $this->crud['columns']); |
|
504 | + $proper_columns_array = array(); |
|
505 | + |
|
506 | + foreach ($current_columns_array as $key => $col) { |
|
507 | + $proper_columns_array[] = [ |
|
508 | + 'name' => $col, |
|
509 | + 'label' => ucfirst($col) //TODO: also replace _ with space |
|
510 | + ]; |
|
511 | + } |
|
512 | + |
|
513 | + $this->crud['columns'] = $proper_columns_array; |
|
514 | + } |
|
515 | + } |
|
516 | + |
|
517 | + /** |
|
518 | + * Prepare the fields to be shown, stored, updated or created. |
|
519 | + * |
|
520 | + * Makes sure $this->crud['fields'] is in the proper format (array of arrays); |
|
521 | + * Makes sure $this->crud['fields'] also contains the id of the current item; |
|
522 | + * Makes sure $this->crud['fields'] also contains the values for each field; |
|
523 | + * |
|
524 | + */ |
|
525 | + protected function prepareFields($entry = false) |
|
526 | + { |
|
527 | + // if the fields have been defined separately for create and update, use that |
|
528 | + if (!isset($this->crud['fields'])) |
|
529 | + { |
|
530 | + if (isset($this->crud['create_fields'])) |
|
531 | + { |
|
532 | + $this->crud['fields'] = $this->crud['create_fields']; |
|
533 | + } elseif (isset($this->crud['update_fields'])) |
|
534 | + { |
|
535 | + $this->crud['fields'] = $this->crud['update_fields']; |
|
536 | + } |
|
537 | + } |
|
538 | + |
|
539 | + // PREREQUISITES CHECK: |
|
540 | + // if the fields aren't set, trigger error |
|
541 | + if (!isset($this->crud['fields'])) |
|
542 | + { |
|
543 | + abort(500, "The CRUD fields are not defined."); |
|
544 | + } |
|
545 | + |
|
546 | + // if the fields are defined as a string, transform it to a proper array |
|
547 | + if (!is_array($this->crud['fields'])) |
|
548 | + { |
|
549 | + $current_fields_array = explode(",", $this->crud['fields']); |
|
550 | + $proper_fields_array = array(); |
|
551 | + |
|
552 | + foreach ($current_fields_array as $key => $field) { |
|
553 | + $proper_fields_array[] = [ |
|
554 | + 'name' => $field, |
|
555 | + 'label' => ucfirst($field), // TODO: also replace _ with space |
|
556 | + 'type' => 'text' // TODO: choose different types of fields depending on the MySQL column type |
|
557 | + ]; |
|
558 | + } |
|
559 | + |
|
560 | + $this->crud['fields'] = $proper_fields_array; |
|
561 | + } |
|
562 | + |
|
563 | + // if no field type is defined, assume the "text" field type |
|
564 | + foreach ($this->crud['fields'] as $k => $field) { |
|
565 | + if (!isset($this->crud['fields'][$k]['type'])) { |
|
566 | + $this->crud['fields'][$k]['type'] = 'text'; |
|
567 | + } |
|
568 | + } |
|
569 | + |
|
570 | + // if an entry was passed, we're preparing for the update form, not create |
|
571 | + if ($entry) { |
|
572 | + // put the values in the same 'fields' variable |
|
573 | + $fields = $this->crud['fields']; |
|
574 | + |
|
575 | + foreach ($fields as $k => $field) { |
|
576 | + // set the value |
|
577 | + if (!isset($this->crud['fields'][$k]['value'])) |
|
578 | + { |
|
579 | + $this->crud['fields'][$k]['value'] = $entry->$field['name']; |
|
580 | + } |
|
581 | + } |
|
582 | + |
|
583 | + // always have a hidden input for the entry id |
|
584 | + $this->crud['fields'][] = array( |
|
585 | + 'name' => 'id', |
|
586 | + 'value' => $entry->id, |
|
587 | + 'type' => 'hidden' |
|
588 | + ); |
|
589 | + } |
|
590 | + } |
|
591 | 591 | |
592 | 592 | } |
@@ -2,7 +2,6 @@ |
||
2 | 2 | namespace Backpack\CRUD; |
3 | 3 | |
4 | 4 | use Illuminate\Support\ServiceProvider; |
5 | -use Illuminate\Routing\Router; |
|
6 | 5 | use Route; |
7 | 6 | |
8 | 7 | class CrudServiceProvider extends ServiceProvider |
@@ -1,6 +1,5 @@ |
||
1 | 1 | <?php namespace Backpack\CRUD; |
2 | 2 | |
3 | -use Illuminate\Database\Eloquent\Model; |
|
4 | 3 | use DB; |
5 | 4 | use Lang; |
6 | 5 |
@@ -12,14 +12,14 @@ |
||
12 | 12 | |-------------------------------------------------------------------------- |
13 | 13 | */ |
14 | 14 | |
15 | - public static function getPossibleEnumValues($field_name){ |
|
15 | + public static function getPossibleEnumValues($field_name) { |
|
16 | 16 | $instance = new static; // create an instance of the model to be able to get the table name |
17 | - $type = DB::select( DB::raw('SHOW COLUMNS FROM '.$instance->getTable().' WHERE Field = "'.$field_name.'"') )[0]->Type; |
|
17 | + $type = DB::select(DB::raw('SHOW COLUMNS FROM '.$instance->getTable().' WHERE Field = "'.$field_name.'"'))[0]->Type; |
|
18 | 18 | preg_match('/^enum\((.*)\)$/', $type, $matches); |
19 | 19 | $enum = array(); |
20 | 20 | $exploded = explode(',', $matches[1]); |
21 | - foreach($exploded as $value){ |
|
22 | - $v = trim( $value, "'" ); |
|
21 | + foreach ($exploded as $value) { |
|
22 | + $v = trim($value, "'"); |
|
23 | 23 | $enum[] = $v; |
24 | 24 | } |
25 | 25 | return $enum; |
@@ -4,30 +4,30 @@ |
||
4 | 4 | |
5 | 5 | class CrudRequest extends FormRequest { |
6 | 6 | |
7 | - /** |
|
8 | - * Determine if the user is authorized to make this request. |
|
9 | - * |
|
10 | - * @return bool |
|
11 | - */ |
|
12 | - public function authorize() |
|
13 | - { |
|
14 | - // only allow creates if the user is logged in |
|
15 | - return \Auth::check(); |
|
16 | - } |
|
7 | + /** |
|
8 | + * Determine if the user is authorized to make this request. |
|
9 | + * |
|
10 | + * @return bool |
|
11 | + */ |
|
12 | + public function authorize() |
|
13 | + { |
|
14 | + // only allow creates if the user is logged in |
|
15 | + return \Auth::check(); |
|
16 | + } |
|
17 | 17 | |
18 | - /** |
|
19 | - * Get the validation rules that apply to the request. |
|
20 | - * |
|
21 | - * @return array |
|
22 | - */ |
|
23 | - public function rules() |
|
24 | - { |
|
25 | - return [ |
|
26 | - // 'name' => 'required|min:3|max:255' |
|
27 | - ]; |
|
28 | - } |
|
18 | + /** |
|
19 | + * Get the validation rules that apply to the request. |
|
20 | + * |
|
21 | + * @return array |
|
22 | + */ |
|
23 | + public function rules() |
|
24 | + { |
|
25 | + return [ |
|
26 | + // 'name' => 'required|min:3|max:255' |
|
27 | + ]; |
|
28 | + } |
|
29 | 29 | |
30 | - // OPTIONAL OVERRIDE |
|
30 | + // OPTIONAL OVERRIDE |
|
31 | 31 | // public function forbiddenResponse() |
32 | 32 | // { |
33 | 33 | // Optionally, send a custom response on authorize failure |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | <!-- elFinder JS (REQUIRED) --> |
18 | 18 | <script src="<?= asset($dir.'/js/elfinder.min.js') ?>"></script> |
19 | 19 | |
20 | - <?php if($locale){ ?> |
|
20 | + <?php if ($locale) { ?> |
|
21 | 21 | <!-- elFinder translation (OPTIONAL) --> |
22 | 22 | <script src="<?= asset($dir."/js/i18n/elfinder.$locale.js") ?>"></script> |
23 | 23 | <?php } ?> |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | $().ready(function() { |
41 | 41 | var elf = $('#elfinder').elfinder({ |
42 | 42 | // set your elFinder options here |
43 | - <?php if($locale){ ?> |
|
43 | + <?php if ($locale) { ?> |
|
44 | 44 | lang: '<?= $locale ?>', // locale |
45 | 45 | <?php } ?> |
46 | 46 | customData: { |
@@ -33,23 +33,23 @@ |
||
33 | 33 | @if (isset($column['type']) && $column['type']=='select_multiple') |
34 | 34 | {{-- relationships with pivot table (n-n) --}} |
35 | 35 | <td><?php |
36 | - $results = $entry->{$column['entity']}()->getResults(); |
|
37 | - if ($results && $results->count()) { |
|
38 | - $results_array = $results->lists($column['attribute'], 'id'); |
|
39 | - echo implode(', ', $results_array->toArray()); |
|
40 | - } |
|
41 | - else |
|
42 | - { |
|
43 | - echo '-'; |
|
44 | - } |
|
45 | - ?></td> |
|
36 | + $results = $entry->{$column['entity']}()->getResults(); |
|
37 | + if ($results && $results->count()) { |
|
38 | + $results_array = $results->lists($column['attribute'], 'id'); |
|
39 | + echo implode(', ', $results_array->toArray()); |
|
40 | + } |
|
41 | + else |
|
42 | + { |
|
43 | + echo '-'; |
|
44 | + } |
|
45 | + ?></td> |
|
46 | 46 | @elseif (isset($column['type']) && $column['type']=='select') |
47 | 47 | {{-- single relationships (1-1, 1-n) --}} |
48 | 48 | <td><?php |
49 | - if ($entry->{$column['entity']}()->getResults()) { |
|
50 | - echo $entry->{$column['entity']}()->getResults()->{$column['attribute']}; |
|
51 | - } |
|
52 | - ?></td> |
|
49 | + if ($entry->{$column['entity']}()->getResults()) { |
|
50 | + echo $entry->{$column['entity']}()->getResults()->{$column['attribute']}; |
|
51 | + } |
|
52 | + ?></td> |
|
53 | 53 | @else |
54 | 54 | {{-- regular object attribute --}} |
55 | 55 | <td>{{ str_limit(strip_tags($entry->$column['name']), 80, "[...]") }}</td> |
@@ -37,8 +37,7 @@ |
||
37 | 37 | if ($results && $results->count()) { |
38 | 38 | $results_array = $results->lists($column['attribute'], 'id'); |
39 | 39 | echo implode(', ', $results_array->toArray()); |
40 | - } |
|
41 | - else |
|
40 | + } else |
|
42 | 41 | { |
43 | 42 | echo '-'; |
44 | 43 | } |
@@ -20,42 +20,42 @@ discard block |
||
20 | 20 | |
21 | 21 | @section('content') |
22 | 22 | <?php |
23 | - function tree_element($entry, $key, $all_entries, $crud) |
|
24 | - { |
|
23 | + function tree_element($entry, $key, $all_entries, $crud) |
|
24 | + { |
|
25 | 25 | if (!isset($entry->tree_element_shown)) { |
26 | - // mark the element as shown |
|
27 | - $all_entries[$key]->tree_element_shown = true; |
|
28 | - $entry->tree_element_shown = true; |
|
26 | + // mark the element as shown |
|
27 | + $all_entries[$key]->tree_element_shown = true; |
|
28 | + $entry->tree_element_shown = true; |
|
29 | 29 | |
30 | - // show the tree element |
|
31 | - echo '<li id="list_'.$entry->id.'">'; |
|
32 | - echo '<div><span class="disclose"><span></span></span>'.$entry->{$crud['reorder_label']}.'</div>'; |
|
30 | + // show the tree element |
|
31 | + echo '<li id="list_'.$entry->id.'">'; |
|
32 | + echo '<div><span class="disclose"><span></span></span>'.$entry->{$crud['reorder_label']}.'</div>'; |
|
33 | 33 | |
34 | - // see if this element has any children |
|
35 | - $children = []; |
|
36 | - foreach ($all_entries as $key => $subentry) { |
|
34 | + // see if this element has any children |
|
35 | + $children = []; |
|
36 | + foreach ($all_entries as $key => $subentry) { |
|
37 | 37 | if ($subentry->parent_id == $entry->id) { |
38 | - $children[] = $subentry; |
|
38 | + $children[] = $subentry; |
|
39 | + } |
|
39 | 40 | } |
40 | - } |
|
41 | 41 | |
42 | - $children = collect($children)->sortBy('lft'); |
|
42 | + $children = collect($children)->sortBy('lft'); |
|
43 | 43 | |
44 | - // if it does have children, show them |
|
45 | - if (count($children)) { |
|
44 | + // if it does have children, show them |
|
45 | + if (count($children)) { |
|
46 | 46 | echo '<ol>'; |
47 | 47 | foreach ($children as $key => $child) { |
48 | - $children[$key] = tree_element($child, $child->id, $all_entries, $crud); |
|
48 | + $children[$key] = tree_element($child, $child->id, $all_entries, $crud); |
|
49 | 49 | } |
50 | 50 | echo '</ol>'; |
51 | - } |
|
52 | - echo '</li>'; |
|
51 | + } |
|
52 | + echo '</li>'; |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | return $entry; |
56 | - } |
|
56 | + } |
|
57 | 57 | |
58 | - ?> |
|
58 | + ?> |
|
59 | 59 | <div class="row"> |
60 | 60 | <div class="col-md-8 col-md-offset-2"> |
61 | 61 | @if (!(isset($crud['view_table_permission']) && !$crud['view_table_permission'])) |
@@ -87,15 +87,15 @@ discard block |
||
87 | 87 | |
88 | 88 | <ol class="sortable"> |
89 | 89 | <?php |
90 | - $all_entries = collect($entries->all())->sortBy('lft')->keyBy('id'); |
|
91 | - $root_entries = $all_entries->filter(function($item) { |
|
90 | + $all_entries = collect($entries->all())->sortBy('lft')->keyBy('id'); |
|
91 | + $root_entries = $all_entries->filter(function($item) { |
|
92 | 92 | return $item->parent_id == 0; |
93 | - }); |
|
94 | - ?> |
|
93 | + }); |
|
94 | + ?> |
|
95 | 95 | @foreach ($root_entries as $key => $entry) |
96 | 96 | <?php |
97 | 97 | $root_entries[$key] = tree_element($entry, $key, $all_entries, $crud); |
98 | - ?> |
|
98 | + ?> |
|
99 | 99 | @endforeach |
100 | 100 | </ol> |
101 | 101 |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | return [ |
4 | 4 | |
5 | - /* |
|
5 | + /* |
|
6 | 6 | |-------------------------------------------------------------------------- |
7 | 7 | | Dick Crud Language Lines |
8 | 8 | |-------------------------------------------------------------------------- |
@@ -13,77 +13,77 @@ discard block |
||
13 | 13 | | |
14 | 14 | */ |
15 | 15 | |
16 | - // Create form |
|
17 | - 'add' => 'Add', |
|
18 | - 'back_to_all' => 'Back to all ', |
|
19 | - 'cancel' => 'Cancel', |
|
20 | - 'add_a_new' => 'Add a new ', |
|
16 | + // Create form |
|
17 | + 'add' => 'Add', |
|
18 | + 'back_to_all' => 'Back to all ', |
|
19 | + 'cancel' => 'Cancel', |
|
20 | + 'add_a_new' => 'Add a new ', |
|
21 | 21 | |
22 | - // Create form - advanced options |
|
23 | - 'after_saving' => "After saving", |
|
24 | - 'go_to_the_table_view' => "go to the table view", |
|
25 | - 'let_me_add_another_item' => "let me add another item", |
|
26 | - 'edit_the_new_item' => "edit the new item", |
|
22 | + // Create form - advanced options |
|
23 | + 'after_saving' => "After saving", |
|
24 | + 'go_to_the_table_view' => "go to the table view", |
|
25 | + 'let_me_add_another_item' => "let me add another item", |
|
26 | + 'edit_the_new_item' => "edit the new item", |
|
27 | 27 | |
28 | - // Edit form |
|
29 | - 'edit' => 'Edit', |
|
30 | - 'save' => 'Save', |
|
28 | + // Edit form |
|
29 | + 'edit' => 'Edit', |
|
30 | + 'save' => 'Save', |
|
31 | 31 | |
32 | - // CRUD table view |
|
33 | - 'all' => 'All ', |
|
34 | - 'in_the_database' => 'in the database', |
|
35 | - 'list' => 'List', |
|
36 | - 'actions' => 'Actions', |
|
37 | - 'preview' => 'Preview', |
|
38 | - 'delete' => 'Delete', |
|
32 | + // CRUD table view |
|
33 | + 'all' => 'All ', |
|
34 | + 'in_the_database' => 'in the database', |
|
35 | + 'list' => 'List', |
|
36 | + 'actions' => 'Actions', |
|
37 | + 'preview' => 'Preview', |
|
38 | + 'delete' => 'Delete', |
|
39 | 39 | |
40 | - // Confirmation messages and bubbles |
|
41 | - 'delete_confirm' => 'Are you sure you want to delete this item?', |
|
42 | - 'delete_confirmation_title' => 'Item Deleted', |
|
43 | - 'delete_confirmation_message' => 'The item has been deleted successfully.', |
|
44 | - 'delete_confirmation_not_title' => 'NOT deleted', |
|
45 | - 'delete_confirmation_not_message' => "There's been an error. Your item might not have been deleted.", |
|
46 | - 'delete_confirmation_not_deleted_title' => 'Not deleted', |
|
47 | - 'delete_confirmation_not_deleted_message' => 'Nothing happened. Your item is safe.', |
|
40 | + // Confirmation messages and bubbles |
|
41 | + 'delete_confirm' => 'Are you sure you want to delete this item?', |
|
42 | + 'delete_confirmation_title' => 'Item Deleted', |
|
43 | + 'delete_confirmation_message' => 'The item has been deleted successfully.', |
|
44 | + 'delete_confirmation_not_title' => 'NOT deleted', |
|
45 | + 'delete_confirmation_not_message' => "There's been an error. Your item might not have been deleted.", |
|
46 | + 'delete_confirmation_not_deleted_title' => 'Not deleted', |
|
47 | + 'delete_confirmation_not_deleted_message' => 'Nothing happened. Your item is safe.', |
|
48 | 48 | |
49 | - // DataTables translation |
|
50 | - "emptyTable" => "No data available in table", |
|
51 | - "info" => "Showing _START_ to _END_ of _TOTAL_ entries", |
|
52 | - "infoEmpty" => "Showing 0 to 0 of 0 entries", |
|
53 | - "infoFiltered" => "(filtered from _MAX_ total entries)", |
|
54 | - "infoPostFix" => "", |
|
55 | - "thousands" => ",", |
|
56 | - "lengthMenu" => "_MENU_ records per page", |
|
57 | - "loadingRecords" => "Loading...", |
|
58 | - "processing" => "Processing...", |
|
59 | - "search" => "Search: ", |
|
60 | - "zeroRecords" => "No matching records found", |
|
61 | - "paginate" => [ |
|
62 | - "first" => "First", |
|
63 | - "last" => "Last", |
|
64 | - "next" => "Next", |
|
65 | - "previous" => "Previous" |
|
66 | - ], |
|
67 | - "aria" => [ |
|
68 | - "sortAscending" => ": activate to sort column ascending", |
|
69 | - "sortDescending" => ": activate to sort column descending" |
|
70 | - ], |
|
49 | + // DataTables translation |
|
50 | + "emptyTable" => "No data available in table", |
|
51 | + "info" => "Showing _START_ to _END_ of _TOTAL_ entries", |
|
52 | + "infoEmpty" => "Showing 0 to 0 of 0 entries", |
|
53 | + "infoFiltered" => "(filtered from _MAX_ total entries)", |
|
54 | + "infoPostFix" => "", |
|
55 | + "thousands" => ",", |
|
56 | + "lengthMenu" => "_MENU_ records per page", |
|
57 | + "loadingRecords" => "Loading...", |
|
58 | + "processing" => "Processing...", |
|
59 | + "search" => "Search: ", |
|
60 | + "zeroRecords" => "No matching records found", |
|
61 | + "paginate" => [ |
|
62 | + "first" => "First", |
|
63 | + "last" => "Last", |
|
64 | + "next" => "Next", |
|
65 | + "previous" => "Previous" |
|
66 | + ], |
|
67 | + "aria" => [ |
|
68 | + "sortAscending" => ": activate to sort column ascending", |
|
69 | + "sortDescending" => ": activate to sort column descending" |
|
70 | + ], |
|
71 | 71 | |
72 | - // global crud - errors |
|
73 | - "unauthorized_access" => "Unauthorized access - you do not have the necessary permissions to see this page.", |
|
72 | + // global crud - errors |
|
73 | + "unauthorized_access" => "Unauthorized access - you do not have the necessary permissions to see this page.", |
|
74 | 74 | |
75 | - // global crud - success / error notification bubbles |
|
76 | - "insert_success" => "The item has been added successfully.", |
|
77 | - "update_success" => "The item has been modified successfully.", |
|
75 | + // global crud - success / error notification bubbles |
|
76 | + "insert_success" => "The item has been added successfully.", |
|
77 | + "update_success" => "The item has been modified successfully.", |
|
78 | 78 | |
79 | - // CRUD reorder view |
|
80 | - 'reorder' => 'Reorder', |
|
81 | - 'reorder_text' => 'Use drag&drop to reorder.', |
|
82 | - 'reorder_success_title' => 'Done', |
|
83 | - 'reorder_success_message' => 'Your order has been saved.', |
|
84 | - 'reorder_error_title' => 'Error', |
|
85 | - 'reorder_error_message' => 'Your order has not been saved.', |
|
79 | + // CRUD reorder view |
|
80 | + 'reorder' => 'Reorder', |
|
81 | + 'reorder_text' => 'Use drag&drop to reorder.', |
|
82 | + 'reorder_success_title' => 'Done', |
|
83 | + 'reorder_success_message' => 'Your order has been saved.', |
|
84 | + 'reorder_error_title' => 'Error', |
|
85 | + 'reorder_error_message' => 'Your order has not been saved.', |
|
86 | 86 | |
87 | - 'rules_text' => "<strong>Notice: </strong> Do not translate words prefixed with colon (ex: ':number_of_items'). Those will be replaced automatically with a proper value. If translated, that stops working.", |
|
87 | + 'rules_text' => "<strong>Notice: </strong> Do not translate words prefixed with colon (ex: ':number_of_items'). Those will be replaced automatically with a proper value. If translated, that stops working.", |
|
88 | 88 | |
89 | 89 | ]; |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | return [ |
4 | 4 | |
5 | - /* |
|
5 | + /* |
|
6 | 6 | |-------------------------------------------------------------------------- |
7 | 7 | | Dick Crud Language Lines |
8 | 8 | |-------------------------------------------------------------------------- |
@@ -13,66 +13,66 @@ discard block |
||
13 | 13 | | |
14 | 14 | */ |
15 | 15 | |
16 | - // Create form |
|
17 | - 'add' => 'Adaugă', |
|
18 | - 'back_to_all' => 'Înapoi la toate ', |
|
19 | - 'cancel' => 'Anulează', |
|
20 | - 'add_a_new' => 'Adaugă un nou ', |
|
16 | + // Create form |
|
17 | + 'add' => 'Adaugă', |
|
18 | + 'back_to_all' => 'Înapoi la toate ', |
|
19 | + 'cancel' => 'Anulează', |
|
20 | + 'add_a_new' => 'Adaugă un nou ', |
|
21 | 21 | |
22 | - // Create form - advanced options |
|
23 | - 'after_saving' => "După salvare", |
|
24 | - 'go_to_the_table_view' => "du-mă la toate intrările", |
|
25 | - 'let_me_add_another_item' => "vreu să adaug o altă intrare", |
|
26 | - 'edit_the_new_item' => "vreau să editez intrarea", |
|
22 | + // Create form - advanced options |
|
23 | + 'after_saving' => "După salvare", |
|
24 | + 'go_to_the_table_view' => "du-mă la toate intrările", |
|
25 | + 'let_me_add_another_item' => "vreu să adaug o altă intrare", |
|
26 | + 'edit_the_new_item' => "vreau să editez intrarea", |
|
27 | 27 | |
28 | - // Edit form |
|
29 | - 'edit' => 'Editează', |
|
30 | - 'save' => 'Salvează', |
|
28 | + // Edit form |
|
29 | + 'edit' => 'Editează', |
|
30 | + 'save' => 'Salvează', |
|
31 | 31 | |
32 | - // CRUD table view |
|
33 | - 'all' => 'Toate ', |
|
34 | - 'in_the_database' => 'din baza de date', |
|
35 | - 'list' => 'Listă', |
|
36 | - 'actions' => 'Operațiuni', |
|
37 | - 'preview' => 'Previzualizează', |
|
38 | - 'delete' => 'Șterge', |
|
32 | + // CRUD table view |
|
33 | + 'all' => 'Toate ', |
|
34 | + 'in_the_database' => 'din baza de date', |
|
35 | + 'list' => 'Listă', |
|
36 | + 'actions' => 'Operațiuni', |
|
37 | + 'preview' => 'Previzualizează', |
|
38 | + 'delete' => 'Șterge', |
|
39 | 39 | |
40 | - // Confirmation messages and bubbles |
|
41 | - 'delete_confirm' => 'Ești sigur că vrei să ștergi această intrare?', |
|
42 | - 'delete_confirmation_title' => 'Intrare ștearsă', |
|
43 | - 'delete_confirmation_message' => 'Intrarea a fost ștearsă cu succes.', |
|
44 | - 'delete_confirmation_not_title' => 'Eroare', |
|
45 | - 'delete_confirmation_not_message' => "A avut loc o eroare. E posibil ca intrarea să nu fi fost ștearsă.", |
|
46 | - 'delete_confirmation_not_deleted_title' => 'Intrarea nu a fost ștearsă', |
|
47 | - 'delete_confirmation_not_deleted_message' => 'Nu am șters intrarea din baza de date.', |
|
40 | + // Confirmation messages and bubbles |
|
41 | + 'delete_confirm' => 'Ești sigur că vrei să ștergi această intrare?', |
|
42 | + 'delete_confirmation_title' => 'Intrare ștearsă', |
|
43 | + 'delete_confirmation_message' => 'Intrarea a fost ștearsă cu succes.', |
|
44 | + 'delete_confirmation_not_title' => 'Eroare', |
|
45 | + 'delete_confirmation_not_message' => "A avut loc o eroare. E posibil ca intrarea să nu fi fost ștearsă.", |
|
46 | + 'delete_confirmation_not_deleted_title' => 'Intrarea nu a fost ștearsă', |
|
47 | + 'delete_confirmation_not_deleted_message' => 'Nu am șters intrarea din baza de date.', |
|
48 | 48 | |
49 | - // DataTables translation |
|
50 | - "emptyTable" => "Nu există intrări în baza de date", |
|
51 | - "info" => "Sunt afișate intrările _START_-_END_ din _TOTAL_", |
|
52 | - "infoEmpty" => "Sunt afișate toate intrarile. Adică niciuna.", |
|
53 | - "infoFiltered" => "(filtrate din _MAX_ intrări în total)", |
|
54 | - "infoPostFix" => "", |
|
55 | - "thousands" => ",", |
|
56 | - "lengthMenu" => "_MENU_ intrări pe pagină", |
|
57 | - "loadingRecords" => "Se încarcă...", |
|
58 | - "processing" => "Se procesează...", |
|
59 | - "search" => "Caută: ", |
|
60 | - "zeroRecords" => "Nu au fost găsite intrări care să se potrivească", |
|
61 | - "paginate" => [ |
|
62 | - "first" => "Prima pagină", |
|
63 | - "last" => "Ultima pagină", |
|
64 | - "next" => "Pagina următoare", |
|
65 | - "previous" => "Pagina anterioară" |
|
66 | - ], |
|
67 | - "aria" => [ |
|
68 | - "sortAscending" => ": activează pentru a ordona ascendent coloana", |
|
69 | - "sortDescending" => ": activează petnru a ordona descendent coloana" |
|
70 | - ], |
|
49 | + // DataTables translation |
|
50 | + "emptyTable" => "Nu există intrări în baza de date", |
|
51 | + "info" => "Sunt afișate intrările _START_-_END_ din _TOTAL_", |
|
52 | + "infoEmpty" => "Sunt afișate toate intrarile. Adică niciuna.", |
|
53 | + "infoFiltered" => "(filtrate din _MAX_ intrări în total)", |
|
54 | + "infoPostFix" => "", |
|
55 | + "thousands" => ",", |
|
56 | + "lengthMenu" => "_MENU_ intrări pe pagină", |
|
57 | + "loadingRecords" => "Se încarcă...", |
|
58 | + "processing" => "Se procesează...", |
|
59 | + "search" => "Caută: ", |
|
60 | + "zeroRecords" => "Nu au fost găsite intrări care să se potrivească", |
|
61 | + "paginate" => [ |
|
62 | + "first" => "Prima pagină", |
|
63 | + "last" => "Ultima pagină", |
|
64 | + "next" => "Pagina următoare", |
|
65 | + "previous" => "Pagina anterioară" |
|
66 | + ], |
|
67 | + "aria" => [ |
|
68 | + "sortAscending" => ": activează pentru a ordona ascendent coloana", |
|
69 | + "sortDescending" => ": activează petnru a ordona descendent coloana" |
|
70 | + ], |
|
71 | 71 | |
72 | - // global crud - errors |
|
73 | - "unauthorized_access" => "Acces neautorizat - Nu ai permisiunea necesară pentru a accesa pagina.", |
|
72 | + // global crud - errors |
|
73 | + "unauthorized_access" => "Acces neautorizat - Nu ai permisiunea necesară pentru a accesa pagina.", |
|
74 | 74 | |
75 | - // global crud - success / error notification bubbles |
|
76 | - "insert_success" => "Intrarea a fost adăugată cu succes.", |
|
77 | - "update_success" => "Intrarea a fost modificată cu succes.", |
|
75 | + // global crud - success / error notification bubbles |
|
76 | + "insert_success" => "Intrarea a fost adăugată cu succes.", |
|
77 | + "update_success" => "Intrarea a fost modificată cu succes.", |
|
78 | 78 | ]; |