CareerTable::bulkDelete()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Adminetic\Website\Http\Livewire\Admin\Career;
4
5
use Adminetic\Website\Models\Admin\Career;
6
use Carbon\Carbon;
7
use Illuminate\Database\Eloquent\Builder;
8
use Illuminate\Support\Facades\Blade;
9
use Rappasoft\LaravelLivewireTables\DataTableComponent;
10
use Rappasoft\LaravelLivewireTables\Views\Column;
11
12
class CareerTable extends DataTableComponent
13
{
14
    public function builder(): Builder
15
    {
16
        return Career::query()->orderBy('position'); // Eager load anything; // Select some things
0 ignored issues
show
Bug Best Practice introduced by
The expression return Adminetic\Website...()->orderBy('position') could return the type Illuminate\Database\Query\Builder which is incompatible with the type-hinted return Illuminate\Database\Eloquent\Builder. Consider adding an additional type-check to rule them out.
Loading history...
17
    }
18
19
    public array $bulkActions = [
20
        'bulkDelete' => 'Bulk Delete',
21
    ];
22
23
    public function bulkDelete()
24
    {
25
        Career::whereIn('id', $this->getSelected())->delete();
26
    }
27
28
    public function configure(): void
29
    {
30
        $this->setPrimaryKey('id');
31
32
        $this->setEagerLoadAllRelationsEnabled();
33
34
        $this->setEmptyMessage('No career found');
35
36
        $this->setReorderStatus(true);
37
38
        $this->setDefaultReorderSort('position', 'asc');
39
    }
40
41
    public function reorder($items): void
42
    {
43
        foreach ($items as $item) {
44
            Career::find((int) $item['value'])->update(['position' => (int) $item['order']]);
45
        }
46
    }
47
48
    public function columns(): array
49
    {
50
        return [
51
            Column::make('ID', 'id')
52
                ->sortable()
53
                ->searchable(),
54
            Column::make('Title', 'title')
55
                ->sortable()
56
                ->searchable(),
57
            Column::make('Group', 'group')
58
                ->label(
59
                    fn ($row, Column $column) => $row->group ?? '-'
0 ignored issues
show
Unused Code introduced by
The parameter $column is not used and could be removed. ( Ignorable by Annotation )

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

59
                    fn ($row, /** @scrutinizer ignore-unused */ Column $column) => $row->group ?? '-'

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
60
                )
61
                ->sortable()
62
                ->searchable(),
63
            Column::make('Designation', 'designation')
64
                ->sortable()
65
                ->searchable(),
66
            Column::make('Location', 'location')
67
                ->sortable()
68
                ->searchable(),
69
            Column::make('Salary', 'salary')
70
                ->label(
71
                    fn ($row, Column $column) => ! is_null($row->salary) ? (currency().$row->salary) : '-'
0 ignored issues
show
Unused Code introduced by
The parameter $column is not used and could be removed. ( Ignorable by Annotation )

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

71
                    fn ($row, /** @scrutinizer ignore-unused */ Column $column) => ! is_null($row->salary) ? (currency().$row->salary) : '-'

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
72
                )
73
                ->searchable(),
74
            Column::make('Deadline', 'deadline')
75
                ->label(
76
                    fn ($row, Column $column) => ! is_null($row->deadline) ? (Carbon::crate($row->deadline))->toFormattedDateString() : '-'
0 ignored issues
show
Unused Code introduced by
The parameter $column is not used and could be removed. ( Ignorable by Annotation )

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

76
                    fn ($row, /** @scrutinizer ignore-unused */ Column $column) => ! is_null($row->deadline) ? (Carbon::crate($row->deadline))->toFormattedDateString() : '-'

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
77
                )
78
                ->sortable()
79
                ->searchable(),
80
            Column::make('Excerpt', 'excerpt')
81
                ->sortable()
82
                ->searchable(),
83
            Column::make('Active', 'active')
84
                ->format(
85
                    fn ($value, $row, Column $column) => '<span class="badge badge-'.($row->getRawOriginal('active') ? 'success' : 'danger').' ">'.($row->getRawOriginal('active') ? 'Active' : 'Inactive').'</span>'
0 ignored issues
show
Unused Code introduced by
The parameter $column is not used and could be removed. ( Ignorable by Annotation )

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

85
                    fn ($value, $row, /** @scrutinizer ignore-unused */ Column $column) => '<span class="badge badge-'.($row->getRawOriginal('active') ? 'success' : 'danger').' ">'.($row->getRawOriginal('active') ? 'Active' : 'Inactive').'</span>'

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
86
                )
87
                ->html()
88
                ->collapseOnTablet(),
89
            Column::make('Apply Button', 'add_apply_button')
90
                ->format(
91
                    fn ($value, $row, Column $column) => '<span class="badge badge-'.($row->getRawOriginal('add_apply_button') ? 'success' : 'danger').' ">'.($row->getRawOriginal('add_apply_button') ? 'Active' : 'Inactive').'</span>'
0 ignored issues
show
Unused Code introduced by
The parameter $column is not used and could be removed. ( Ignorable by Annotation )

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

91
                    fn ($value, $row, /** @scrutinizer ignore-unused */ Column $column) => '<span class="badge badge-'.($row->getRawOriginal('add_apply_button') ? 'success' : 'danger').' ">'.($row->getRawOriginal('add_apply_button') ? 'Active' : 'Inactive').'</span>'

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
92
                )
93
                ->html()
94
                ->collapseOnTablet(),
95
            Column::make('Action')
96
                ->label(
97
                    fn ($row, Column $column) => Blade::render('<x-adminetic-action :model="$model" route="career"><x-slot name="buttons"><a href="{{ route("career.applications", ["career" => $model->id]) }}"class="btn btn-info btn-air-info p-2 btn-sm"><i class="fa fa-file"></i> <span class="mx-2 p-2"style="background-color: white;color:black">{{ $model->applications->count() }}</span></a></x-slot></x-adminetic-action>', ['model' => $row])
0 ignored issues
show
Unused Code introduced by
The parameter $column is not used and could be removed. ( Ignorable by Annotation )

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

97
                    fn ($row, /** @scrutinizer ignore-unused */ Column $column) => Blade::render('<x-adminetic-action :model="$model" route="career"><x-slot name="buttons"><a href="{{ route("career.applications", ["career" => $model->id]) }}"class="btn btn-info btn-air-info p-2 btn-sm"><i class="fa fa-file"></i> <span class="mx-2 p-2"style="background-color: white;color:black">{{ $model->applications->count() }}</span></a></x-slot></x-adminetic-action>', ['model' => $row])

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
98
                )
99
                ->html()
100
                ->collapseOnTablet(),
101
        ];
102
    }
103
}
104