芝麻web文件管理V1.00
编辑当前文件:/home/qrafawbu/qrafiqxcreativeagency.com/accounts/office/app/DataTables/KnowledgeBaseDataTable.php
editKnowledgebasePermission = user()->permission('edit_knowledgebase'); $this->deleteKnowledgebasePermission = user()->permission('delete_knowledgebase'); } /** * 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->editKnowledgebasePermission == 'all' || ($this->editKnowledgebasePermission == 'added' && user()->id == $row->added_by)) { $action .= '
' . trans('app.edit') . '
'; } if ($this->deleteKnowledgebasePermission == 'all' || ($this->deleteKnowledgebasePermission == 'added' && user()->id == $row->added_by)) { $action .= '
' . trans('app.delete') . '
'; } $action .= '
'; return $action; }) ->editColumn( 'heading', function ($row) { $heading = '
' . $row->heading . '
'; return $heading; } ) ->editColumn( 'created_at', function ($row) { return $row->created_at->translatedFormat($this->company->date_format); } ) ->editColumn( 'to', function ($row) { return $row->to; } ) ->addIndexColumn() ->smart(false) ->setRowId(function ($row) { return 'row-' . $row->id; }) ->rawColumns(['action', 'check', 'heading']); } /** * Get query source of dataTable. * * @param \App\Models\KnowledgeBase $model * @return \Illuminate\Database\Eloquent\Builder */ public function query(KnowledgeBase $model) { $request = $this->request(); $model = $model->select('*'); 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(knowledge_bases.`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(knowledge_bases.`created_at`)'), '<=', $endDate); } if ($request->searchText != '') { $model->where(function ($query) { $query->where('knowledge_bases.heading', 'like', '%' . request('searchText') . '%'); }); } if (!in_array('admin', user_roles()) && !in_array('client', user_roles())) { $model = $model->where('to', 'employee'); } if (in_array('client', user_roles())) { $model = $model->where('to', 'client'); } if (user()->permission('view_knowledgebase') == 'added') { $model->where('added_by', user()->id); } return $model; } /** * Optional method if you want to use html builder. * * @return \Yajra\DataTables\Html\Builder */ public function html() { $dataTable = $this->setBuilder('knowledgebase-table', 3) ->parameters([ 'initComplete' => 'function () { window.LaravelDataTables["knowledgebase-table"].buttons().container() .appendTo("#table-actions") }', 'fnDrawCallback' => 'function( oSettings ) { $("body").tooltip({ selector: \'[data-toggle="tooltip"]\' }) }', ]); 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, 'visible' => true, ], '#' => ['data' => 'DT_RowIndex', 'orderable' => false, 'searchable' => false, 'visible' => false, 'title' => '#'], __('modules.knowledgeBase.knowledge') => ['data' => 'heading', 'name' => 'heading', 'title' => __('modules.knowledgeBase.knowledge')], __('app.date') => ['data' => 'created_at', 'name' => 'created_at', 'title' => __('app.date')], __('app.to') => ['data' => 'to', 'name' => 'to', 'title' => __('app.to')], Column::computed('action', __('app.action')) ->exportable(false) ->printable(false) ->orderable(false) ->searchable(false) ->width(150) ->addClass('text-right pr-20') ]; } }