Completed
Push — develop ( 508664...7b00fe )
by Abdelrahman
01:58
created

AbilitiesDataTable::getColumns()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 9
nc 2
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Auth\DataTables\Adminarea;
6
7
use Cortex\Auth\Models\Ability;
8
use Cortex\Foundation\DataTables\AbstractDataTable;
9
10
class AbilitiesDataTable extends AbstractDataTable
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15
    protected $model = Ability::class;
16
17
    /**
18
     * Get the query object to be processed by dataTables.
19
     *
20
     * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder|\Illuminate\Support\Collection
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use \Illuminate\Database\Que...tabase\Eloquent\Builder.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
21
     */
22
    public function query()
23
    {
24
        $currentUser = $this->request->user($this->request->route('guard'));
25
26
        $query = $currentUser->can('superadmin') ? app($this->model)->query() : app($this->model)->query()->whereIn('id', $currentUser->getAbilities()->pluck('id')->toArray());
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 176 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
27
28
        return $this->applyScopes($query);
29
    }
30
31
    /**
32
     * Display ajax response.
33
     *
34
     * @return \Illuminate\Http\JsonResponse
35
     */
36
    public function ajax()
37
    {
38
        return datatables($this->query())
39
            ->orderColumn('title', 'title->"$.'.app()->getLocale().'" $1')
40
            ->make(true);
41
    }
42
43
    /**
44
     * Get columns.
45
     *
46
     * @return array
47
     */
48
    protected function getColumns(): array
49
    {
50
        $link = config('cortex.foundation.route.locale_prefix')
51
            ? '"<a href=\""+routes.route(\'adminarea.abilities.edit\', {ability: full.id, locale: \''.$this->request->segment(1).'\'})+"\">"+data+"</a>"'
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 153 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
52
            : '"<a href=\""+routes.route(\'adminarea.abilities.edit\', {ability: full.id})+"\">"+data+"</a>"';
53
54
        return [
55
            'title' => ['title' => trans('cortex/auth::common.title'), 'render' => $link, 'responsivePriority' => 0],
56
            'name' => ['title' => trans('cortex/auth::common.name')],
57
            'created_at' => ['title' => trans('cortex/auth::common.created_at'), 'render' => "moment(data).format('MMM Do, YYYY')"],
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 132 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
58
            'updated_at' => ['title' => trans('cortex/auth::common.updated_at'), 'render' => "moment(data).format('MMM Do, YYYY')"],
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 132 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
59
        ];
60
    }
61
}
62