107 lines
		
	
	
		
			3.2 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			107 lines
		
	
	
		
			3.2 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?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(); |