芝麻web文件管理V1.00
编辑当前文件:/home/qrafawbu/qrafiqxcreativeagency.com/accounts/office/app/DataTables/HolidayDataTable.php
viewPermission = user()->permission('view_holiday'); $this->editPermission = user()->permission('edit_holiday'); $this->deletePermission = user()->permission('delete_holiday'); } /** * Build DataTable class. * * @param mixed $query Results from query() method. * @return \Yajra\DataTables\DataTableAbstract */ public function dataTable($query) { return (new EloquentDataTable($query)) ->addIndexColumn() ->addColumn('check', function ($row) { return '
'; }) ->editColumn('holiday_date', function ($row) { return Carbon::parse($row->date)->translatedFormat($this->company->date_format); }) ->addColumn('occasion', function ($row) { return $row->occassion; }) ->addColumn('day', function ($row) { return $row->date->translatedFormat('l'); }) ->addColumn('action', function ($row) { $actions = '
'; $actions .= '
' . __('app.view') . '
'; if ($this->editPermission == 'all' || ($this->editPermission == 'added' && user()->id == $row->added_by)) { $actions .= '
' . __('app.edit') . '
'; } if ($this->deletePermission == 'all' || ($this->deletePermission == 'added' && user()->id == $row->added_by)) { $actions .= '
' . __('app.delete') . '
'; } $actions .= '
'; return $actions; }) ->smart(false) ->setRowId(function ($row) { return 'row-' . $row->id; }) ->orderColumn('holiday_date', 'date $1') ->orderColumn('day', 'day_name $1') ->rawColumns(['check', 'action']); } /** * @param Holiday $model * @return \Illuminate\Database\Query\Builder */ public function query(Holiday $model) { $holidays = $model->select('holidays.*', DB::raw('DAYNAME(date) as day_name')); if (!is_null(request()->year)) { $holidays->where(DB::raw('Year(holidays.date)'), request()->year); } if (!is_null(request()->month)) { $holidays->where(DB::raw('Month(holidays.date)'), request()->month); } if (request()->searchText != '') { $holidays->where('holidays.occassion', 'like', '%' . request()->searchText . '%'); } if ($this->viewPermission == 'added') { $holidays->where('holidays.added_by', user()->id); } return $holidays; } /** * Optional method if you want to use html builder. * * @return \Yajra\DataTables\Html\Builder */ public function html() { $dataTable = $this->setBuilder('holiday-table') ->parameters([ 'initComplete' => 'function () { window.LaravelDataTables["holiday-table"].buttons().container() .appendTo("#table-actions") }', 'fnDrawCallback' => 'function( oSettings ) { $("body").tooltip({ selector: \'[data-toggle="tooltip"]\' }); $(".statusChange").selectpicker(); }', ]); if (canDataTableExport()) { $dataTable->buttons(Button::make(['extend' => 'excel', 'text' => '
' . trans('app.exportExcel')])); } return $dataTable; } /** * Get columns. * * @return array */ protected function getColumns() { return [ 'check' => [ 'title' => '
', 'exportable' => false, 'orderable' => false, 'searchable' => false ], '#' => ['data' => 'DT_RowIndex', 'orderable' => false, 'searchable' => false, 'visible' => false, 'title' => '#'], __('modules.holiday.date') => ['data' => 'holiday_date', 'name' => 'date', 'title' => __('modules.holiday.date')], __('modules.holiday.occasion') => ['data' => 'occasion', 'name' => 'occasion', 'title' => __('modules.holiday.occasion')], __('modules.holiday.day') => ['data' => 'day', 'name' => 'day', 'title' => __('modules.holiday.day')], Column::computed('action', __('app.action')) ->exportable(false) ->printable(false) ->orderable(false) ->searchable(false) ->addClass('text-right pr-20') ]; } }