Code Duplication    Length = 92-94 lines in 2 locations

app/DataTables/General/EventlogDataTable.php 1 location

@@ 31-122 (lines=92) @@
28
use App\Models\General\Eventlog;
29
use Yajra\Datatables\Services\DataTable;
30
31
class EventlogDataTable extends DataTable
32
{
33
    /**
34
     * Display ajax response.
35
     *
36
     * @return \Illuminate\Http\JsonResponse
37
     */
38
    public function ajax()
39
    {
40
        return $this->datatables
41
            ->eloquent($this->query())
42
            ->editColumn('device.hostname', function($eventlog) {
43
                $hostname = is_null($eventlog->device) ? trans('devices.text.deleted') : $eventlog->device->hostname;
44
                return '<a href="'.url("devices/".$eventlog->device_id).'">'.$hostname.'</a>';
45
            })
46
            ->make(true);
47
    }
48
49
    /**
50
     * Get the query object to be processed by datatables.
51
     *
52
     * @return \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder
53
     */
54
    public function query()
55
    {
56
        $eventlogs = Eventlog::with('device')->select('eventlog.*');
57
        return $this->applyScopes($eventlogs);
58
    }
59
60
    /**
61
     * Optional method if you want to use html builder.
62
     *
63
     * @return \Yajra\Datatables\Html\Builder
64
     */
65
    public function html()
66
    {
67
        return $this->builder()
68
                    ->columns($this->getColumns())
69
                    ->parameters($this->getBuilderParameters());
70
    }
71
72
    /**
73
     * Get columns.
74
     *
75
     * @return array
76
     */
77
    private function getColumns()
78
    {
79
        return [
80
            'device.hostname' => [
81
                'title'       => trans('devices.label.hostname'),
82
            ],
83
            'type'      => [
84
                'title' => trans('general.text.type'),
85
                'name'  => 'eventlog.type',
86
            ],
87
            'message'   => [
88
                'title' => trans('general.text.message'),
89
            ],
90
            'datetime'  => [
91
                'title' => trans('general.text.timestamp'),
92
            ],
93
        ];
94
    }
95
96
    /**
97
     * Get filename for export.
98
     *
99
     * @return string
100
     */
101
    protected function filename()
102
    {
103
        return 'eventlog';
104
    }
105
106
    /**
107
     * Get Builder Params
108
     *
109
     * @return array
110
     */
111
    protected function getBuilderParameters()
112
    {
113
        return [
114
            'dom' => 'Blfrtip',
115
            'lengthMenu' => [[25, 50, 100, -1], [25, 50, 100, "All"]],
116
            'buttons' => [
117
                'csv', 'excel', 'pdf', 'print', 'reset', 'reload',
118
            ],
119
        ];
120
    }
121
122
}
123

app/DataTables/General/InventoryDataTable.php 1 location

@@ 31-124 (lines=94) @@
28
use App\Models\General\Inventory;
29
use Yajra\Datatables\Services\DataTable;
30
31
class InventoryDataTable extends DataTable
32
{
33
    /**
34
     * Display ajax response.
35
     *
36
     * @return \Illuminate\Http\JsonResponse
37
     */
38
    public function ajax()
39
    {
40
        return $this->datatables
41
            ->eloquent($this->query())
42
            ->editColumn('device.hostname', function($inventory) {
43
                $hostname = is_null($inventory->device) ? trans('devices.text.deleted') : $inventory->device->hostname;
44
                return '<a href="'.url("devices/".$inventory->device_id).'">'.$hostname.'</a>';
45
            })
46
            ->make(true);
47
    }
48
49
    /**
50
     * Get the query object to be processed by datatables.
51
     *
52
     * @return \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder
53
     */
54
    public function query()
55
    {
56
        $inventory = Inventory::with('device')->select('entPhysical.*');
57
        return $this->applyScopes($inventory);
58
    }
59
60
    /**
61
     * Optional method if you want to use html builder.
62
     *
63
     * @return \Yajra\Datatables\Html\Builder
64
     */
65
    public function html()
66
    {
67
        return $this->builder()
68
                    ->columns($this->getColumns())
69
                    ->parameters($this->getBuilderParameters());
70
    }
71
72
    /**
73
     * Get columns.
74
     *
75
     * @return array
76
     */
77
    private function getColumns()
78
    {
79
        return [
80
            'device.hostname' => [
81
                'title'       => trans('devices.label.hostname'),
82
            ],
83
            'entPhysicalDescr'      => [
84
                'title' => trans('general.text.description'),
85
            ],
86
            'entPhysicalName'   => [
87
                'title' => trans('general.text.name'),
88
            ],
89
            'entPhysicalModelName'  => [
90
                'title' => trans('general.text.model'),
91
            ],
92
            'entPhysicalSerialNum'  => [
93
                'title' => trans('general.text.serial'),
94
            ],
95
        ];
96
    }
97
98
    /**
99
     * Get filename for export.
100
     *
101
     * @return string
102
     */
103
    protected function filename()
104
    {
105
        return 'inventory';
106
    }
107
108
    /**
109
     * Get Builder Params
110
     *
111
     * @return array
112
     */
113
    protected function getBuilderParameters()
114
    {
115
        return [
116
            'dom' => 'Blfrtip',
117
            'lengthMenu' => [[25, 50, 100, -1], [25, 50, 100, "All"]],
118
            'buttons' => [
119
                'csv', 'excel', 'pdf', 'print', 'reset', 'reload',
120
            ],
121
        ];
122
    }
123
124
}
125