Completed
Push — master ( e7d3d1...c447a8 )
by Arjay
14:54
created

ModulesDataTable::html()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 13

Duplication

Lines 21
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 13
nc 1
nop 0
dl 21
loc 21
rs 9.3142
c 0
b 0
f 0
1
<?php
2
3
namespace Yajra\CMS\DataTables;
4
5
use Yajra\Datatables\Services\DataTable;
6
7
class ModulesDataTable extends DataTable
8
{
9
    /**
10
     * @return \Illuminate\Http\JsonResponse
11
     */
12
    public function ajax()
13
    {
14
        return $this->datatables
15
            ->collection($this->query())
16
            ->editColumn('active', function ($module) {
17
                return $module['active'] ? 'Yes' : 'No';
18
            })
19
            ->addColumn('action', 'administrator.modules.datatables.action')
20
            ->make(true);
21
    }
22
23
    /**
24
     * @return \Illuminate\Database\Eloquent\Builder
25
     */
26
    public function query()
27
    {
28
        $collections = app('modules')->toCollection()->toArray();
29
        $modules     = collect($collections)->map(function ($module) {
30
            return $module;
31
        });
32
33
        return $this->applyScopes($modules);
34
    }
35
36
    /**
37
     * @return \Yajra\Datatables\Html\Builder
38
     */
39 View Code Duplication
    public function html()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40
    {
41
        return $this
42
            ->builder()
43
            ->columns($this->getColumns())
44
            ->addAction(['width' => '80px'])
45
            ->parameters([
46
                'stateSave' => true,
47
                'order'     => [[0, 'desc']],
48
                'buttons'   => [
49
//                    [
0 ignored issues
show
Unused Code Comprehensibility introduced by
49% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
50
//                        'extend' => 'create',
51
//                        'text'   => '<i class="fa fa-plus"></i>&nbsp;&nbsp;' . trans('cms::module.table.buttons.create'),
52
//                    ],
53
                    'export',
54
                    'print',
55
                    'reset',
56
                    'reload',
57
                ],
58
            ]);
59
    }
60
61
    /**
62
     * @return array
63
     */
64
    protected function getColumns()
65
    {
66
        return [
67
            'name'   => ['title' => trans('cms::module.table.columns.name')],
68
            'alias'  => ['title' => trans('cms::module.table.columns.alias')],
69
            'active' => ['title' => trans('cms::module.table.columns.active')],
70
            'order'  => ['title' => trans('cms::module.table.columns.order')],
71
        ];
72
    }
73
}
74