Completed
Push — master ( 8f08c7...7bd638 )
by Mohamed
02:25
created

RoleDataTable::html()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21

Duplication

Lines 21
Ratio 100 %

Importance

Changes 0
Metric Value
dl 21
loc 21
rs 9.584
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Microboard\DataTables;
4
5
use Illuminate\Database\Eloquent\Builder;
6
use Microboard\Models\Role;
7
use Microboard\Traits\DataTable as MicroboardDataTable;
8
use Yajra\DataTables\DataTableAbstract;
9
use Yajra\DataTables\Html\Column;
10
use Yajra\DataTables\Services\DataTable;
11
12
class RoleDataTable extends DataTable
13
{
14
    use MicroboardDataTable;
15
16
    /**
17
     * Build DataTable class.
18
     *
19
     * @param $query
20
     * @return DataTableAbstract
21
     */
22
    public function dataTable($query)
23
    {
24
        return $this->build($query)
25
            ->editColumn('users', function (Role $role) {
26
                return $role->users_count;
27
            })
28
            ->editColumn('permissions', function (Role $role) {
29
                return $role->permissions_count;
30
            });
31
    }
32
33
    /**
34
     * Get query source of dataTable.
35
     *
36
     * @param Role $model
37
     * @return Builder
38
     */
39
    public function query(Role $model)
40
    {
41
        return $model->newQuery()->withCount(['users', 'permissions']);
42
    }
43
44
    /**
45
     * Get columns.
46
     *
47
     * @return array
48
     */
49
    protected function getColumns()
50
    {
51
        return [
52
            Column::make('id')->title(trans('microboard::roles.fields.id'))->width('1%'),
53
            Column::make('display_name')->title(trans('microboard::roles.fields.display_name')),
54
            Column::make('users')->title(trans('microboard::roles.fields.users')),
55
            Column::make('permissions')->title(trans('microboard::roles.fields.permissionsCount')),
56
            Column::computed('action', '')
57
                ->exportable(false)
58
                ->printable(false)
59
                ->width('1%')
60
                ->addClass('text-right')
61
        ];
62
    }
63
}
64