Files
gestalt/kernel/app_modules/event/views/index.php
2025-06-18 14:50:18 +03:00

107 lines
3.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* @var \Illuminate\Database\Eloquent\Collection $event
* @var int $page_number
* @var \kernel\CgView $view
*/
use kernel\app_modules\event\models\Event;
use Itguild\EloquentTable\EloquentDataProvider;
use Itguild\EloquentTable\ListEloquentTable;
use kernel\widgets\IconBtn\IconBtnCreateWidget;
use kernel\widgets\IconBtn\IconBtnDeleteWidget;
use kernel\widgets\IconBtn\IconBtnEditWidget;
use kernel\widgets\IconBtn\IconBtnViewWidget;
$view->setTitle("Список event");
$view->setMeta([
'description' => 'Список event системы'
]);
$fillable = ['title', 'date_start', 'status', 'photo'];
//Для использования таблицы с моделью, необходимо создать таблицу в базе данных
$table = new ListEloquentTable(new EloquentDataProvider(Event::class, [
'currentPage' => $page_number,
'perPage' => 8,
'params' => ["class" => "table table-bordered", "border" => "2"],
'baseUrl' => "/admin/event",
'fillable' => $fillable
]));
$entityRelation = new \kernel\EntityRelation();
$additionals = $entityRelation->getEntityRelationsBySlug("event");
foreach ($additionals as $additional) {
if (in_array($additional, $fillable)){
$table->addColumn($additional, $additional, function ($id) use ($entityRelation, $additional) {
return $entityRelation->getAdditionalPropertyByEntityId("event", $id, $additional);
});
}
}
//$table = new \Itguild\Tables\ListJsonTable(json_encode(
// [
// 'meta' => [
// 'total' => 0,
// 'totalWithFilters' => 0,
// 'columns' => [
// 'title',
// 'slug',
// 'status',
// ],
// 'perPage' => 5,
// 'currentPage' => 1,
// 'baseUrl' => '/admin/some',
// 'params' => [
// 'class' => 'table table-bordered',
// 'border' => 2
// ]
// ],
// 'filters' => [],
// 'data' => [],
// ]
//));
// Пример фильтра
$table->columns([
'title' => [
'filter' => [
'class' => \Itguild\Tables\Filter\InputTextFilter::class,
'value' => $get['title'] ?? ''
]
],
'date_start' => [
'format' => 'date:d-m-Y',
],
'date_end' => [
'format' => 'date:d-m-Y',
],
'status' => [
'value' => function ($data) {
return Event::getStatus()[$data];
}
]
]);
$table->addColumn("Контакты", "event_contacts", function ($data){
$event = Event::with('contacts')->find($data);
return $event->contacts->pluck('title')->implode(', ');
});
$table->beforePrint(function () {
return IconBtnCreateWidget::create(['url' => '/admin/event/create'])->run();
});
$table->addAction(function($row) {
return IconBtnViewWidget::create(['url' => '/admin/event/view/' . $row['id']])->run();
});
$table->addAction(function($row) {
return IconBtnEditWidget::create(['url' => '/admin/event/update/' . $row['id']])->run();
});
$table->addAction(function($row) {
return IconBtnDeleteWidget::create(['url' => '/admin/event/delete/' . $row['id']])->run();
});
$table->create();
$table->render();