Passed
Push — master ( 795d23...149f73 )
by Grant
06:52 queued 12s
created

JobApplicationCrudController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 50
c 1
b 0
f 0
dl 0
loc 76
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setup() 0 8 1
A setupListOperation() 0 62 2
1
<?php
2
3
namespace App\Http\Controllers\Admin;
4
5
use App\Models\Lookup\ApplicationStatus;
6
use Backpack\CRUD\app\Http\Controllers\CrudController;
7
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
8
9
/**
10
 * Class JobApplicationCrudController
11
 * @package App\Http\Controllers\Admin
12
 * @property-read \Backpack\CRUD\app\Library\CrudPanel\CrudPanel $crud
13
 */
14
class JobApplicationCrudController extends CrudController
15
{
16
    use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
17
18
    public function setup()
19
    {
20
        $this->crud->setModel('App\Models\JobApplication');
21
        $this->crud->setRoute(config('backpack.base.route_prefix') . '/job-application');
0 ignored issues
show
Bug introduced by
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

21
        $this->crud->setRoute(/** @scrutinizer ignore-call */ config('backpack.base.route_prefix') . '/job-application');
Loading history...
22
        $this->crud->setEntityNameStrings('application', 'applications');
23
        $this->crud->denyAccess(['update', 'create', 'delete']);
24
        $this->crud->orderBy('id', 'asc');
25
        $this->crud->addButtonFromView('line', 'view_job_application', 'view_job_application', 'end');
26
    }
27
28
    protected function setupListOperation()
29
    {
30
        $this->crud->addColumn([
31
            'name' => 'id',
32
            'type' => 'number',
33
            'label' => 'ID',
34
            'orderable' => true,
35
        ]);
36
37
        $this->crud->addColumn([
38
            'name' => 'job_poster.title',
39
            'type' => 'text',
40
            'label' => 'Job Poster Title',
41
            'searchLogic' => function ($query, $column, $searchTerm) {
42
                $query->orWhereHas('job_poster', function ($q) use ($searchTerm) {
43
                    $q->where('title', 'ilike', '%'.$searchTerm.'%');
44
                });
45
            }
46
        ]);
47
48
        $this->crud->addColumn([
49
            'name' => 'applicant.user.full_name',
50
            'type' => 'text',
51
            'label' => 'Applicant Name',
52
            'searchLogic' => function ($query, $column, $searchTerm) {
53
                $query->orWhereHas('applicant.user', function ($q) use ($searchTerm) {
54
                    $q->where('first_name', 'ilike', '%'.$searchTerm.'%')
55
                    ->orWhere('last_name', 'ilike', '%'.$searchTerm.'%');
56
                });
57
            }
58
        ]);
59
60
        $this->crud->addColumn([
61
            'name' => 'applicant.user.email',
62
            'type' => 'text',
63
            'label' => 'Applicant Email',
64
            'searchLogic' => function ($query, $column, $searchTerm) {
65
                $query->orWhereHas('applicant.user', function ($q) use ($searchTerm) {
66
                    $q->where('email', 'ilike', '%'.$searchTerm.'%');
67
                });
68
            }
69
        ]);
70
71
        $this->crud->addColumn([
72
            'name' => 'application_status.name',
73
            'type' => 'text',
74
            'label' => 'Application Status',
75
        ]);
76
77
        $this->crud->addFilter([
78
            'name' => 'application_status',
79
            'key' => 'application_status_filter',
80
            'type' => 'select2_multiple',
81
            'label' => 'Filter by Application Status'
82
        ], function () {
83
            // The options that show up in the select2.
84
            return ApplicationStatus::all()->pluck('name', 'id')->toArray();
85
        }, function ($values) {
86
            // If the filter is active.
87
            foreach (json_decode($values) as $key => $value) {
88
                $this->crud->query = $this->crud->query->orWhereHas('application_status', function ($query) use ($value) {
89
                    $query->where('id', $value);
90
                });
91
            }
92
        });
93
    }
94
}
95