芝麻web文件管理V1.00
编辑当前文件:/home/sditechnicalteam/public_html/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)->format($this->company->date_format); }) ->addColumn('occasion', function ($row) { return $row->occassion; }) ->addColumn('day', function ($row) { return $row->date->format('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() { return $this->builder() ->setTableId('holiday-table') ->columns($this->getColumns()) ->minifiedAjax() ->orderBy(1) ->destroy(true) ->responsive(true) ->serverSide(true) ->stateSave(true) ->processing(true) ->dom($this->domHtml) ->language(__('app.datatable')) ->parameters([ 'initComplete' => 'function () { window.LaravelDataTables["holiday-table"].buttons().container() .appendTo("#table-actions") }', 'fnDrawCallback' => 'function( oSettings ) { $("body").tooltip({ selector: \'[data-toggle="tooltip"]\' }); $(".statusChange").selectpicker(); }', ]) ->buttons(Button::make(['extend' => 'excel', 'text' => '
' . trans('app.exportExcel')])); } /** * 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], __('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') ]; } /** * Get filename for export. * * @return string */ protected function filename() { return 'holiday_' . date('YmdHis'); } public function pdf() { set_time_limit(0); if ('snappy' == config('datatables-buttons.pdf_generator', 'snappy')) { return $this->snappyPdf(); } $pdf = app('dompdf.wrapper'); $pdf->loadView('datatables::print', ['data' => $this->getDataForPrint()]); return $pdf->download($this->getFilename() . '.pdf'); } }