first
This commit is contained in:
63
kernel/app_modules/event/EventModule.php
Normal file
63
kernel/app_modules/event/EventModule.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_modules\event;
|
||||
|
||||
use kernel\app_modules\event\models\Event;
|
||||
use kernel\helpers\Debug;
|
||||
use kernel\Module;
|
||||
use kernel\modules\menu\service\MenuService;
|
||||
use kernel\services\MigrationService;
|
||||
|
||||
class EventModule extends Module
|
||||
{
|
||||
|
||||
public MenuService $menuService;
|
||||
public MigrationService $migrationService;
|
||||
public function __construct()
|
||||
{
|
||||
$this->menuService = new MenuService();
|
||||
$this->migrationService = new MigrationService();
|
||||
}
|
||||
|
||||
public function init(): void
|
||||
{
|
||||
$this->migrationService->runAtPath("{KERNEL_APP_MODULES}/event/migrations");
|
||||
|
||||
$this->menuService->createItem([
|
||||
"label" => "Мероприятия",
|
||||
"url" => "/admin/event",
|
||||
"slug" => "event",
|
||||
]);
|
||||
|
||||
$this->menuService->createItem([
|
||||
"label" => "Список",
|
||||
"url" => "/admin/event",
|
||||
"slug" => "event_list",
|
||||
"parent_slug" => "event",
|
||||
]);
|
||||
$this->menuService->createItem([
|
||||
"label" => "Создать",
|
||||
"url" => "/admin/event/create",
|
||||
"slug" => "event_create",
|
||||
"parent_slug" => "event",
|
||||
]);
|
||||
$this->menuService->createItem([
|
||||
"label" => "Контакты",
|
||||
"url" => "/admin/event-contacts",
|
||||
"slug" => "event_contacts",
|
||||
"parent_slug" => "event",
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function deactivate(): void
|
||||
{
|
||||
$this->migrationService->rollbackAtPath("{KERNEL_APP_MODULES}/event/migrations");
|
||||
$this->menuService->removeItemBySlug("event_contacts");
|
||||
$this->menuService->removeItemBySlug("event_create");
|
||||
$this->menuService->removeItemBySlug("event_list");
|
||||
$this->menuService->removeItemBySlug("event");
|
||||
}
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_modules\event\controllers;
|
||||
|
||||
use Exception;
|
||||
use JetBrains\PhpStorm\NoReturn;
|
||||
use kernel\AdminController;
|
||||
use kernel\app_modules\event\models\forms\CreateEventContactForm;
|
||||
use kernel\app_modules\event\models\EventContact;
|
||||
use kernel\app_modules\event\services\EventContactService;
|
||||
use kernel\helpers\Debug;
|
||||
|
||||
class EventContactController extends AdminController
|
||||
{
|
||||
private EventContactService $eventService;
|
||||
protected function init(): void
|
||||
{
|
||||
parent::init();
|
||||
$this->cgView->viewPath = KERNEL_APP_MODULES_DIR . "/event/views/eventcontact/";
|
||||
$this->eventService = new EventContactService();
|
||||
}
|
||||
|
||||
public function actionCreate(): void
|
||||
{
|
||||
$this->cgView->render("form.php");
|
||||
}
|
||||
|
||||
#[NoReturn] public function actionAdd(): void
|
||||
{
|
||||
$eventForm = new CreateEventContactForm();
|
||||
$eventForm->load($_REQUEST);
|
||||
if ($eventForm->validate()){
|
||||
$event = $this->eventService->create($eventForm);
|
||||
if ($event){
|
||||
$this->redirect("/admin/event-contacts/view/" . $event->id);
|
||||
}
|
||||
}
|
||||
$this->redirect("/admin/event-contacts/create");
|
||||
}
|
||||
|
||||
public function actionIndex($page_number = 1): void
|
||||
{
|
||||
$this->cgView->render("index.php", ['page_number' => $page_number]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function actionView($id): void
|
||||
{
|
||||
$event = EventContact::find($id);
|
||||
|
||||
if (!$event){
|
||||
throw new Exception(message: "The event contact not found");
|
||||
}
|
||||
$this->cgView->render("view.php", ['event' => $event]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function actionUpdate($id): void
|
||||
{
|
||||
$model = EventContact::find($id);
|
||||
if (!$model){
|
||||
throw new Exception(message: "The event contact not found");
|
||||
}
|
||||
|
||||
$this->cgView->render("form.php", ['model' => $model]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function actionEdit($id): void
|
||||
{
|
||||
$event = EventContact::find($id);
|
||||
if (!$event){
|
||||
throw new Exception(message: "The event not found");
|
||||
}
|
||||
$eventForm = new CreateEventContactForm();
|
||||
$eventService = new EventContactService();
|
||||
$eventForm->load($_REQUEST);
|
||||
if ($eventForm->validate()) {
|
||||
$event = $eventService->update($eventForm, $event);
|
||||
if ($event) {
|
||||
$this->redirect("/admin/event-contacts/view/" . $event->id);
|
||||
}
|
||||
}
|
||||
$this->redirect("/admin/event-contacts/update/" . $id);
|
||||
}
|
||||
|
||||
#[NoReturn] public function actionDelete($id): void
|
||||
{
|
||||
$event = EventContact::find($id)->first();
|
||||
$event->delete();
|
||||
$this->redirect("/admin/event-contacts/");
|
||||
}
|
||||
}
|
109
kernel/app_modules/event/controllers/EventController.php
Normal file
109
kernel/app_modules/event/controllers/EventController.php
Normal file
@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_modules\event\controllers;
|
||||
|
||||
use Exception;
|
||||
use JetBrains\PhpStorm\NoReturn;
|
||||
use kernel\AdminController;
|
||||
use kernel\app_modules\event\models\forms\CreateEventForm;
|
||||
use kernel\app_modules\event\models\Event;
|
||||
use kernel\app_modules\event\services\EventService;
|
||||
use kernel\EntityRelation;
|
||||
use kernel\helpers\Debug;
|
||||
use kernel\Request;
|
||||
|
||||
class EventController extends AdminController
|
||||
{
|
||||
private EventService $eventService;
|
||||
protected function init(): void
|
||||
{
|
||||
parent::init();
|
||||
$this->cgView->viewPath = KERNEL_APP_MODULES_DIR . "/event/views/";
|
||||
$this->eventService = new EventService();
|
||||
}
|
||||
|
||||
public function actionCreate(): void
|
||||
{
|
||||
$this->cgView->render("form.php");
|
||||
}
|
||||
|
||||
#[NoReturn] public function actionAdd(): void
|
||||
{
|
||||
$eventForm = new CreateEventForm();
|
||||
$eventForm->load($_REQUEST);
|
||||
if ($eventForm->validate()){
|
||||
$event = $this->eventService->create($eventForm);
|
||||
|
||||
$entityRelation = new EntityRelation();
|
||||
$entityRelation->saveEntityRelation(entity: "event", model: $event, request: new Request());
|
||||
|
||||
if ($event){
|
||||
$this->redirect("/admin/event/view/" . $event->id);
|
||||
}
|
||||
}
|
||||
$this->redirect("/admin/event/create");
|
||||
}
|
||||
|
||||
public function actionIndex($page_number = 1): void
|
||||
{
|
||||
$this->cgView->render("index.php", ['page_number' => $page_number]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function actionView($id): void
|
||||
{
|
||||
$event = Event::find($id);
|
||||
|
||||
if (!$event){
|
||||
throw new Exception(message: "The event not found");
|
||||
}
|
||||
$this->cgView->render("view.php", ['event' => $event]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function actionUpdate($id): void
|
||||
{
|
||||
$model = Event::find($id);
|
||||
if (!$model){
|
||||
throw new Exception(message: "The event not found");
|
||||
}
|
||||
|
||||
$this->cgView->render("form.php", ['model' => $model]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function actionEdit($id): void
|
||||
{
|
||||
$event = Event::find($id);
|
||||
if (!$event){
|
||||
throw new Exception(message: "The event not found");
|
||||
}
|
||||
$eventForm = new CreateEventForm();
|
||||
$eventService = new EventService();
|
||||
$eventForm->load($_REQUEST);
|
||||
if ($eventForm->validate()) {
|
||||
$event = $eventService->update($eventForm, $event);
|
||||
|
||||
$entityRelation = new EntityRelation();
|
||||
$entityRelation->saveEntityRelation(entity: "event", model: $event, request: new Request());
|
||||
|
||||
if ($event) {
|
||||
$this->redirect("/admin/event/view/" . $event->id);
|
||||
}
|
||||
}
|
||||
$this->redirect("/admin/event/update/" . $id);
|
||||
}
|
||||
|
||||
#[NoReturn] public function actionDelete($id): void
|
||||
{
|
||||
$event = Event::find($id)->first();
|
||||
$event->delete();
|
||||
$this->redirect("/admin/event/");
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
\kernel\App::$db->schema->create('event', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('title', 255)->nullable(false);
|
||||
$table->string('type', 255)->nullable(false);
|
||||
$table->integer('hours_count')->nullable(false);
|
||||
$table->dateTime('date_start')->nullable(false);
|
||||
$table->dateTime('date_end')->nullable(true);
|
||||
$table->string('place')->nullable(false);
|
||||
$table->text('event_format')->nullable(true);
|
||||
$table->text('description')->nullable(false);
|
||||
$table->text('additional_info')->nullable(true);
|
||||
$table->integer('status')->nullable(true)->default(1);
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
\kernel\App::$db->schema->create('event_contact', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('title', 255)->nullable(false);
|
||||
$table->string('type', 255)->nullable(false);
|
||||
$table->integer('event_id')->nullable(false);
|
||||
$table->integer('status')->nullable(true)->default(1);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
\kernel\App::$db->schema->dropIfExists('event_contact');
|
||||
\kernel\App::$db->schema->dropIfExists('event');
|
||||
}
|
||||
};
|
110
kernel/app_modules/event/models/Event.php
Normal file
110
kernel/app_modules/event/models/Event.php
Normal file
@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_modules\event\models;
|
||||
|
||||
use DateTime;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use kernel\helpers\Debug;
|
||||
|
||||
// Добавить @property
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $status
|
||||
* @property int $hours_count
|
||||
* @property string $title
|
||||
* @property string $type
|
||||
* @property string $date_start
|
||||
* @property string $dateStartFormated
|
||||
* @property string $dateStartFormatedToForm
|
||||
* @property string $dateEndFormatedToForm
|
||||
* @property string $dateEndFormated
|
||||
* @property string $date_end
|
||||
* @property string $place
|
||||
* @property string $event_format
|
||||
* @property string $description
|
||||
* @property string $additional_info
|
||||
*/
|
||||
class Event extends Model
|
||||
{
|
||||
const DISABLE_STATUS = 0;
|
||||
const ACTIVE_STATUS = 1;
|
||||
|
||||
protected $table = 'event';
|
||||
|
||||
protected $fillable = ['title', 'type', 'hours_count', 'date_start', 'date_end', 'place', 'event_format', 'description', 'additional_info', 'status'];
|
||||
|
||||
public static function labels(): array
|
||||
{
|
||||
return [
|
||||
'title' => 'Название',
|
||||
'type' => 'Тип',
|
||||
'hours_count' => 'Количество часов',
|
||||
'date_start' => 'Дата начала',
|
||||
'date_end' => 'Дата окончания',
|
||||
'place' => 'Место',
|
||||
'event_format' => 'Формат',
|
||||
'description' => 'Описание',
|
||||
'additional_info' => 'Дополнительная информация',
|
||||
'status' => 'Статус',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public static function getStatus(): array
|
||||
{
|
||||
return [
|
||||
self::DISABLE_STATUS => "Не активный",
|
||||
self::ACTIVE_STATUS => "Активный",
|
||||
];
|
||||
}
|
||||
|
||||
public function contacts(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(EventContact::class);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getDateStartFormatedAttribute(): string
|
||||
{
|
||||
$startDate = new DateTime($this->date_start);
|
||||
|
||||
return $startDate->format("d-m-Y");
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getDateStartFormatedToFormAttribute(): string
|
||||
{
|
||||
$startDate = new DateTime($this->date_start);
|
||||
|
||||
return $startDate->format("Y-m-d");
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getDateEndFormatedAttribute(): string
|
||||
{
|
||||
$endDate = new DateTime($this->date_end);
|
||||
|
||||
return $endDate->format("d-m-Y");
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getDateEndFormatedToFormAttribute(): string
|
||||
{
|
||||
$endDate = new DateTime($this->date_end);
|
||||
|
||||
return $endDate->format("Y-m-d");
|
||||
}
|
||||
|
||||
|
||||
}
|
61
kernel/app_modules/event/models/EventContact.php
Normal file
61
kernel/app_modules/event/models/EventContact.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_modules\event\models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
// Добавить @property
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $status
|
||||
* @property int $event_id
|
||||
* @property string $title
|
||||
* @property string $type
|
||||
*/
|
||||
class EventContact extends Model
|
||||
{
|
||||
const DISABLE_STATUS = 0;
|
||||
const ACTIVE_STATUS = 1;
|
||||
|
||||
const TYPE_EMAIL = 'email';
|
||||
const TYPE_PHONE = 'phone';
|
||||
const TYPE_TG = 'tg';
|
||||
|
||||
protected $table = 'event_contact';
|
||||
|
||||
protected $fillable = ['title', 'type', 'event_id', 'status']; // Заполнить массив. Пример: ['label', 'slug', 'status']
|
||||
|
||||
public static function labels(): array
|
||||
{
|
||||
return [
|
||||
'title' => 'Название',
|
||||
'type' => 'Тип',
|
||||
'event_id' => 'Мероприятие',
|
||||
'status' => 'Статус',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public static function getStatus(): array
|
||||
{
|
||||
return [
|
||||
self::DISABLE_STATUS => "Не активный",
|
||||
self::ACTIVE_STATUS => "Активный",
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public static function getTypes(): array
|
||||
{
|
||||
return [
|
||||
self::TYPE_EMAIL => "Email",
|
||||
self::TYPE_PHONE => "Телефон",
|
||||
self::TYPE_TG => "Телеграм",
|
||||
];
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_modules\event\models\forms;
|
||||
|
||||
use kernel\FormModel;
|
||||
|
||||
class CreateEventContactForm extends FormModel
|
||||
{
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
// Заполнить массив правил
|
||||
// Пример:
|
||||
// return [
|
||||
// 'label' => 'required|min-str-len:5|max-str-len:30',
|
||||
// 'entity' => 'required',
|
||||
// 'slug' => '',
|
||||
// 'status' => ''
|
||||
// ];
|
||||
return [
|
||||
'title' => 'required|min-str-len:5|max-str-len:30',
|
||||
'type' => 'required|min-str-len:5|max-str-len:30',
|
||||
'event_id' => 'required|integer',
|
||||
'status' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
}
|
34
kernel/app_modules/event/models/forms/CreateEventForm.php
Normal file
34
kernel/app_modules/event/models/forms/CreateEventForm.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_modules\event\models\forms;
|
||||
|
||||
use kernel\FormModel;
|
||||
|
||||
class CreateEventForm extends FormModel
|
||||
{
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
// Заполнить массив правил
|
||||
// Пример:
|
||||
// return [
|
||||
// 'label' => 'required|min-str-len:5|max-str-len:30',
|
||||
// 'entity' => 'required',
|
||||
// 'slug' => '',
|
||||
// 'status' => ''
|
||||
// ];
|
||||
return [
|
||||
'title' => 'required|min-str-len:5|max-str-len:30',
|
||||
'type' => 'required|min-str-len:5|max-str-len:30',
|
||||
'hours_count' => 'required',
|
||||
'date_start' => 'date',
|
||||
'date_end' => 'date',
|
||||
'place' => 'required|min-str-len:5|max-str-len:30',
|
||||
'event_format' => '',
|
||||
'description' => 'required|min-str-len:5',
|
||||
'additional_info' => '',
|
||||
'status' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
}
|
35
kernel/app_modules/event/routs/event.php
Normal file
35
kernel/app_modules/event/routs/event.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use kernel\App;
|
||||
use kernel\CgRouteCollector;
|
||||
use Phroute\Phroute\RouteCollector;
|
||||
|
||||
App::$collector->group(["prefix" => "admin"], function (CgRouteCollector $router) {
|
||||
App::$collector->group(["before" => "auth"], function (RouteCollector $router) {
|
||||
App::$collector->group(["prefix" => "event"], function (CGRouteCollector $router) {
|
||||
App::$collector->get('/', [\app\modules\event\controllers\EventController::class, 'actionIndex']);
|
||||
App::$collector->get('/page/{page_number}', [\app\modules\event\controllers\EventController::class, 'actionIndex']);
|
||||
App::$collector->get('/create', [\app\modules\event\controllers\EventController::class, 'actionCreate']);
|
||||
App::$collector->post("/", [\app\modules\event\controllers\EventController::class, 'actionAdd']);
|
||||
App::$collector->get('/view/{id}', [\app\modules\event\controllers\EventController::class, 'actionView']);
|
||||
App::$collector->any('/update/{id}', [\app\modules\event\controllers\EventController::class, 'actionUpdate']);
|
||||
App::$collector->any("/edit/{id}", [\app\modules\event\controllers\EventController::class, 'actionEdit']);
|
||||
App::$collector->get('/delete/{id}', [\app\modules\event\controllers\EventController::class, 'actionDelete']);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
App::$collector->group(["prefix" => "admin"], function (CgRouteCollector $router) {
|
||||
App::$collector->group(["before" => "auth"], function (RouteCollector $router) {
|
||||
App::$collector->group(["prefix" => "event-contacts"], function (CGRouteCollector $router) {
|
||||
App::$collector->get('/', [\kernel\app_modules\event\controllers\EventContactController::class, 'actionIndex']);
|
||||
App::$collector->get('/page/{page_number}', [\kernel\app_modules\event\controllers\EventContactController::class, 'actionIndex']);
|
||||
App::$collector->get('/create', [\kernel\app_modules\event\controllers\EventContactController::class, 'actionCreate']);
|
||||
App::$collector->post("/", [\kernel\app_modules\event\controllers\EventContactController::class, 'actionAdd']);
|
||||
App::$collector->get('/view/{id}', [\kernel\app_modules\event\controllers\EventContactController::class, 'actionView']);
|
||||
App::$collector->any('/update/{id}', [\kernel\app_modules\event\controllers\EventContactController::class, 'actionUpdate']);
|
||||
App::$collector->any("/edit/{id}", [\kernel\app_modules\event\controllers\EventContactController::class, 'actionEdit']);
|
||||
App::$collector->get('/delete/{id}', [\kernel\app_modules\event\controllers\EventContactController::class, 'actionDelete']);
|
||||
});
|
||||
});
|
||||
});
|
41
kernel/app_modules/event/services/EventContactService.php
Normal file
41
kernel/app_modules/event/services/EventContactService.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_modules\event\services;
|
||||
|
||||
use kernel\helpers\Debug;
|
||||
use kernel\app_modules\event\models\EventContact;
|
||||
use kernel\FormModel;
|
||||
|
||||
class EventContactService
|
||||
{
|
||||
public function create(FormModel $form_model): false|EventContact
|
||||
{
|
||||
$model = new EventContact();
|
||||
// Пример заполнения:
|
||||
$model->title = $form_model->getItem('title');
|
||||
$model->type = $form_model->getItem('type');
|
||||
$model->event_id = $form_model->getItem('event_id');
|
||||
$model->status = $form_model->getItem('status');
|
||||
|
||||
if ($model->save()){
|
||||
return $model;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function update(FormModel $form_model, EventContact $event): false|EventContact
|
||||
{
|
||||
// Пример обновления:
|
||||
$event->title = $form_model->getItem('title');
|
||||
$event->type = $form_model->getItem('type');
|
||||
$event->event_id = $form_model->getItem('event_id');
|
||||
$event->status = $form_model->getItem('status');
|
||||
|
||||
if ($event->save()){
|
||||
return $event;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
58
kernel/app_modules/event/services/EventService.php
Normal file
58
kernel/app_modules/event/services/EventService.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_modules\event\services;
|
||||
|
||||
use kernel\helpers\Debug;
|
||||
use kernel\app_modules\event\models\Event;
|
||||
use kernel\FormModel;
|
||||
|
||||
class EventService
|
||||
{
|
||||
public function create(FormModel $form_model): false|Event
|
||||
{
|
||||
$model = new Event();
|
||||
$model->title = $form_model->getItem('title');
|
||||
$model->type = $form_model->getItem('type');
|
||||
$model->hours_count = $form_model->getItem('hours_count');
|
||||
$model->date_start = $form_model->getItem('date_start');
|
||||
$model->date_end = $form_model->getItem('date_end');
|
||||
$model->place = $form_model->getItem('place');
|
||||
$model->event_format = $form_model->getItem('event_format');
|
||||
$model->description = $form_model->getItem('description');
|
||||
$model->additional_info = $form_model->getItem('additional_info');
|
||||
$model->status = $form_model->getItem('status');
|
||||
|
||||
if ($model->save()){
|
||||
return $model;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function update(FormModel $form_model, Event $event): false|Event
|
||||
{
|
||||
$event->title = $form_model->getItem('title');
|
||||
$event->type = $form_model->getItem('type');
|
||||
$event->hours_count = $form_model->getItem('hours_count');
|
||||
$event->date_start = $form_model->getItem('date_start');
|
||||
$event->date_end = $form_model->getItem('date_end');
|
||||
$event->place = $form_model->getItem('place');
|
||||
$event->event_format = $form_model->getItem('event_format');
|
||||
$event->description = $form_model->getItem('description');
|
||||
$event->additional_info = $form_model->getItem('additional_info');
|
||||
$event->status = $form_model->getItem('status');
|
||||
|
||||
if ($event->save()){
|
||||
return $event;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function getList(): array
|
||||
{
|
||||
return Event::select('id', 'title')->get()
|
||||
->pluck('title', 'id')
|
||||
->toArray();
|
||||
}
|
||||
}
|
71
kernel/app_modules/event/views/eventcontact/form.php
Normal file
71
kernel/app_modules/event/views/eventcontact/form.php
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/**
|
||||
* @var EventContact $model
|
||||
*/
|
||||
|
||||
use kernel\app_modules\event\models\EventContact;
|
||||
|
||||
$form = new \itguild\forms\ActiveForm();
|
||||
$form->beginForm(isset($model) ? "/admin/event-contacts/edit/" . $model->id : "/admin/event-contacts", 'multipart/form-data');
|
||||
|
||||
// Пример формы:
|
||||
|
||||
|
||||
$form->field(\itguild\forms\inputs\TextInput::class, 'title', [
|
||||
'class' => "form-control",
|
||||
'placeholder' => 'Контакт',
|
||||
'value' => $model->title ?? ''
|
||||
])
|
||||
->setLabel("Контакт")
|
||||
->render();
|
||||
|
||||
$form->field(class: \itguild\forms\inputs\Select::class, name: "type", params: [
|
||||
'class' => "form-control",
|
||||
'value' => $model->type ?? ''
|
||||
])
|
||||
->setLabel("Тип контакта")
|
||||
->setOptions(EventContact::getTypes())
|
||||
->render();
|
||||
|
||||
$form->field(class: \itguild\forms\inputs\Select::class, name: "event_id", params: [
|
||||
'class' => "form-control",
|
||||
'value' => $model->event_id ?? ''
|
||||
])
|
||||
->setLabel("Мероприятие")
|
||||
->setOptions(\kernel\app_modules\event\services\EventService::getList())
|
||||
->render();
|
||||
|
||||
$form->field(class: \itguild\forms\inputs\Select::class, name: "status", params: [
|
||||
'class' => "form-control",
|
||||
'value' => $model->status ?? ''
|
||||
])
|
||||
->setLabel("Статус")
|
||||
->setOptions(EventContact::getStatus())
|
||||
->render();
|
||||
|
||||
|
||||
?>
|
||||
<div class="row">
|
||||
<div class="col-sm-2">
|
||||
<?php
|
||||
$form->field(\itguild\forms\inputs\Button::class, name: "btn-submit", params: [
|
||||
'class' => "btn btn-primary ",
|
||||
'value' => 'Отправить',
|
||||
'typeInput' => 'submit'
|
||||
])
|
||||
->render();
|
||||
?>
|
||||
</div>
|
||||
<div class="col-sm-2">
|
||||
<?php
|
||||
$form->field(\itguild\forms\inputs\Button::class, name: "btn-reset", params: [
|
||||
'class' => "btn btn-warning",
|
||||
'value' => 'Сбросить',
|
||||
'typeInput' => 'reset'
|
||||
])
|
||||
->render();
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
$form->endForm();
|
89
kernel/app_modules/event/views/eventcontact/index.php
Normal file
89
kernel/app_modules/event/views/eventcontact/index.php
Normal file
@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Database\Eloquent\Collection $event
|
||||
* @var int $page_number
|
||||
* @var \kernel\CgView $view
|
||||
*/
|
||||
|
||||
use kernel\app_modules\event\models\EventContact;
|
||||
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 contacts");
|
||||
$view->setMeta([
|
||||
'description' => 'Список event contacts системы'
|
||||
]);
|
||||
|
||||
//Для использования таблицы с моделью, необходимо создать таблицу в базе данных
|
||||
$table = new ListEloquentTable(new EloquentDataProvider(EventContact::class, [
|
||||
'currentPage' => $page_number,
|
||||
'perPage' => 8,
|
||||
'params' => ["class" => "table table-bordered", "border" => "2"],
|
||||
'baseUrl' => "/admin/event-contacts"
|
||||
]));
|
||||
|
||||
|
||||
//$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'] ?? ''
|
||||
]
|
||||
],
|
||||
'event_id' => [
|
||||
'value' => function ($data) {
|
||||
$model = \kernel\app_modules\event\models\Event::find($data);
|
||||
return $model->title ?? '';
|
||||
}
|
||||
],
|
||||
'status' => [
|
||||
'value' => function ($data) {
|
||||
return EventContact::getStatus()[$data];
|
||||
}
|
||||
]
|
||||
]);
|
||||
|
||||
$table->beforePrint(function () {
|
||||
return IconBtnCreateWidget::create(['url' => '/admin/event-contacts/create'])->run();
|
||||
});
|
||||
|
||||
$table->addAction(function($row) {
|
||||
return IconBtnViewWidget::create(['url' => '/admin/event-contacts/view/' . $row['id']])->run();
|
||||
});
|
||||
$table->addAction(function($row) {
|
||||
return IconBtnEditWidget::create(['url' => '/admin/event-contacts/update/' . $row['id']])->run();
|
||||
});
|
||||
$table->addAction(function($row) {
|
||||
return IconBtnDeleteWidget::create(['url' => '/admin/event-contacts/delete/' . $row['id']])->run();
|
||||
});
|
||||
$table->create();
|
||||
$table->render();
|
40
kernel/app_modules/event/views/eventcontact/view.php
Normal file
40
kernel/app_modules/event/views/eventcontact/view.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Database\Eloquent\Collection $event
|
||||
*/
|
||||
|
||||
use Itguild\EloquentTable\ViewEloquentTable;
|
||||
use Itguild\EloquentTable\ViewJsonTableEloquentModel;
|
||||
use kernel\app_modules\event\models\EventContact;
|
||||
use kernel\widgets\IconBtn\IconBtnDeleteWidget;
|
||||
use kernel\widgets\IconBtn\IconBtnEditWidget;
|
||||
use kernel\widgets\IconBtn\IconBtnListWidget;
|
||||
|
||||
$table = new ViewEloquentTable(new ViewJsonTableEloquentModel($event, [
|
||||
'params' => ["class" => "table table-bordered", "border" => "2"],
|
||||
'baseUrl' => "/admin/event-contacts",
|
||||
]));
|
||||
$table->beforePrint(function () use ($event) {
|
||||
$btn = IconBtnListWidget::create(['url' => '/admin/event-contacts'])->run();
|
||||
$btn .= IconBtnEditWidget::create(['url' => '/admin/event-contacts/update/' . $event->id])->run();
|
||||
$btn .= IconBtnDeleteWidget::create(['url' => '/admin/event-contacts/delete/' . $event->id])->run();
|
||||
return $btn;
|
||||
});
|
||||
|
||||
$table->rows([
|
||||
'event_id' => [
|
||||
'value' => function ($data) {
|
||||
$model = \kernel\app_modules\event\models\Event::find($data);
|
||||
return $model->title ?? '';
|
||||
}
|
||||
],
|
||||
'status' => [
|
||||
'value' => function ($data) {
|
||||
return EventContact::getStatus()[$data];
|
||||
}
|
||||
]
|
||||
]);
|
||||
|
||||
$table->create();
|
||||
$table->render();
|
136
kernel/app_modules/event/views/form.php
Normal file
136
kernel/app_modules/event/views/form.php
Normal file
@ -0,0 +1,136 @@
|
||||
<?php
|
||||
/**
|
||||
* @var Event $model
|
||||
*/
|
||||
|
||||
use kernel\app_modules\event\models\Event;
|
||||
|
||||
$form = new \itguild\forms\ActiveForm();
|
||||
$form->beginForm(isset($model) ? "/admin/event/edit/" . $model->id : "/admin/event", 'multipart/form-data');
|
||||
|
||||
// Пример формы:
|
||||
|
||||
|
||||
$form->field(\itguild\forms\inputs\TextInput::class, 'title', [
|
||||
'class' => "form-control",
|
||||
'placeholder' => 'Название',
|
||||
'value' => $model->title ?? ''
|
||||
])
|
||||
->setLabel("Название мероприятие")
|
||||
->render();
|
||||
|
||||
$form->field(\itguild\forms\inputs\TextInput::class, 'type', [
|
||||
'class' => "form-control",
|
||||
'placeholder' => 'Тип',
|
||||
'value' => $model->type ?? ''
|
||||
])
|
||||
->setLabel("Тип мероприятие")
|
||||
->render();
|
||||
|
||||
$form->field(\itguild\forms\inputs\TextInput::class, 'hours_count', [
|
||||
'class' => "form-control",
|
||||
'type' => 'number',
|
||||
'placeholder' => 'Кол-во часов',
|
||||
'value' => $model->hours_count ?? ''
|
||||
])
|
||||
->setLabel("Кол-во часов")
|
||||
->render();
|
||||
|
||||
$form->field(\itguild\forms\inputs\TextInput::class, 'date_start', [
|
||||
'class' => "form-control",
|
||||
'placeholder' => 'Дата начала',
|
||||
'type' => 'date',
|
||||
'value' => $model->dateStartFormatedToForm ?? ''
|
||||
])
|
||||
->setLabel("Дата начала")
|
||||
->render();
|
||||
|
||||
$form->field(\itguild\forms\inputs\TextInput::class, 'date_end', [
|
||||
'class' => "form-control",
|
||||
'placeholder' => 'Дата окончания',
|
||||
'type' => 'date',
|
||||
'value' => $model->dateEndFormatedToForm ?? ''
|
||||
])
|
||||
->setLabel("Дата окончания")
|
||||
->render();
|
||||
|
||||
$form->field(\itguild\forms\inputs\TextInput::class, 'place', [
|
||||
'class' => "form-control",
|
||||
'placeholder' => 'Место',
|
||||
'value' => $model->place ?? ''
|
||||
])
|
||||
->setLabel("Место провежения")
|
||||
->render();
|
||||
|
||||
$form->field(\itguild\forms\inputs\TextArea::class, 'event_format', [
|
||||
'class' => "form-control",
|
||||
'placeholder' => 'Формат',
|
||||
'value' => $model->event_format ?? ''
|
||||
])
|
||||
->setLabel("Формат мероприятия")
|
||||
->render();
|
||||
|
||||
$form->field(\itguild\forms\inputs\TextArea::class, 'description', [
|
||||
'class' => "form-control",
|
||||
'placeholder' => 'Описание',
|
||||
'value' => $model->description ?? ''
|
||||
])
|
||||
->setLabel("Описание")
|
||||
->render();
|
||||
|
||||
$form->field(\itguild\forms\inputs\TextArea::class, 'additional_info', [
|
||||
'class' => "form-control",
|
||||
'placeholder' => 'Дополнительная информация',
|
||||
'value' => $model->additional_info ?? ''
|
||||
])
|
||||
->setLabel("Дополнительная информация")
|
||||
->render();
|
||||
|
||||
$form->field(class: \itguild\forms\inputs\Select::class, name: "status", params: [
|
||||
'class' => "form-control",
|
||||
'value' => $model->status ?? ''
|
||||
])
|
||||
->setLabel("Статус")
|
||||
->setOptions(Event::getStatus())
|
||||
->render();
|
||||
|
||||
$entityRelations = new \kernel\EntityRelation();
|
||||
if (!isset($model)) {
|
||||
$model = new Event();
|
||||
}
|
||||
$entityRelations->renderEntityAdditionalPropertyFormBySlug("event", $model);
|
||||
|
||||
//$form->field(class: \itguild\forms\inputs\Select::class, name: "user_id", params: [
|
||||
// 'class' => "form-control",
|
||||
// 'value' => $model->user_id ?? ''
|
||||
//])
|
||||
// ->setLabel("Пользователи")
|
||||
// ->setOptions(\kernel\modules\user\service\UserService::createUsernameArr())
|
||||
// ->render();
|
||||
|
||||
|
||||
?>
|
||||
<div class="row">
|
||||
<div class="col-sm-2">
|
||||
<?php
|
||||
$form->field(\itguild\forms\inputs\Button::class, name: "btn-submit", params: [
|
||||
'class' => "btn btn-primary ",
|
||||
'value' => 'Отправить',
|
||||
'typeInput' => 'submit'
|
||||
])
|
||||
->render();
|
||||
?>
|
||||
</div>
|
||||
<div class="col-sm-2">
|
||||
<?php
|
||||
$form->field(\itguild\forms\inputs\Button::class, name: "btn-reset", params: [
|
||||
'class' => "btn btn-warning",
|
||||
'value' => 'Сбросить',
|
||||
'typeInput' => 'reset'
|
||||
])
|
||||
->render();
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
$form->endForm();
|
107
kernel/app_modules/event/views/index.php
Normal file
107
kernel/app_modules/event/views/index.php
Normal file
@ -0,0 +1,107 @@
|
||||
<?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();
|
50
kernel/app_modules/event/views/view.php
Normal file
50
kernel/app_modules/event/views/view.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Database\Eloquent\Collection $event
|
||||
*/
|
||||
|
||||
use Itguild\EloquentTable\ViewEloquentTable;
|
||||
use Itguild\EloquentTable\ViewJsonTableEloquentModel;
|
||||
use kernel\app_modules\event\models\Event;
|
||||
use kernel\widgets\IconBtn\IconBtnDeleteWidget;
|
||||
use kernel\widgets\IconBtn\IconBtnEditWidget;
|
||||
use kernel\widgets\IconBtn\IconBtnListWidget;
|
||||
|
||||
$table = new ViewEloquentTable(new ViewJsonTableEloquentModel($event, [
|
||||
'params' => ["class" => "table table-bordered", "border" => "2"],
|
||||
'baseUrl' => "/admin/event",
|
||||
]));
|
||||
|
||||
$entityRelation = new \kernel\EntityRelation();
|
||||
$additionals = $entityRelation->getEntityAdditionalProperty("event", $event);
|
||||
|
||||
foreach ($additionals as $key => $additional) {
|
||||
$table->addRow($key, function () use ($additional) {
|
||||
return $additional;
|
||||
}, ['after' => 'additional_info']);
|
||||
}
|
||||
|
||||
$table->rows([
|
||||
'date_start' => [
|
||||
'format' => 'date:d-m-Y',
|
||||
],
|
||||
'date_end' => [
|
||||
'format' => 'date:d-m-Y',
|
||||
],
|
||||
'status' => [
|
||||
'value' => function ($data) {
|
||||
return Event::getStatus()[$data];
|
||||
}
|
||||
]
|
||||
]);
|
||||
|
||||
$table->beforePrint(function () use ($event) {
|
||||
$btn = IconBtnListWidget::create(['url' => '/admin/event'])->run();
|
||||
$btn .= IconBtnEditWidget::create(['url' => '/admin/event/update/' . $event->id])->run();
|
||||
$btn .= IconBtnDeleteWidget::create(['url' => '/admin/event/delete/' . $event->id])->run();
|
||||
return $btn;
|
||||
});
|
||||
|
||||
$table->create();
|
||||
$table->render();
|
Reference in New Issue
Block a user