|
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'); |
|
|
|
|
|
|
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
|
|
|
|