芝麻web文件管理V1.00
编辑当前文件:/home/sditechnicalteam/public_html/app/DataTables/NoticeBoardDataTable.php
editNoticePermission = user()->permission('edit_notice'); $this->deleteNoticePermission = user()->permission('delete_notice'); $this->viewNoticePermission = user()->permission('view_notice'); } /** * Build DataTable class. * * @param mixed $query Results from query() method. * @return \Yajra\DataTables\DataTableAbstract */ public function dataTable($query) { return datatables() ->eloquent($query) ->addColumn('check', function ($row) { return '
'; }) ->addColumn('action', function ($row) { $action = '
'; $action .= '
' . __('app.view') . '
'; if ($this->editNoticePermission == 'all' || ($this->editNoticePermission == 'added' && user()->id == $row->added_by) || ($this->editNoticePermission == 'owned' && in_array($row->to, user_roles())) || ($this->editNoticePermission == 'both' && (in_array($row->to, user_roles()) || $row->added_by == user()->id)) ) { $action .= '
' . trans('app.edit') . '
'; } if ($this->deleteNoticePermission == 'all' || ($this->deleteNoticePermission == 'added' && user()->id == $row->added_by) || ($this->deleteNoticePermission == 'owned' && in_array($row->to, user_roles())) || ($this->deleteNoticePermission == 'both' && (in_array($row->to, user_roles()) || $row->added_by == user()->id)) ) { $action .= '
' . trans('app.delete') . '
'; } $action .= '
'; return $action; }) ->editColumn( 'heading', function ($row) { return '
' . $row->heading . '
'; } ) ->editColumn( 'created_at', function ($row) { return $row->created_at->format($this->company->date_format); } ) ->editColumn( 'to', function ($row) { return ucfirst($row->to); } ) ->addIndexColumn() ->smart(false) ->setRowId(function ($row) { return 'row-' . $row->id; }) ->rawColumns(['action', 'heading', 'check']); } /*** * @param Notice $model * @return \Illuminate\Database\Query\Builder */ public function query(Notice $model) { $request = $this->request(); $model = $model->select('id', 'heading', 'to', 'created_at', 'added_by'); if ($request->startDate !== null && $request->startDate != 'null' && $request->startDate != '') { $startDate = Carbon::createFromFormat($this->company->date_format, $request->startDate)->toDateString(); $model = $model->where(DB::raw('DATE(notices.`created_at`)'), '>=', $startDate); } if ($request->endDate !== null && $request->endDate != 'null' && $request->endDate != '') { $endDate = Carbon::createFromFormat($this->company->date_format, $request->endDate)->toDateString(); $model = $model->where(DB::raw('DATE(notices.`created_at`)'), '<=', $endDate); } if ($request->searchText != '') { $model->where(function ($query) { $query->where('notices.heading', 'like', '%' . request('searchText') . '%'); }); } if (in_array('client', user_roles())) { $model = $model->where('to', 'client'); } if (in_array('client', user_roles())) { $model = $model->where('to', 'client'); } if ($this->viewNoticePermission == 'added') { $model->where('notices.added_by', user()->id); } return $model; } /** * Optional method if you want to use html builder. * * @return \Yajra\DataTables\Html\Builder */ public function html() { return $this->builder() ->setTableId('notice-board-table') ->columns($this->getColumns()) ->minifiedAjax() ->orderBy(3) ->destroy(true) ->responsive(true) ->serverSide(true) ->stateSave(true) ->processing(true) ->dom($this->domHtml) ->language(__('app.datatable')) ->buttons(Button::make(['extend' => 'excel', 'text' => '
' . trans('app.exportExcel')])) ->parameters([ 'initComplete' => 'function () { window.LaravelDataTables["notice-board-table"].buttons().container() .appendTo("#table-actions") }', 'fnDrawCallback' => 'function( oSettings ) { $("body").tooltip({ selector: \'[data-toggle="tooltip"]\' }) }', ]); } /** * Get columns. * * @return array */ protected function getColumns() { return [ 'check' => [ 'title' => '
', 'exportable' => false, 'orderable' => false, 'searchable' => false, 'visible' => !in_array('client', user_roles()) ], '#' => ['data' => 'DT_RowIndex', 'orderable' => false, 'searchable' => false, 'visible' => false], __('modules.notices.notice') => ['data' => 'heading', 'name' => 'heading', 'title' => __('modules.notices.notice')], __('app.date') => ['data' => 'created_at', 'name' => 'created_at', 'title' => __('app.date')], __('app.to') => ['data' => 'to', 'name' => 'to', 'title' => __('app.to'), 'visible' => !in_array('client', user_roles())], 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 'Notice_' . 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'); } }