| Conditions | 5 |
| Paths | 2 |
| Total Lines | 83 |
| Code Lines | 62 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 32 | public function setupListOperation() |
||
| 33 | { |
||
| 34 | // Required for order logic. |
||
| 35 | $locale = 'en'; |
||
| 36 | if (null !== $this->request->input('locale')) { |
||
| 37 | $locale = $this->request->input('locale'); |
||
| 38 | } |
||
| 39 | App::setLocale($locale); |
||
| 40 | |||
| 41 | // Add the custom blade buttons found in resources/views/vendor/backpack/crud/buttons/. |
||
| 42 | $this->crud->addButtonFromView('line', 'job_admin_edit', 'job_admin_edit', 'end'); |
||
| 43 | $this->crud->addButtonFromView('line', 'spb_link', 'spb_link', 'end'); |
||
| 44 | $this->crud->addButtonFromView('line', 'jpb_link', 'jpb_link', 'end'); |
||
| 45 | $this->crud->addButtonFromView('line', 'job_poster_link', 'job_poster_link', 'end'); |
||
| 46 | |||
| 47 | |||
| 48 | $this->crud->addColumn([ |
||
| 49 | 'name' => 'id', |
||
| 50 | 'type' => 'number', |
||
| 51 | 'label' => 'ID' |
||
| 52 | ]); |
||
| 53 | $this->crud->addColumn([ |
||
| 54 | 'name' => 'title', |
||
| 55 | 'type' => 'text', |
||
| 56 | 'label' => 'Title', |
||
| 57 | 'searchLogic' => function ($query, $column, $searchTerm) use ($locale) : void { |
||
| 58 | $query->orWhere('title->' . $locale, 'ilike', "%$searchTerm%"); |
||
| 59 | }, |
||
| 60 | 'orderLogic' => function ($query, $column, $columnDirection) use ($locale) { |
||
| 61 | return $query->orderBy('title->' . $locale, $columnDirection)->select('*'); |
||
| 62 | } |
||
| 63 | ]); |
||
| 64 | $this->crud->addColumn([ |
||
| 65 | 'name' => 'status', |
||
| 66 | 'label' => 'Status', |
||
| 67 | 'type' => 'model_function', |
||
| 68 | 'function_name' => 'status' |
||
| 69 | ]); |
||
| 70 | $this->crud->addColumn([ |
||
| 71 | 'name' => 'published', |
||
| 72 | 'label' => 'Published', |
||
| 73 | 'type' => 'check', |
||
| 74 | ]); |
||
| 75 | $this->crud->addColumn([ |
||
| 76 | 'name' => 'manager_user_name', |
||
| 77 | 'type' => 'closure', |
||
| 78 | 'label' => 'Manager', |
||
| 79 | 'orderable' => false, |
||
| 80 | 'function' => function ($entry) { |
||
| 81 | return '<a href="' . route('manager.profile.edit', $entry->manager->id) . '" target="_blank">' . $entry->manager->user->full_name . '</a>'; |
||
|
|
|||
| 82 | } |
||
| 83 | ]); |
||
| 84 | $this->crud->addColumn([ |
||
| 85 | 'name' => 'department.name', |
||
| 86 | 'label' => 'Department', |
||
| 87 | 'type' => 'text' |
||
| 88 | ]); |
||
| 89 | $this->crud->addColumn([ |
||
| 90 | 'name' => 'submitted_applications_count', |
||
| 91 | 'label' => 'Applications', |
||
| 92 | 'type' => 'closure', |
||
| 93 | 'function' => |
||
| 94 | function ($entry) { |
||
| 95 | return $entry->submitted_applications_count() > 0 ? |
||
| 96 | '<a target="_blank" href="' . route('manager.jobs.applications', $entry->id) . '">' . $entry->submitted_applications_count() . ' (View <i class="fa fa-external-link"></i>)</a>' : |
||
| 97 | $entry->submitted_applications_count(); |
||
| 98 | } |
||
| 99 | ]); |
||
| 100 | |||
| 101 | // Filters. |
||
| 102 | $this->crud->addFilter([ |
||
| 103 | 'name' => 'departments', |
||
| 104 | 'type' => 'select2_multiple', |
||
| 105 | 'label' => 'Departments' |
||
| 106 | ], function () { |
||
| 107 | return Department::all()->pluck('name', 'id')->toArray(); |
||
| 108 | }, function ($values) { |
||
| 109 | $this->crud->addClause('WhereHas', 'department', function ($query) use ($values) { |
||
| 110 | foreach (json_decode($values) as $key => $value) { |
||
| 111 | if ($key === 0) { |
||
| 112 | $query->where('id', $value); |
||
| 113 | } else { |
||
| 114 | $query->orWhere('id', $value); |
||
| 115 | } |
||
| 223 |