Passed
Pull Request — release/1.0.15 (#1655)
by Tristan
10:06 queued 02:47
created

JobPosterCrudController::setupUpdateOperation()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 33
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 24
c 0
b 0
f 0
dl 0
loc 33
rs 9.536
cc 3
nc 2
nop 0
1
<?php
2
3
namespace App\Http\Controllers\Admin;
4
5
use Backpack\CRUD\app\Http\Controllers\CrudController;
6
7
class JobPosterCrudController extends CrudController
8
{
9
    use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
0 ignored issues
show
introduced by
The trait Backpack\CRUD\app\Http\C...perations\ListOperation requires some properties which are not provided by App\Http\Controllers\Admin\JobPosterCrudController: $model, $query, $entity_name_plural
Loading history...
10
    use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
0 ignored issues
show
introduced by
The trait Backpack\CRUD\app\Http\C...rations\UpdateOperation requires some properties which are not provided by App\Http\Controllers\Admin\JobPosterCrudController: $model, $entity_name
Loading history...
11
12
    /**
13
     * Prepare the admin interface by setting the associated
14
     * model, setting the route, and adding custom columns/fields.
15
     *
16
     * @return void
17
     */
18
    public function setup() : void
19
    {
20
        $this->crud->setModel('App\Models\JobPoster');
21
        $this->crud->setRoute('admin/job-poster');
22
        $this->crud->setEntityNameStrings('Job Poster', 'Job Posters');
23
24
        if (!$this->request->has('order')) {
25
            $this->crud->orderBy('close_date_time', 'desc');
26
        }
27
    }
28
29
    public function setupListOperation()
1 ignored issue
show
Coding Style Documentation introduced by
Missing doc comment for function setupListOperation()
Loading history...
30
    {
31
        // Add the custom blade buttons found in resources/views/vendor/backpack/crud/buttons/.
32
        $this->crud->addButtonFromView('line', 'job_admin_edit', 'job_admin_edit', 'end');
33
        $this->crud->addButtonFromView('line', 'jpb_link', 'jpb_link', 'end');
34
35
        $this->crud->addColumn([
36
            'name' => 'title',
37
            'type' => 'text',
38
            'label' => 'Title'
39
        ]);
40
        $this->crud->addColumn([
41
            'name' => 'open_date_time',
42
            'type' => 'datetime',
43
            'label' => 'Open Date'
44
        ]);
45
        $this->crud->addColumn([
46
            'name' => 'close_date_time',
47
            'type' => 'datetime',
48
            'label' => 'Close Date'
49
        ]);
50
        $this->crud->addColumn([
51
            'name' => 'status',
52
            'label' => 'Status',
53
            'type' => 'model_function',
54
            'function_name' => 'status'
55
        ]);
56
        $this->crud->addColumn([
57
            'name' => 'published',
58
            'label' => 'Published',
59
            'type' => 'check',
60
        ]);
61
        $this->crud->addColumn([
62
            'name' => 'manager.user.name',
63
            'key' => 'manager_user_name',
64
            'type' => 'text',
65
            'label' => 'Manager',
66
            'orderable' => false
67
        ]);
68
        $this->crud->addColumn([
69
            'name' => 'submitted_applications_count',
70
            'label' => 'Applications',
71
            'type' => 'closure',
72
            'function' => function ($entry) {
73
                return $entry->submitted_applications_count() > 0 ?
74
                        '<a href="' . route('manager.jobs.applications', $entry->id) . '" target="_blank">' . $entry->submitted_applications_count() . ' (View <i class="fa fa-external-link"></i>)</a>' :
75
                        $entry->submitted_applications_count();
76
            }
77
        ]);
78
    }
79
80
    public function setupUpdateOperation()
1 ignored issue
show
Coding Style Documentation introduced by
Missing doc comment for function setupUpdateOperation()
Loading history...
81
    {
82
        $this->crud->addField([
83
            'name' => 'title',
84
            'label' => 'Title',
85
            'type' => 'text',
86
            'attributes' => [
87
                'readonly' => 'readonly'
88
            ]
89
        ]);
90
        $this->crud->addField([
91
            'name' => 'open_date_time',
92
            'label' => 'Open Date',
93
            'type' => 'datetime_picker',
94
            'datetime_picker_options' => [
95
                'format' => 'YYYY-MM-DD HH:mm:ss',
96
            ],
97
        ]);
98
        $this->crud->addField([
99
            'name' => 'close_date_time',
100
            'label' => 'Close Date',
101
            'type' => 'datetime_picker',
102
            'datetime_picker_options' => [
103
                'format' => 'YYYY-MM-DD HH:mm:ss',
104
            ],
105
        ]);
106
        if ($this->crud->getCurrentEntry() &&
107
            !$this->crud->getCurrentEntry()->published
108
        ) {
109
            $this->crud->addField([
110
                'name' => 'published',
111
                'label' => 'Publish',
112
                'type' => 'checkbox'
113
            ]);
114
        }
115
    }
116
}
117