Completed
Push — master ( bd4222...e5ba92 )
by Arjay
13:31
created

ExtensionsDataTable::query()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 3
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 6
rs 9.4285
1
<?php
2
3
namespace Yajra\CMS\DataTables;
4
5
use Yajra\CMS\Entities\Extension;
6
use Yajra\Datatables\Services\DataTable;
7
8
class ExtensionsDataTable extends DataTable
9
{
10
    /**
11
     * Display ajax response.
12
     *
13
     * @return \Illuminate\Http\JsonResponse
14
     */
15
    public function ajax()
16
    {
17
        return $this->datatables
18
            ->eloquent($this->query())
19
            ->addColumn('action', 'administrator.extensions.datatables.action')
20
            ->editColumn('name', function ($extension) {
21
                return "<h3 class=\"lead no-margin\">{$extension->name} <small>{$extension->version}</small></h3>
22
                            <p>{$extension->description}</p>";
23
            })
24
            ->editColumn('enabled', function ($extension) {
25
                return $extension->enabled ? 'Y' : 'N';
26
            })
27
            ->make(true);
28
    }
29
30
    /**
31
     * Get the query object to be processed by datatables.
32
     *
33
     * @return \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder
34
     */
35
    public function query()
36
    {
37
        $users = Extension::query();
38
39
        return $this->applyScopes($users);
40
    }
41
42
    /**
43
     * Optional method if you want to use html builder.
44
     *
45
     * @return \Yajra\Datatables\Html\Builder
46
     */
47
    public function html()
48
    {
49
        return $this->builder()
50
                    ->columns($this->getColumns())
51
                    ->ajax('')
52
                    ->addAction(['width' => '80px'])
53
                    ->parameters($this->getBuilderParameters());
54
    }
55
56
    /**
57
     * Get columns.
58
     *
59
     * @return array
60
     */
61
    private function getColumns()
62
    {
63
        return [
64
            'id'      => ['width' => '20px', 'title' => trans('cms::extension.table.id')],
65
            'name'    => ['title' => trans('cms::extension.table.name')],
66
            'type'    => ['width' => '60px', 'title' => trans('cms::extension.table.type')],
67
            'enabled' => ['width' => '20px', 'title' => trans('cms::extension.table.enabled')],
68
        ];
69
    }
70
71
    /**
72
     * Get filename for export.
73
     *
74
     * @return string
75
     */
76
    protected function filename()
77
    {
78
        return 'extensions';
79
    }
80
}
81