You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
146 lines
5.6 KiB
146 lines
5.6 KiB
<?php
|
|
|
|
namespace App\Http\DataTables\Admission;
|
|
|
|
use App\Domains\Admission\Models\AdmissionSchedule;
|
|
use Illuminate\Database\Eloquent\Builder as QueryBuilder;
|
|
use Yajra\DataTables\EloquentDataTable;
|
|
use Yajra\DataTables\Html\Builder as HtmlBuilder;
|
|
use Yajra\DataTables\Html\Button;
|
|
use Yajra\DataTables\Html\Column;
|
|
use Yajra\DataTables\Services\DataTable;
|
|
|
|
class AdmissionScheduleDataTable extends DataTable
|
|
{
|
|
/**
|
|
* Build the DataTable class.
|
|
*
|
|
* @param QueryBuilder<AdmissionSchedule> $query Results from query() method.
|
|
*/
|
|
public function dataTable(QueryBuilder $query): EloquentDataTable
|
|
{
|
|
return (new EloquentDataTable($query))
|
|
->editColumn(
|
|
'action',
|
|
fn (AdmissionSchedule $admissionSchedule) => view('components.datatables.action-button', [
|
|
'log' => true,
|
|
'view' => [
|
|
'url' => route('admission-schedules.view', ['id' => $admissionSchedule->ulid]),
|
|
'permission' => auth()->user()->can('view', $admissionSchedule),
|
|
],
|
|
'edit' => [
|
|
'modal' => 'admissionschedule-form-modal',
|
|
'permission' => auth()->user()->can('update', $admissionSchedule),
|
|
],
|
|
'delete' => [
|
|
'url' => null,
|
|
'title' => __('ui.button.delete'),
|
|
'message' => __('ui.confirmation.delete', ['resource' => __('resources.admission-schedule')]),
|
|
'success_message' => __('ui.crud.success.deleted', ['resource' => __('resources.admission-schedule')]),
|
|
'permission' => auth()->user()->can('delete', $admissionSchedule),
|
|
],
|
|
'table_name' => 'admissionschedule-table',
|
|
'id' => $admissionSchedule->ulid,
|
|
])
|
|
)
|
|
->rawColumns(['action'])
|
|
->addIndexColumn();
|
|
}
|
|
|
|
/**
|
|
* Get the query source of dataTable.
|
|
*
|
|
* @return QueryBuilder<AdmissionSchedule>
|
|
*/
|
|
public function query(AdmissionSchedule $model): QueryBuilder
|
|
{
|
|
return $model->newQuery()
|
|
->join('admission_tracks', 'admission_tracks.id', '=', 'admission_schedules.admission_track_id')
|
|
->join('terms', 'terms.id', '=', 'admission_schedules.term_id')
|
|
->select('admission_schedules.*', 'admission_tracks.name as admission_track_name', 'terms.name as term_name');
|
|
}
|
|
|
|
/**
|
|
* Optional method if you want to use the html builder.
|
|
*/
|
|
public function html(): HtmlBuilder
|
|
{
|
|
return $this->builder()
|
|
->setTableId('admissionschedule-table')
|
|
->columns($this->getColumns())
|
|
->minifiedAjax()
|
|
->orderBy(-1)
|
|
->layout([
|
|
'topStart' => [
|
|
'rowClass' => 'row gap-1',
|
|
'className' => 'col-md-auto me-auto d-flex flex-sm-row flex-column justify-content-center justify-content-md-start align-items-center align-items-md-start gap-1',
|
|
'features' => ['buttons', 'pageLength'],
|
|
],
|
|
'topEnd' => [
|
|
'className' => 'col-md-auto ms-auto d-flex flex-sm-row flex-column justify-content-center justify-content-md-end align-items-center align-items-md-start gap-1',
|
|
'features' => ['search'],
|
|
],
|
|
|
|
'bottomStart' => 'info',
|
|
'bottomEnd' => 'paging',
|
|
])
|
|
->parameters([
|
|
'language' => [
|
|
'search' => '',
|
|
'searchPlaceholder' => __('ui.button.lookup'),
|
|
],
|
|
'fixedColumns' => [
|
|
'start' => 2,
|
|
],
|
|
'scrollX' => true,
|
|
'scrollCollapse' => true,
|
|
'responsive' => true,
|
|
])
|
|
->buttons([
|
|
Button::make('add')
|
|
->action('$("#admissionschedule-form-modal").modal("show");')
|
|
->text(svg('tabler-plus', ['width' => 16, 'height' => 16])->toHtml())
|
|
->addClass('btn-sm'),
|
|
Button::make('reload')
|
|
->text(svg('tabler-reload', ['width' => 16, 'height' => 16])->toHtml())
|
|
->addClass('btn-sm'),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Get the dataTable columns definition.
|
|
*/
|
|
public function getColumns(): array
|
|
{
|
|
return [
|
|
Column::computed('DT_RowIndex')
|
|
->width(10)
|
|
->title('#'),
|
|
Column::make('admission_track_name')
|
|
->width(450)
|
|
->title(__('domains/admission/field.admission-schedule.track_name')),
|
|
Column::make('term_name')
|
|
->width(250)
|
|
->title(__('domains/admission/field.admission-schedule.term_name')),
|
|
Column::computed('date_start')
|
|
->width(150)
|
|
->title(__('domains/admission/field.admission-schedule.date-start')),
|
|
Column::computed('date_end')
|
|
->width(150)
|
|
->title(__('domains/admission/field.admission-schedule.date-end')),
|
|
Column::computed('action')
|
|
->title(__('ui.label.actions'))
|
|
->exportable(false)
|
|
->printable(false)
|
|
->addClass('text-center'),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get the filename for export.
|
|
*/
|
|
protected function filename(): string
|
|
{
|
|
return 'AdmissionSchedule_'.date('YmdHis');
|
|
}
|
|
}
|
|
|