![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/ts.corals.io/corals-api/Corals/modules/Timesheet/DataTables/ |
<?php namespace Corals\Modules\Timesheet\DataTables; use Corals\Foundation\DataTables\BaseDataTable; use Corals\Modules\Timesheet\DataTables\Scopes\EntriesClientAndProjectScope; use Corals\Modules\Timesheet\DataTables\Scopes\InvoiceFilterScope; use Corals\Modules\Timesheet\Models\Entry; use Corals\Modules\Timesheet\Transformers\API\EntryTransformer; use Yajra\DataTables\EloquentDataTable; class EntriesDataTable extends BaseDataTable { /** * Build DataTable class. * * @param mixed $query Results from query() method. * @return \Yajra\DataTables\DataTableAbstract */ public function dataTable($query) { $this->setResourceUrl(config('Timesheet.models.entry.resource_url')); $dataTable = new EloquentDataTable($query); return $dataTable->setTransformer(new EntryTransformer()); } /** * @param Entry $model * @return \Illuminate\Database\Eloquent\Builder */ public function query(Entry $model) { return $model->newQuery() ->with(['user', 'project', 'activity', 'invoice']) ->when(user()->cannot('admin', Entry::class) && !user()->hasRole('client'), function ($notAdmin) { $notAdmin->where('timesheet_entries.user_id', user()->id); }) ->select('timesheet_entries.*'); } /** * Get columns. * * @return array */ protected function getColumns() { return [ 'id' => ['visible' => false], 'created_at' => ['title' => trans('Corals::attributes.created_at')], 'updated_at' => ['title' => trans('Corals::attributes.updated_at')], ]; } public function getFilters() { return [ 'description' => [ 'title' => trans('Timesheet::attributes.entry.description'), 'class' => 'col-md-2', 'type' => 'text', 'condition' => 'like', 'active' => true ], 'spent_at' => [ 'title' => trans('Timesheet::attributes.entry.spent_at'), 'class' => 'col-md-2', 'type' => 'date', 'active' => true ], 'user_id' => ['type' => 'number'], 'project' => ['builder' => EntriesClientAndProjectScope::class], 'client' => ['builder' => EntriesClientAndProjectScope::class], 'has_reviewed' => [ 'type' => 'boolean', 'active' => true ], 'invoice' => ['builder' => InvoiceFilterScope::class], ]; } }