This commit is contained in:
2025-06-18 14:50:18 +03:00
parent a64ed080bb
commit 4c716a8a8c
160 changed files with 6786 additions and 23 deletions

View 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");
}
}

View File

@ -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/");
}
}

View 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/");
}
}

View File

@ -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');
}
};

View 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");
}
}

View 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 => "Телеграм",
];
}
}

View File

@ -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',
];
}
}

View 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',
];
}
}

View 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']);
});
});
});

View 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;
}
}

View 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();
}
}

View 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();

View 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();

View 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();

View 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();

View 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();

View 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();

View File

@ -0,0 +1,43 @@
<?php
namespace kernel\app_modules\gestalt_profile;
use kernel\helpers\Debug;
use kernel\Module;
use kernel\modules\menu\service\MenuService;
use kernel\services\MigrationService;
class Gestalt_profileModule extends Module
{
public MenuService $menuService;
public MigrationService $migrationService;
public function __construct()
{
$this->menuService = new MenuService();
$this->migrationService = new MigrationService();
}
/**
* @throws \Exception
*/
public function init(): void
{
$this->migrationService->runAtPath("{KERNEL_APP_MODULES}/gestalt_profile/migrations");
$this->menuService->createItem([
"label" => "Профили психологов",
"url" => "/admin/gestalt_profile",
"slug" => "gestalt_profile",
]);
}
/**
* @throws \Exception
*/
public function deactivate(): void
{
$this->migrationService->rollbackAtPath("{KERNEL_APP_MODULES}/gestalt_profile/migrations");
$this->menuService->removeItemBySlug("gestalt_profile");
}
}

View File

@ -0,0 +1,22 @@
<?php
namespace kernel\app_modules\gestalt_profile\controllers;
use kernel\app_modules\gestalt_profile\models\Gestalt_profile;
use kernel\modules\post\models\Post;
use kernel\RestController;
class GestaltProfileRestController extends RestController
{
public function __construct()
{
$this->model = new Gestalt_profile();
}
protected function expand(): array
{
return ["user"];
}
}

View File

@ -0,0 +1,100 @@
<?php
namespace kernel\app_modules\gestalt_profile\controllers;
use Exception;
use JetBrains\PhpStorm\NoReturn;
use kernel\AdminController;
use kernel\app_modules\gestalt_profile\models\forms\CreateGestalt_profileForm;
use kernel\app_modules\gestalt_profile\models\Gestalt_profile;
use kernel\app_modules\gestalt_profile\services\Gestalt_profileService;
use kernel\helpers\Debug;
class Gestalt_profileController extends AdminController
{
private Gestalt_profileService $gestalt_profileService;
protected function init(): void
{
parent::init();
$this->cgView->viewPath = KERNEL_APP_MODULES_DIR . "/gestalt_profile/views/";
$this->gestalt_profileService = new Gestalt_profileService();
}
public function actionCreate(): void
{
$this->cgView->render("form.php");
}
#[NoReturn] public function actionAdd(): void
{
$gestalt_profileForm = new CreateGestalt_profileForm();
$gestalt_profileForm->load($_REQUEST);
if ($gestalt_profileForm->validate()){
$gestalt_profile = $this->gestalt_profileService->create($gestalt_profileForm);
if ($gestalt_profile){
$this->redirect("/admin/gestalt_profile/view/" . $gestalt_profile->id);
}
}
$this->redirect("/admin/gestalt_profile/create");
}
public function actionIndex($page_number = 1): void
{
$this->cgView->render("index.php", ['page_number' => $page_number]);
}
/**
* @throws Exception
*/
public function actionView($id): void
{
$gestalt_profile = Gestalt_profile::find($id);
if (!$gestalt_profile){
throw new Exception(message: "The gestalt_profile not found");
}
$this->cgView->render("view.php", ['gestalt_profile' => $gestalt_profile]);
}
/**
* @throws Exception
*/
public function actionUpdate($id): void
{
$model = Gestalt_profile::find($id);
if (!$model){
throw new Exception(message: "The gestalt_profile not found");
}
$this->cgView->render("form.php", ['model' => $model]);
}
/**
* @throws Exception
*/
public function actionEdit($id): void
{
$gestalt_profile = Gestalt_profile::find($id);
if (!$gestalt_profile){
throw new Exception(message: "The gestalt_profile not found");
}
$gestalt_profileForm = new CreateGestalt_profileForm();
$gestalt_profileService = new Gestalt_profileService();
$gestalt_profileForm->load($gestalt_profile->toArray());
$gestalt_profileForm->load($_REQUEST);
if ($gestalt_profileForm->validate()) {
$gestalt_profile = $gestalt_profileService->update($gestalt_profileForm, $gestalt_profile);
if ($gestalt_profile) {
$this->redirect("/admin/gestalt_profile/view/" . $gestalt_profile->id);
}
}
$this->redirect("/admin/gestalt_profile/update/" . $id);
}
#[NoReturn] public function actionDelete($id): void
{
$gestalt_profile = Gestalt_profile::find($id)->first();
$gestalt_profile->delete();
$this->redirect("/admin/gestalt_profile/");
}
}

View File

@ -0,0 +1,41 @@
<?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('gestalt_profile', function (Blueprint $table) {
$table->id();
$table->integer('user_id')->nullable();
$table->string('fio', 255)->nullable(false);
$table->string('phone', 255)->nullable(false);
$table->string('email', 255)->nullable(false);
$table->string('city', 255);
$table->string('photo', 255);
$table->text('community_status')->nullable(true);
$table->text('specialization')->nullable(true);
$table->text('description_of_professional_activity')->nullable(true);
$table->text('past_events')->nullable(true);
$table->text('upcoming_events')->nullable(true);
$table->text('under_curation_events')->nullable(true);
$table->integer('status')->default(1);
$table->integer('show_on_main')->default(0);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
\kernel\App::$db->schema->dropIfExists('gestalt_profile');
}
};

View File

@ -0,0 +1,118 @@
<?php
namespace kernel\app_modules\gestalt_profile\models;
use Illuminate\Database\Eloquent\Model;
use kernel\app_modules\gestalt_profile_relationship\models\GestaltProfileRelationship;
// Добавить @property
/**
* @property int $id
* @property int $status
* @property int $show_on_main
* @property int $user_id
* @property string $fio
* @property string $phone
* @property string $email
* @property string $city
* @property string $photo
* @property string $community_status
* @property string $specialization
* @property string $description_of_professional_activity
* @property string $past_events
* @property string $upcoming_events
* @property string $under_curation_events
* @property array $communityStatusArr
* @property array $specializationArr
*/
class Gestalt_profile extends Model
{
const DISABLE_STATUS = 0;
const ACTIVE_STATUS = 1;
const DONT_SHOW_ON_MAIN = 0;
const SHOW_ON_MAIN = 1;
protected $table = 'gestalt_profile';
protected $fillable = [
'user_id',
'fio',
'phone',
'email',
'city',
'photo',
'community_status',
'specialization',
'description_of_professional_activity',
'past_events',
'upcoming_events',
'under_curation_events',
'status',
'show_on_main',
];
public static function labels(): array
{
return [
'user_id' => 'Пользователь',
'fio' => 'ФИО',
'phone' => 'Телефон',
'email' => 'Почта',
'city' => 'Город',
'photo' => 'Фото',
'community_status' => 'Статус в сообществе',
'specialization' => 'Специализация',
'description_of_professional_activity' => 'Описание профессиональной деятельности',
'past_events' => 'Прошедшие мероприятия',
'upcoming_events' => 'Будущие мероприятия',
'under_curation_events' => 'Под руководством специалиста',
'status' => 'Статус',
'show_on_main' => 'Показать на главной',
];
}
/**
* @return string[]
*/
public static function getStatus(): array
{
return [
self::DISABLE_STATUS => "Не активный",
self::ACTIVE_STATUS => "Активный",
];
}
/**
* @return string[]
*/
public static function getShowOnMain(): array
{
return [
self::DONT_SHOW_ON_MAIN => "Не показывать",
self::SHOW_ON_MAIN => "Показывать",
];
}
public function relationships(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->hasMany(GestaltProfileRelationship::class, 'gestalt_profile_id');
}
public function getCommunityStatusArrAttribute(): array
{
return array_filter(explode(", ", $this->community_status));
}
public function getSpecializationArrAttribute(): array
{
return array_filter(explode(", ", $this->specialization));
}
public static function getCountProfiles()
{
return self::count();
}
}

View File

@ -0,0 +1,38 @@
<?php
namespace kernel\app_modules\gestalt_profile\models\forms;
use kernel\FormModel;
class CreateGestalt_profileForm extends FormModel
{
public function rules(): array
{
// Заполнить массив правил
// Пример:
// return [
// 'label' => 'required|min-str-len:5|max-str-len:30',
// 'entity' => 'required',
// 'slug' => '',
// 'status' => ''
// ];
return [
'user_id' => 'integer',
'fio' => 'required|min-str-len:5|max-str-len:80',
'phone' => 'required|min-str-len:5|max-str-len:30',
'email' => 'required|min-str-len:5|max-str-len:30',
'city' => 'required|min-str-len:3|max-str-len:30',
'photo' => '',
'community_status' => '',
'specialization' => '',
'description_of_professional_activity' => '',
'past_events' => '',
'upcoming_events' => '',
'under_curation_events' => '',
'status' => 'integer',
'show_on_main' => 'integer',
];
}
}

View File

@ -0,0 +1,25 @@
<?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" => "gestalt_profile"], function (CGRouteCollector $router) {
App::$collector->get('/', [\app\modules\gestalt_profile\controllers\Gestalt_profileController::class, 'actionIndex']);
App::$collector->get('/page/{page_number}', [\app\modules\gestalt_profile\controllers\Gestalt_profileController::class, 'actionIndex']);
App::$collector->get('/create', [\app\modules\gestalt_profile\controllers\Gestalt_profileController::class, 'actionCreate']);
App::$collector->post("/", [\app\modules\gestalt_profile\controllers\Gestalt_profileController::class, 'actionAdd']);
App::$collector->get('/view/{id}', [\app\modules\gestalt_profile\controllers\Gestalt_profileController::class, 'actionView']);
App::$collector->any('/update/{id}', [\app\modules\gestalt_profile\controllers\Gestalt_profileController::class, 'actionUpdate']);
App::$collector->any("/edit/{id}", [\app\modules\gestalt_profile\controllers\Gestalt_profileController::class, 'actionEdit']);
App::$collector->get('/delete/{id}', [\app\modules\gestalt_profile\controllers\Gestalt_profileController::class, 'actionDelete']);
});
});
});
App::$collector->group(["prefix" => "api"], function (CgRouteCollector $router){
App::$collector->group(['before' => 'bearer'], function (CgRouteCollector $router){
$router->rest("gestalt_profile", [\kernel\app_modules\gestalt_profile\controllers\GestaltProfileRestController::class]);
});
});

View File

@ -0,0 +1,77 @@
<?php
namespace kernel\app_modules\gestalt_profile\services;
use kernel\helpers\Debug;
use kernel\app_modules\gestalt_profile\models\Gestalt_profile;
use kernel\FormModel;
class Gestalt_profileService
{
protected Gestalt_profile $model;
public function __construct()
{
$this->model = new Gestalt_profile();
}
public function create(FormModel $form_model): false|Gestalt_profile
{
$model = new Gestalt_profile();
// Пример заполнения:
$model->user_id = $form_model->getItem('user_id');
$model->fio = $form_model->getItem('fio');
$model->phone = $form_model->getItem('phone');
$model->email = $form_model->getItem('email');
$model->city = $form_model->getItem('city');
$model->photo = $form_model->getItem('photo');
$model->community_status = $form_model->getItem('community_status');
$model->specialization = $form_model->getItem('specialization');
$model->description_of_professional_activity = $form_model->getItem('description_of_professional_activity');
$model->past_events = $form_model->getItem('past_events');
$model->upcoming_events = $form_model->getItem('upcoming_events');
$model->under_curation_events = $form_model->getItem('under_curation_events');
$model->status = $form_model->getItem('status');
$model->show_on_main = $form_model->getItem('show_on_main');
if ($model->save()){
return $model;
}
return false;
}
public function update(FormModel $form_model, Gestalt_profile $gestalt_profile): false|Gestalt_profile
{
// Пример обновления:
$gestalt_profile->user_id = $form_model->getItem('user_id');
$gestalt_profile->fio = $form_model->getItem('fio');
$gestalt_profile->phone = $form_model->getItem('phone');
$gestalt_profile->email = $form_model->getItem('email');
$gestalt_profile->city = $form_model->getItem('city');
$gestalt_profile->photo = $form_model->getItem('photo');
$gestalt_profile->community_status = $form_model->getItem('community_status');
$gestalt_profile->specialization = $form_model->getItem('specialization');
$gestalt_profile->description_of_professional_activity = $form_model->getItem('description_of_professional_activity');
$gestalt_profile->past_events = $form_model->getItem('past_events');
$gestalt_profile->upcoming_events = $form_model->getItem('upcoming_events');
$gestalt_profile->under_curation_events = $form_model->getItem('under_curation_events');
$gestalt_profile->status = $form_model->getItem('status');
$gestalt_profile->show_on_main = $form_model->getItem('show_on_main');
if ($gestalt_profile->save()){
return $gestalt_profile;
}
return false;
}
public static function getCount()
{
return Gestalt_profile::count();
}
public static function getLast4(): array
{
return Gestalt_profile::query()->limit(4)->orderBy('id', 'desc')->get()->toArray();
}
}

View File

@ -0,0 +1,55 @@
<?php
/**
* @var Gestalt_profile $model
*/
use kernel\app_modules\gestalt_profile\models\Gestalt_profile;
$form = new \itguild\forms\ActiveForm();
$form->beginForm(isset($model) ? "/admin/gestalt_profile/edit/" . $model->id : "/admin/gestalt_profile", '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: "show_on_main", params: [
'class' => "form-control",
'value' => $model->show_on_main ?? ''
])
->setLabel("Показать на главной")
->setOptions(Gestalt_profile::getShowOnMain())
->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();

View File

@ -0,0 +1,90 @@
<?php
/**
* @var \Illuminate\Database\Eloquent\Collection $gestalt_profile
* @var int $page_number
* @var \kernel\CgView $view
*/
use kernel\app_modules\gestalt_profile\models\Gestalt_profile;
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;
$get = (new \kernel\Request())->get();
$view->setTitle("Список gestalt_profile");
$view->setMeta([
'description' => 'Список gestalt_profile системы'
]);
//Для использования таблицы с моделью, необходимо создать таблицу в базе данных
$table = new ListEloquentTable(new EloquentDataProvider(Gestalt_profile::class, [
'currentPage' => $page_number,
'perPage' => 8,
'params' => ["class" => "table table-bordered", "border" => "2"],
'baseUrl' => "/admin/gestalt_profile",
'searchPrefix' => "",
'searchParams' => $get,
'fillable' => ['fio', 'photo', 'phone', 'email', 'city']
]));
//$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'] ?? ''
// ]
// ],
//]);
$table->columns([
"photo" => [
"value" => function ($cell) {
return \kernel\helpers\Html::img($cell, ['width' => '200px']);
}]
]);
$table->beforePrint(function () {
return IconBtnCreateWidget::create(['url' => '/admin/gestalt_profile/create'])->run();
});
$table->addAction(function ($row) {
return IconBtnViewWidget::create(['url' => '/admin/gestalt_profile/view/' . $row['id']])->run();
});
$table->addAction(function ($row) {
return IconBtnEditWidget::create(['url' => '/admin/gestalt_profile/update/' . $row['id']])->run();
});
$table->addAction(function ($row) {
return IconBtnDeleteWidget::create(['url' => '/admin/gestalt_profile/delete/' . $row['id']])->run();
});
$table->create();
$table->render();

View File

@ -0,0 +1,32 @@
<?php
/**
* @var \Illuminate\Database\Eloquent\Collection $gestalt_profile
*/
use Itguild\EloquentTable\ViewEloquentTable;
use Itguild\EloquentTable\ViewJsonTableEloquentModel;
use kernel\widgets\IconBtn\IconBtnDeleteWidget;
use kernel\widgets\IconBtn\IconBtnEditWidget;
use kernel\widgets\IconBtn\IconBtnListWidget;
$table = new ViewEloquentTable(new ViewJsonTableEloquentModel($gestalt_profile, [
'params' => ["class" => "table table-bordered", "border" => "2"],
'baseUrl' => "/admin/gestalt_profile",
]));
$table->beforePrint(function () use ($gestalt_profile) {
$btn = IconBtnListWidget::create(['url' => '/admin/gestalt_profile'])->run();
$btn .= IconBtnEditWidget::create(['url' => '/admin/gestalt_profile/update/' . $gestalt_profile->id])->run();
$btn .= IconBtnDeleteWidget::create(['url' => '/admin/gestalt_profile/delete/' . $gestalt_profile->id])->run();
return $btn;
});
$table->rows([
'photo' => function ($data) {
return \kernel\helpers\Html::img($data, ['width' => '200px']);
},
]);
$table->create();
$table->render();

View File

@ -0,0 +1,113 @@
<?php
namespace kernel\app_modules\gestalt_profile_relationship;
use Illuminate\Database\Eloquent\Model;
use itguild\forms\builders\SelectBuilder;
use kernel\app_modules\gestalt_profile_relationship\models\GestaltProfileRelationship;
use kernel\app_modules\gestalt_profile_relationship\services\GestaltProfileRelationshipService;
use kernel\app_modules\tag\models\Tag;
use kernel\app_modules\tag\service\TagEntityService;
use kernel\helpers\Debug;
use kernel\Module;
use kernel\modules\menu\service\MenuService;
use kernel\modules\option\service\OptionService;
use kernel\Request;
use kernel\services\MigrationService;
class Gestalt_profile_relationshipModule extends Module
{
public MenuService $menuService;
public MigrationService $migrationService;
public function __construct()
{
$this->menuService = new MenuService();
$this->migrationService = new MigrationService();
}
/**
* @throws \Exception
*/
public function init(): void
{
$this->migrationService->runAtPath("{KERNEL_APP_MODULES}/gestalt_profile_relationship/migrations");
$this->menuService->createItem([
"label" => "Профили психологов (связь)",
"url" => "/admin/gestalt_profile_relationship",
"slug" => "gestalt_profile_relationship",
]);
$this->menuService->createItem([
"label" => "Профили психологов",
"url" => "/admin/settings/gestalt_profile_relationship",
"slug" => "gestalt_profile_relationship_settings",
"parent_slug" => "settings"
]);
OptionService::createFromParams("entity_gestalt_profile_relationship_list", "{}", "Список тегов");
}
/**
* @throws \Exception
*/
public function deactivate(): void
{
$this->menuService->removeItemBySlug("gestalt_profile_relationship");
$this->menuService->removeItemBySlug("gestalt_profile_relationship_settings");
$this->migrationService->rollbackAtPath("{KERNEL_APP_MODULES}/gestalt_profile_relationship/migrations");
OptionService::removeOptionByKey("entity_gestalt_profile_relationship_list");
}
public function formInputs(string $entity, Model $model = null): void
{
if (isset($model->id)) {
$value = GestaltProfileRelationshipService::getProfileByEntity($entity, $model->id);
}
$input = SelectBuilder::build("gestalt_profiles[]", [
'class' => 'form-control',
'placeholder' => 'Психологи',
'value' => $value ?? '',
'multiple' => "multiple",
'options' => GestaltProfileRelationshipService::getProfilesList()
]);
$input->setLabel("Психологи");
$input->create()->render();
}
public function saveInputs(string $entity, Model $model, Request $request): void
{
GestaltProfileRelationship::where("entity", $entity)->where("entity_id", $model->id)->delete();
$profiles = $request->post("gestalt_profiles");
if (is_array($profiles)) {
foreach ($profiles as $profile) {
$gpr = new GestaltProfileRelationship();
$gpr->entity = $entity;
$gpr->entity_id = $model->id;
$gpr->gestalt_profile_id = $profile;
$gpr->save();
}
}
}
public function getItems(string $entity, Model $model): array|string
{
$profiles = GestaltProfileRelationship::where("entity", $entity)->where("entity_id", $model->id)->with("profile")->get();
return $profiles->pluck('profile.fio')->filter()->implode(', ');
}
public function getItem(string $entity, string $entity_id): string
{
$profiles = GestaltProfileRelationship::where("entity", $entity)->where("entity_id", $entity_id)->with("profile")->get();
return $profiles->pluck('profile.fio')->filter()->implode(', ');
}
public function getItemsObject(string $entity, string $entity_id)
{
return GestaltProfileRelationship::where("entity", $entity)->where("entity_id", $entity_id)->with("profile")->get();
}
}

View File

@ -0,0 +1,116 @@
<?php
namespace kernel\app_modules\gestalt_profile_relationship\controllers;
use Exception;
use JetBrains\PhpStorm\NoReturn;
use kernel\AdminController;
use kernel\app_modules\gestalt_profile_relationship\models\forms\CreateGestaltProfileRelationshipForm;
use kernel\app_modules\gestalt_profile_relationship\models\GestaltProfileRelationship;
use kernel\app_modules\gestalt_profile_relationship\services\GestaltProfileRelationshipService;
use kernel\EntityRelation;
use kernel\Flash;
use kernel\Request;
class GestaltProfileRelationshipController extends AdminController
{
private GestaltProfileRelationshipService $gestalt_profile_relationshipService;
protected function init(): void
{
parent::init();
$this->cgView->viewPath = KERNEL_APP_MODULES_DIR . "/gestalt_profile_relationship/views/";
$this->gestalt_profile_relationshipService = new GestaltProfileRelationshipService();
}
public function actionCreate(): void
{
$this->cgView->render("form.php");
}
#[NoReturn] public function actionAdd(): void
{
$gestalt_profile_relationshipForm = new CreateGestaltProfileRelationshipForm();
$gestalt_profile_relationshipForm->load($_REQUEST);
if ($gestalt_profile_relationshipForm->validate()){
$gestalt_profile_relationship = $this->gestalt_profile_relationshipService->create($gestalt_profile_relationshipForm);
if ($gestalt_profile_relationship){
$this->redirect("/admin/gestalt_profile_relationship/view/" . $gestalt_profile_relationship->id);
}
}
$this->redirect("/admin/gestalt_profile_relationship/create");
}
public function actionIndex($page_number = 1): void
{
$this->cgView->render("index.php", ['page_number' => $page_number]);
}
/**
* @throws Exception
*/
public function actionView($id): void
{
$gestalt_profile_relationship = GestaltProfileRelationship::find($id);
if (!$gestalt_profile_relationship){
throw new Exception(message: "The gestalt_profile_relationship not found");
}
$this->cgView->render("view.php", ['gestalt_profile_relationship' => $gestalt_profile_relationship]);
}
/**
* @throws Exception
*/
public function actionUpdate($id): void
{
$model = GestaltProfileRelationship::find($id);
if (!$model){
throw new Exception(message: "The gestalt_profile_relationship not found");
}
$this->cgView->render("form.php", ['model' => $model]);
}
/**
* @throws Exception
*/
public function actionEdit($id): void
{
$gestalt_profile_relationship = GestaltProfileRelationship::find($id);
if (!$gestalt_profile_relationship){
throw new Exception(message: "The gestalt_profile_relationship not found");
}
$gestalt_profile_relationshipForm = new CreateGestaltProfileRelationshipForm();
$gestalt_profile_relationshipService = new GestaltProfileRelationshipService();
$gestalt_profile_relationshipForm->load($_REQUEST);
if ($gestalt_profile_relationshipForm->validate()) {
$gestalt_profile_relationship = $gestalt_profile_relationshipService->update($gestalt_profile_relationshipForm, $gestalt_profile_relationship);
if ($gestalt_profile_relationship) {
$this->redirect("/admin/gestalt_profile_relationship/view/" . $gestalt_profile_relationship->id);
}
}
$this->redirect("/admin/gestalt_profile_relationship/update/" . $id);
}
#[NoReturn] public function actionDelete($id): void
{
$gestalt_profile_relationship = GestaltProfileRelationship::find($id)->first();
$gestalt_profile_relationship->delete();
$this->redirect("/admin/gestalt_profile_relationship/");
}
public function actionSettings(): void
{
$this->cgView->render('settingsForm.php');
}
#[NoReturn] public function actionSaveSettings(): void
{
$request = new Request();
$entities = $request->post('entity');
EntityRelation::configurationEntitiesByProperty($entities, 'gestalt_profile_relationship');
Flash::setMessage("success", "Настройка прошла успешно");
$this->redirect("/admin/settings/gestalt_profile_relationship", 302);
}
}

View File

@ -0,0 +1,30 @@
<?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('gestalt_profile_relationship', function (Blueprint $table) {
$table->id();
$table->integer('gestalt_profile_id')->nullable(false);
$table->string('entity', 255)->nullable(false);
$table->integer('entity_id')->nullable(false);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
\kernel\App::$db->schema->dropIfExists('gestalt_profile_relationship');
}
};

View File

@ -0,0 +1,57 @@
<?php
namespace kernel\app_modules\gestalt_profile_relationship\models;
use Illuminate\Database\Eloquent\Model;
use kernel\app_modules\gestalt_profile\models\Gestalt_profile;
// Добавить @property
/**
* @property int $id
* @property int $gestalt_profile_id
* @property int $entity_id
* @property string $entity
*/
class GestaltProfileRelationship extends Model
{
const DISABLE_STATUS = 0;
const ACTIVE_STATUS = 1;
protected $table = 'gestalt_profile_relationship';
protected $fillable = ['gestalt_profile_id', 'entity', 'entity_id'];
public static function labels(): array
{
// Заполнить массив
// Пример: [
// 'label' => 'Заголовок',
// 'entity' => 'Сущность',
// 'slug' => 'Slug',
// 'status' => 'Статус',
// ]
return [
'gestalt_profile_id' => 'Профиль',
'entity' => 'Сущность',
'entity_id' => 'ID сущности',
];
}
/**
* @return string[]
*/
public static function getStatus(): array
{
return [
self::DISABLE_STATUS => "Не активный",
self::ACTIVE_STATUS => "Активный",
];
}
public function profile(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(Gestalt_profile::class, 'gestalt_profile_id');
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace kernel\app_modules\gestalt_profile_relationship\models\forms;
use kernel\FormModel;
class CreateGestaltProfileRelationshipForm extends FormModel
{
public function rules(): array
{
// Заполнить массив правил
// Пример:
// return [
// 'label' => 'required|min-str-len:5|max-str-len:30',
// 'entity' => 'required',
// 'slug' => '',
// 'status' => ''
// ];
return [
'gestalt_profile_id' => 'required|integer',
'entity' => 'required|min-str-len:5|max-str-len:30',
'entity_id' => 'required|integer',
];
}
}

View File

@ -0,0 +1,24 @@
<?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" => "gestalt_profile_relationship"], function (CGRouteCollector $router) {
App::$collector->get('/', [\app\modules\gestalt_profile_relationship\controllers\GestaltProfileRelationshipController::class, 'actionIndex']);
App::$collector->get('/page/{page_number}', [\app\modules\gestalt_profile_relationship\controllers\GestaltProfileRelationshipController::class, 'actionIndex']);
App::$collector->get('/create', [\app\modules\gestalt_profile_relationship\controllers\GestaltProfileRelationshipController::class, 'actionCreate']);
App::$collector->post("/", [\app\modules\gestalt_profile_relationship\controllers\GestaltProfileRelationshipController::class, 'actionAdd']);
App::$collector->get('/view/{id}', [\app\modules\gestalt_profile_relationship\controllers\GestaltProfileRelationshipController::class, 'actionView']);
App::$collector->any('/update/{id}', [\app\modules\gestalt_profile_relationship\controllers\GestaltProfileRelationshipController::class, 'actionUpdate']);
App::$collector->any("/edit/{id}", [\app\modules\gestalt_profile_relationship\controllers\GestaltProfileRelationshipController::class, 'actionEdit']);
App::$collector->get('/delete/{id}', [\app\modules\gestalt_profile_relationship\controllers\GestaltProfileRelationshipController::class, 'actionDelete']);
});
App::$collector->group(["prefix" => "settings"], function (CGRouteCollector $router) {
App::$collector->get('/gestalt_profile_relationship', [\kernel\app_modules\gestalt_profile_relationship\controllers\GestaltProfileRelationshipController::class, 'actionSettings']);
App::$collector->post('/gestalt_profile_relationship/update', [\kernel\app_modules\gestalt_profile_relationship\controllers\GestaltProfileRelationshipController::class, 'actionSaveSettings']);
});
});
});

View File

@ -0,0 +1,54 @@
<?php
namespace kernel\app_modules\gestalt_profile_relationship\services;
use kernel\app_modules\gestalt_profile\models\Gestalt_profile;
use kernel\helpers\Debug;
use kernel\app_modules\gestalt_profile_relationship\models\GestaltProfileRelationship;
use kernel\FormModel;
class GestaltProfileRelationshipService
{
public function create(FormModel $form_model): false|GestaltProfileRelationship
{
$model = new GestaltProfileRelationship();
$model->gestalt_profile_id = $form_model->getItem('gestalt_profile_id');
$model->entity = $form_model->getItem('entity');
$model->entity_id = $form_model->getItem('entity_id');
if ($model->save()){
return $model;
}
return false;
}
public function update(FormModel $form_model, GestaltProfileRelationship $gestalt_profile_relationship): false|GestaltProfileRelationship
{
$gestalt_profile_relationship->gestalt_profile_id = $form_model->getItem('gestalt_profile_id');
$gestalt_profile_relationship->entity = $form_model->getItem('entity');
$gestalt_profile_relationship->entity_id = $form_model->getItem('entity_id');
if ($gestalt_profile_relationship->save()){
return $gestalt_profile_relationship;
}
return false;
}
public static function getProfileByEntity(string $entity, int $entity_id): array
{
$profiles = GestaltProfileRelationship::with('profile')->where("entity_id", $entity_id)->where("entity", $entity)->get();
$value = [];
foreach ($profiles as $profile) {
$value[$profile->gestalt_profile_id] = $profile->profile->fio;
}
return $value;
}
public static function getProfilesList(): array
{
return Gestalt_profile::pluck('fio', 'id')->all();
}
}

View File

@ -0,0 +1,55 @@
<?php
/**
* @var GestaltProfileRelationship $model
*/
use kernel\app_modules\gestalt_profile_relationship\models\GestaltProfileRelationship;
$form = new \itguild\forms\ActiveForm();
$form->beginForm(isset($model) ? "/admin/gestalt_profile_relationship/edit/" . $model->id : "/admin/gestalt_profile_relationship", '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: "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();

View File

@ -0,0 +1,77 @@
<?php
/**
* @var \Illuminate\Database\Eloquent\Collection $gestalt_profile_relationship
* @var int $page_number
* @var \kernel\CgView $view
*/
use kernel\app_modules\gestalt_profile_relationship\models\GestaltProfileRelationship;
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("Список gestalt_profile_relationship");
$view->setMeta([
'description' => 'Список gestalt_profile_relationship системы'
]);
//Для использования таблицы с моделью, необходимо создать таблицу в базе данных
$table = new ListEloquentTable(new EloquentDataProvider(GestaltProfileRelationship::class, [
'currentPage' => $page_number,
'perPage' => 8,
'params' => ["class" => "table table-bordered", "border" => "2"],
'baseUrl' => "/admin/gestalt_profile_relationship"
]));
//$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([
'gestalt_profile_id' => [
'value' => function ($data) {
return \kernel\app_modules\gestalt_profile\models\Gestalt_profile::find($data)->fio ?? '';
}
],
]);
//$table->beforePrint(function () {
// return IconBtnCreateWidget::create(['url' => '/admin/gestalt_profile_relationship/create'])->run();
//});
$table->addAction(function($row) {
return IconBtnViewWidget::create(['url' => '/admin/gestalt_profile_relationship/view/' . $row['id']])->run();
});
//$table->addAction(function($row) {
// return IconBtnEditWidget::create(['url' => '/admin/gestalt_profile_relationship/update/' . $row['id']])->run();
//});
$table->addAction(function($row) {
return IconBtnDeleteWidget::create(['url' => '/admin/gestalt_profile_relationship/delete/' . $row['id']])->run();
});
$table->create();
$table->render();

View File

@ -0,0 +1,49 @@
<?php
$form = new \itguild\forms\ActiveForm();
$form->beginForm("/admin/settings/gestalt_profile_relationship/update");
?>
<div class="row">
<h5>Выберите сущности, к которым хотите прикрепить фото</h5>
</div>
<?php
$form->field(\itguild\forms\inputs\Select::class, "entity[]", [
'class' => "form-control",
'value' => \kernel\EntityRelation::getEntityByProperty('gestalt_profile_relationship') ?? '',
'multiple' => "multiple",
])
->setLabel("Сущности")
->setOptions(\kernel\EntityRelation::getEntityList())
->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();

View File

@ -0,0 +1,33 @@
<?php
/**
* @var \Illuminate\Database\Eloquent\Collection $gestalt_profile_relationship
*/
use Itguild\EloquentTable\ViewEloquentTable;
use Itguild\EloquentTable\ViewJsonTableEloquentModel;
use kernel\widgets\IconBtn\IconBtnDeleteWidget;
use kernel\widgets\IconBtn\IconBtnEditWidget;
use kernel\widgets\IconBtn\IconBtnListWidget;
$table = new ViewEloquentTable(new ViewJsonTableEloquentModel($gestalt_profile_relationship, [
'params' => ["class" => "table table-bordered", "border" => "2"],
'baseUrl' => "/admin/gestalt_profile_relationship",
]));
$table->beforePrint(function () use ($gestalt_profile_relationship) {
$btn = IconBtnListWidget::create(['url' => '/admin/gestalt_profile_relationship'])->run();
// $btn .= IconBtnEditWidget::create(['url' => '/admin/gestalt_profile_relationship/update/' . $gestalt_profile_relationship->id])->run();
$btn .= IconBtnDeleteWidget::create(['url' => '/admin/gestalt_profile_relationship/delete/' . $gestalt_profile_relationship->id])->run();
return $btn;
});
$table->rows([
'gestalt_profile_id' => [
'value' => function ($data) {
return \kernel\app_modules\gestalt_profile\models\Gestalt_profile::find($data)->fio ?? '';
}
],
]);
$table->create();
$table->render();

View File

@ -94,12 +94,22 @@ class PhotoModule extends Module
return substr($photoStr, 0, -1);
}
public function getItem(string $entity, string $entity_id): string
public function getItem(string $entity, string $entity_id, array $params = []): string
{
$photos = Photo::where("entity", $entity)->where("entity_id", $entity_id)->get();
$photoStr = "";
if (isset($params['width'])){
$w = $params['width'];
$style = "width: $w;";
}
elseif(isset($params['cover'])) {
$style = "width: 100%; height: 100%; object-fit: cover;";
}
else {
$style = "width: 150px;";
}
foreach ($photos as $photo) {
$photoStr .= "<img src='$photo->image' width='150px'>" . " ";
$photoStr .= "<img src='$photo->image' style='$style'>" . " ";
}
return substr($photoStr, 0, -1);