first
This commit is contained in:
482
kernel/EloquentDataProvider.php
Normal file
482
kernel/EloquentDataProvider.php
Normal file
@ -0,0 +1,482 @@
|
||||
<?php
|
||||
|
||||
namespace kernel;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class EloquentDataProvider
|
||||
{
|
||||
protected Builder $query;
|
||||
protected int $perPage = 15;
|
||||
protected array $filters = [];
|
||||
protected array $sort = [];
|
||||
protected array $with = [];
|
||||
protected array $withCount = [];
|
||||
protected array $search = [];
|
||||
protected array $allowedFilters = [];
|
||||
protected array $allowedSorts = [];
|
||||
protected array $allowedSearch = [];
|
||||
protected array $defaultSort = [];
|
||||
protected array $beforeQueryCallbacks = [];
|
||||
protected array $afterQueryCallbacks = [];
|
||||
|
||||
protected array $paginationTemplates = [];
|
||||
|
||||
public function __construct(Builder $query)
|
||||
{
|
||||
$this->query = $query;
|
||||
}
|
||||
|
||||
public function setPerPage(int $perPage): self
|
||||
{
|
||||
$this->perPage = max(1, $perPage);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setFilters(array $filters): self
|
||||
{
|
||||
$this->filters = $filters;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setSort(array $sort): self
|
||||
{
|
||||
$this->sort = $sort;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function with(array $relations): self
|
||||
{
|
||||
$this->with = $relations;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withCount(array $relations): self
|
||||
{
|
||||
$this->withCount = $relations;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setSearch(array $search): self
|
||||
{
|
||||
$this->search = $search;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function allowFilters(array $filters): self
|
||||
{
|
||||
$this->allowedFilters = $filters;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function allowSorts(array $sorts): self
|
||||
{
|
||||
$this->allowedSorts = $sorts;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function allowSearch(array $fields): self
|
||||
{
|
||||
$this->allowedSearch = $fields;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setDefaultSort(array $sort): self
|
||||
{
|
||||
$this->defaultSort = $sort;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function beforeQuery(callable $callback): self
|
||||
{
|
||||
$this->beforeQueryCallbacks[] = $callback;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function afterQuery(callable $callback): self
|
||||
{
|
||||
$this->afterQueryCallbacks[] = $callback;
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function applyFilters(): void
|
||||
{
|
||||
foreach ($this->filters as $field => $value) {
|
||||
if (!$this->isFilterAllowed($field)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_array($value)) {
|
||||
$this->applyArrayFilter($field, $value);
|
||||
} elseif (Str::contains($field, '.')) {
|
||||
$this->applyRelationFilter($field, $value);
|
||||
} elseif ($value !== null && $value !== '') {
|
||||
$this->query->where($field, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function applyArrayFilter(string $field, array $value): void
|
||||
{
|
||||
$operator = strtolower($value[0] ?? null);
|
||||
$operand = $value[1] ?? null;
|
||||
|
||||
switch ($operator) {
|
||||
case 'in':
|
||||
$this->query->whereIn($field, (array)$operand);
|
||||
break;
|
||||
case 'not in':
|
||||
$this->query->whereNotIn($field, (array)$operand);
|
||||
break;
|
||||
case 'between':
|
||||
$this->query->whereBetween($field, (array)$operand);
|
||||
break;
|
||||
case 'not between':
|
||||
$this->query->whereNotBetween($field, (array)$operand);
|
||||
break;
|
||||
case 'null':
|
||||
$this->query->whereNull($field);
|
||||
break;
|
||||
case 'not null':
|
||||
$this->query->whereNotNull($field);
|
||||
break;
|
||||
case 'like':
|
||||
$this->query->where($field, 'like', "%{$operand}%");
|
||||
break;
|
||||
case '>':
|
||||
case '<':
|
||||
case '>=':
|
||||
case '<=':
|
||||
case '!=':
|
||||
$this->query->where($field, $operator, $operand);
|
||||
break;
|
||||
default:
|
||||
$this->query->whereIn($field, $value);
|
||||
}
|
||||
}
|
||||
|
||||
protected function applyRelationFilter(string $field, $value): void
|
||||
{
|
||||
[$relation, $column] = explode('.', $field, 2);
|
||||
|
||||
$this->query->whereHas($relation, function ($query) use ($column, $value) {
|
||||
if (is_array($value)) {
|
||||
$query->whereIn($column, $value);
|
||||
} else {
|
||||
$query->where($column, $value);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected function applySort(): void
|
||||
{
|
||||
if (empty($this->sort) && !empty($this->defaultSort)) {
|
||||
$this->sort = $this->defaultSort;
|
||||
}
|
||||
|
||||
foreach ($this->sort as $field => $direction) {
|
||||
if (!$this->isSortAllowed($field)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$direction = strtolower($direction) === 'desc' ? 'desc' : 'asc';
|
||||
|
||||
if (Str::contains($field, '.')) {
|
||||
$this->applyRelationSort($field, $direction);
|
||||
} else {
|
||||
$this->query->orderBy($field, $direction);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function applyRelationSort(string $field, string $direction): void
|
||||
{
|
||||
[$relation, $column] = explode('.', $field, 2);
|
||||
|
||||
$this->query->with([$relation => function ($query) use ($column, $direction) {
|
||||
$query->orderBy($column, $direction);
|
||||
}]);
|
||||
}
|
||||
|
||||
protected function applySearch(): void
|
||||
{
|
||||
if (empty($this->search) || empty($this->allowedSearch)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$searchTerm = Arr::get($this->search, 'term', '');
|
||||
if (empty($searchTerm)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->query->where(function ($query) use ($searchTerm) {
|
||||
foreach ($this->allowedSearch as $field) {
|
||||
if (Str::contains($field, '.')) {
|
||||
[$relation, $column] = explode('.', $field, 2);
|
||||
$query->orWhereHas($relation, function ($q) use ($column, $searchTerm) {
|
||||
$q->where($column, 'like', "%{$searchTerm}%");
|
||||
});
|
||||
} else {
|
||||
$query->orWhere($field, 'like', "%{$searchTerm}%");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected function applyRelations(): void
|
||||
{
|
||||
if (!empty($this->with)) {
|
||||
$this->query->with($this->with);
|
||||
}
|
||||
|
||||
if (!empty($this->withCount)) {
|
||||
$this->query->withCount($this->withCount);
|
||||
}
|
||||
}
|
||||
|
||||
protected function isFilterAllowed(string $field): bool
|
||||
{
|
||||
if (empty($this->allowedFilters)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$baseField = Str::before($field, '.');
|
||||
|
||||
return in_array($field, $this->allowedFilters) ||
|
||||
in_array($baseField, $this->allowedFilters);
|
||||
}
|
||||
|
||||
protected function isSortAllowed(string $field): bool
|
||||
{
|
||||
if (empty($this->allowedSorts)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$baseField = Str::before($field, '.');
|
||||
|
||||
return in_array($field, $this->allowedSorts) ||
|
||||
in_array($baseField, $this->allowedSorts);
|
||||
}
|
||||
|
||||
protected function executeCallbacks(array $callbacks): void
|
||||
{
|
||||
foreach ($callbacks as $callback) {
|
||||
call_user_func($callback, $this->query);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Получение данных с ручной пагинацией
|
||||
*/
|
||||
public function getManualPaginated(int $page = 1, int $perPage = null): array
|
||||
{
|
||||
$perPage = $perPage ?? $this->perPage;
|
||||
|
||||
$this->applyRelations();
|
||||
$this->applyFilters();
|
||||
$this->applySearch();
|
||||
$this->applySort();
|
||||
|
||||
$total = $this->query->count();
|
||||
$results = $this->query
|
||||
->offset(($page - 1) * $perPage)
|
||||
->limit($perPage)
|
||||
->get();
|
||||
|
||||
return [
|
||||
'data' => $results,
|
||||
'meta' => [
|
||||
'total' => $total,
|
||||
'per_page' => $perPage,
|
||||
'current_page' => $page,
|
||||
'last_page' => ceil($total / $perPage),
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function getAll(): \Illuminate\Database\Eloquent\Collection
|
||||
{
|
||||
$this->executeCallbacks($this->beforeQueryCallbacks);
|
||||
|
||||
$this->applyRelations();
|
||||
$this->applyFilters();
|
||||
$this->applySearch();
|
||||
$this->applySort();
|
||||
|
||||
$result = $this->query->get();
|
||||
|
||||
$this->executeCallbacks($this->afterQueryCallbacks);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getFirst(): ?\Illuminate\Database\Eloquent\Model
|
||||
{
|
||||
$this->executeCallbacks($this->beforeQueryCallbacks);
|
||||
|
||||
$this->applyRelations();
|
||||
$this->applyFilters();
|
||||
$this->applySearch();
|
||||
$this->applySort();
|
||||
|
||||
$result = $this->query->first();
|
||||
|
||||
$this->executeCallbacks($this->afterQueryCallbacks);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Генерирует массив с основными ссылками пагинации
|
||||
*
|
||||
* @param array $meta Мета-информация из getManualPaginated()
|
||||
* @param string|null $baseUrl Базовый URL (если null - определит автоматически)
|
||||
* @return array
|
||||
*/
|
||||
public function getPaginationLinks(array $meta, ?string $baseUrl = null): array
|
||||
{
|
||||
$currentPage = $meta['current_page'];
|
||||
$lastPage = $meta['last_page'];
|
||||
|
||||
// Определяем базовый URL
|
||||
$baseUrl = $this->normalizeBaseUrl($baseUrl);
|
||||
|
||||
$links = [
|
||||
'first' => null,
|
||||
'previous' => null,
|
||||
'current' => $this->buildPageUrl($baseUrl, $currentPage),
|
||||
'next' => null,
|
||||
'last' => null,
|
||||
];
|
||||
|
||||
// Первая страница (если не на первой)
|
||||
if ($currentPage > 1) {
|
||||
$links['first'] = $this->buildPageUrl($baseUrl, 1);
|
||||
}
|
||||
|
||||
// Предыдущая страница
|
||||
if ($currentPage > 1) {
|
||||
$links['previous'] = $this->buildPageUrl($baseUrl, $currentPage - 1);
|
||||
}
|
||||
|
||||
// Следующая страница
|
||||
if ($currentPage < $lastPage) {
|
||||
$links['next'] = $this->buildPageUrl($baseUrl, $currentPage + 1);
|
||||
}
|
||||
|
||||
// Последняя страница (если не на последней)
|
||||
if ($currentPage < $lastPage) {
|
||||
$links['last'] = $this->buildPageUrl($baseUrl, $lastPage);
|
||||
}
|
||||
|
||||
// Дополнительная мета-информация
|
||||
$links['meta'] = [
|
||||
'current_page' => $currentPage,
|
||||
'last_page' => $lastPage,
|
||||
'per_page' => $meta['per_page'],
|
||||
'total' => $meta['total']
|
||||
];
|
||||
|
||||
return $links;
|
||||
}
|
||||
|
||||
/**
|
||||
* Нормализует базовый URL
|
||||
*/
|
||||
protected function normalizeBaseUrl(?string $url): string
|
||||
{
|
||||
if ($url !== null) {
|
||||
return $url;
|
||||
}
|
||||
|
||||
if (function_exists('url')) {
|
||||
// Laravel
|
||||
return url()->current();
|
||||
}
|
||||
|
||||
// Чистый PHP
|
||||
$protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || ($_SERVER['SERVER_PORT'] ?? null) == 443) ? 'https://' : 'http://';
|
||||
|
||||
$host = $_SERVER['HTTP_HOST'] ?? 'localhost';
|
||||
$uri = $_SERVER['REQUEST_URI'] ?? '/';
|
||||
|
||||
// Удаляем параметр page если он есть
|
||||
$uri = preg_replace('/([?&])page=[^&]*(&|$)/', '$1', $uri);
|
||||
|
||||
return $protocol . $host . rtrim($uri, '?&');
|
||||
}
|
||||
|
||||
/**
|
||||
* Строит URL для конкретной страницы
|
||||
*/
|
||||
protected function buildPageUrl(string $baseUrl, int $page): string
|
||||
{
|
||||
if ($page <= 1) {
|
||||
return $baseUrl; // Первая страница без параметра
|
||||
}
|
||||
|
||||
$separator = strpos($baseUrl, '?') === false ? '?' : '&';
|
||||
return $baseUrl . $separator . 'page=' . $page;
|
||||
}
|
||||
|
||||
public function renderPaginationLinks(array $meta, string $url, int $showPages = 5): string
|
||||
{
|
||||
$currentPage = $meta['current_page'];
|
||||
$lastPage = $meta['last_page'];
|
||||
|
||||
// Определяем диапазон страниц для отображения
|
||||
$startPage = max(1, $currentPage - floor($showPages / 2));
|
||||
$endPage = min($lastPage, $startPage + $showPages - 1);
|
||||
|
||||
$html = '<div class="pagination">';
|
||||
|
||||
// Кнопка "Назад"
|
||||
if ($currentPage > 1) {
|
||||
$html .= '<a href="' . $this->buildPageUrl($url, $currentPage - 1) . '" class="page-link prev">« Назад</a>';
|
||||
}
|
||||
|
||||
// Первая страница
|
||||
if ($startPage > 1) {
|
||||
$html .= '<a href="' . $this->buildPageUrl($url, 1) . '" class="page-link">1</a>';
|
||||
if ($startPage > 2) {
|
||||
$html .= '<span class="page-dots">...</span>';
|
||||
}
|
||||
}
|
||||
|
||||
// Основные страницы
|
||||
for ($i = $startPage; $i <= $endPage; $i++) {
|
||||
$activeClass = $i == $currentPage ? ' active' : '';
|
||||
$html .= '<a href="' . $this->buildPageUrl($url, $i) . '" class="page-link' . $activeClass . '">' . $i . '</a>';
|
||||
}
|
||||
|
||||
// Последняя страница
|
||||
if ($endPage < $lastPage) {
|
||||
if ($endPage < $lastPage - 1) {
|
||||
$html .= '<span class="page-dots">...</span>';
|
||||
}
|
||||
$html .= '<a href="' . $this->buildPageUrl($url, $lastPage) . '" class="page-link">' . $lastPage . '</a>';
|
||||
}
|
||||
|
||||
// Кнопка "Вперед"
|
||||
if ($currentPage < $lastPage) {
|
||||
$html .= '<a href="' . $this->buildPageUrl($url, $currentPage + 1) . '" class="page-link next">Вперед »</a>';
|
||||
}
|
||||
|
||||
$html .= '</div>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function setPaginationTemplate(array $tpl)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function getQuery(): Builder
|
||||
{
|
||||
return $this->query;
|
||||
}
|
||||
}
|
@ -209,11 +209,11 @@ class EntityRelation
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getAdditionalPropertyByEntityId(string $entity, string $entity_id, string $additionalPropertySlug): string
|
||||
public function getAdditionalPropertyByEntityId(string $entity, string $entity_id, string $additionalPropertySlug, array $params = []): string
|
||||
{
|
||||
$moduleClass = $this->getAdditionalPropertyClassBySlug($additionalPropertySlug);
|
||||
if ($moduleClass and method_exists($moduleClass, "getItem")) {
|
||||
return $moduleClass->getItem($entity, $entity_id);
|
||||
return $moduleClass->getItem($entity, $entity_id, $params);
|
||||
}
|
||||
|
||||
return "";
|
||||
@ -276,4 +276,20 @@ class EntityRelation
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function callModuleMethod(string $slug, string $method, array $params)
|
||||
{
|
||||
$module = $this->moduleService->getModuleInfoBySlug($slug);
|
||||
if (isset($module['module_class'])) {
|
||||
$moduleClass = new $module['module_class']();
|
||||
if (method_exists($moduleClass, $method)) {
|
||||
|
||||
return call_user_func_array([$moduleClass, $method], $params);
|
||||
} else {
|
||||
echo "Метод $method не существует";
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -132,6 +132,18 @@ class Request
|
||||
return $_GET[$param] ?? $defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $param
|
||||
* @return mixed
|
||||
*/
|
||||
public function except(string $param): mixed
|
||||
{
|
||||
$params = $this->get();
|
||||
unset($param);
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Возвращает POST - параметр.
|
||||
|
@ -63,15 +63,6 @@ $assets = new \kernel\admin_themes\default\DefaultAdminThemeAssets($resources)
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="/admin/logout">Выход</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="#">About</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="#">Portfolio</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="#">Contact</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
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();
|
43
kernel/app_modules/gestalt_profile/Gestalt_profileModule.php
Normal file
43
kernel/app_modules/gestalt_profile/Gestalt_profileModule.php
Normal 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");
|
||||
}
|
||||
}
|
@ -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"];
|
||||
}
|
||||
|
||||
}
|
@ -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/");
|
||||
}
|
||||
}
|
@ -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');
|
||||
}
|
||||
};
|
118
kernel/app_modules/gestalt_profile/models/Gestalt_profile.php
Normal file
118
kernel/app_modules/gestalt_profile/models/Gestalt_profile.php
Normal 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();
|
||||
}
|
||||
|
||||
}
|
@ -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',
|
||||
];
|
||||
}
|
||||
|
||||
}
|
25
kernel/app_modules/gestalt_profile/routs/gestalt_profile.php
Normal file
25
kernel/app_modules/gestalt_profile/routs/gestalt_profile.php
Normal 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]);
|
||||
});
|
||||
});
|
@ -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();
|
||||
}
|
||||
}
|
55
kernel/app_modules/gestalt_profile/views/form.php
Normal file
55
kernel/app_modules/gestalt_profile/views/form.php
Normal 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();
|
90
kernel/app_modules/gestalt_profile/views/index.php
Normal file
90
kernel/app_modules/gestalt_profile/views/index.php
Normal 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();
|
32
kernel/app_modules/gestalt_profile/views/view.php
Normal file
32
kernel/app_modules/gestalt_profile/views/view.php
Normal 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();
|
@ -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();
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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');
|
||||
}
|
||||
};
|
@ -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');
|
||||
}
|
||||
|
||||
}
|
@ -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',
|
||||
];
|
||||
}
|
||||
|
||||
}
|
@ -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']);
|
||||
});
|
||||
});
|
||||
});
|
@ -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();
|
||||
}
|
||||
}
|
@ -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();
|
@ -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();
|
@ -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();
|
@ -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();
|
@ -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);
|
||||
|
31
kernel/app_themes/gestalt/GestaltTheme.php
Normal file
31
kernel/app_themes/gestalt/GestaltTheme.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_themes\gestalt;
|
||||
|
||||
use kernel\modules\menu\service\MenuService;
|
||||
use kernel\services\MigrationService;
|
||||
|
||||
class GestaltTheme
|
||||
{
|
||||
public MenuService $menuService;
|
||||
public MigrationService $migrationService;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->menuService = new MenuService();
|
||||
$this->migrationService = new MigrationService();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function init(): void
|
||||
{
|
||||
//TODO
|
||||
}
|
||||
|
||||
public function deactivate(): void
|
||||
{
|
||||
//TODO
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_themes\gestalt\services;
|
||||
|
||||
class GestaltThemeService
|
||||
{
|
||||
|
||||
}
|
@ -119,4 +119,48 @@ class ModuleController extends ConsoleController
|
||||
$this->out->r("Модуль $slug создан", 'green');
|
||||
}
|
||||
|
||||
public function actionConstructController(): void
|
||||
{
|
||||
$this->out->r("Введите slug контроллера:", 'yellow');
|
||||
$slug = substr(fgets(STDIN), 0, -1);
|
||||
$slug = strtolower($slug);
|
||||
|
||||
$this->out->r("Введите model контроллера:", 'yellow');
|
||||
$model = substr(fgets(STDIN), 0, -1);
|
||||
|
||||
$this->out->r("Введите путь контроллера:", 'yellow');
|
||||
$path = substr(fgets(STDIN), 0, -1);
|
||||
$path = strtolower($path);
|
||||
|
||||
$moduleService = new ModuleService();
|
||||
$moduleService->createController([
|
||||
'slug' => $slug,
|
||||
'model' => $model,
|
||||
], $path);
|
||||
|
||||
$this->out->r("Контроллер $slug создан", 'green');
|
||||
}
|
||||
|
||||
public function actionConstructCRUD(): void
|
||||
{
|
||||
$this->out->r("Введите slug для CRUD:", 'yellow');
|
||||
$slug = substr(fgets(STDIN), 0, -1);
|
||||
$slug = strtolower($slug);
|
||||
|
||||
$this->out->r("Введите model для CRUD:", 'yellow');
|
||||
$model = substr(fgets(STDIN), 0, -1);
|
||||
|
||||
$this->out->r("Введите путь для CRUD:", 'yellow');
|
||||
$path = substr(fgets(STDIN), 0, -1);
|
||||
$path = strtolower($path);
|
||||
|
||||
$moduleService = new ModuleService();
|
||||
$moduleService->createCRUD([
|
||||
'slug' => $slug,
|
||||
'model' => $model,
|
||||
], $path);
|
||||
|
||||
$this->out->r("CRUD $model создан", 'green');
|
||||
}
|
||||
|
||||
}
|
@ -91,6 +91,14 @@ App::$collector->group(["prefix" => "module"], callback: function (RouteCollecto
|
||||
[\kernel\console\controllers\ModuleController::class, 'actionConstructModule'],
|
||||
additionalInfo: ['description' => 'Сгенерировать модуль']
|
||||
);
|
||||
App::$collector->console('construct/controller',
|
||||
[\kernel\console\controllers\ModuleController::class, 'actionConstructController'],
|
||||
additionalInfo: ['description' => 'Сгенерировать контроллер']
|
||||
);
|
||||
App::$collector->console('construct/crud',
|
||||
[\kernel\console\controllers\ModuleController::class, 'actionConstructCRUD'],
|
||||
additionalInfo: ['description' => 'Сгенерировать CRUD']
|
||||
);
|
||||
});
|
||||
|
||||
App::$collector->group(["prefix" => "kernel"], callback: function (RouteCollector $router){
|
||||
|
@ -125,4 +125,12 @@ class Files
|
||||
}
|
||||
}
|
||||
|
||||
public static function isImageByExtension($filename): bool
|
||||
{
|
||||
$allowedExtensions = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp'];
|
||||
$extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
|
||||
|
||||
return in_array($extension, $allowedExtensions);
|
||||
}
|
||||
|
||||
}
|
19
kernel/helpers/Url.php
Normal file
19
kernel/helpers/Url.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\helpers;
|
||||
|
||||
class Url
|
||||
{
|
||||
|
||||
public static function get_base_url()
|
||||
{
|
||||
// Удаляем параметр page если он есть
|
||||
$currentUrl = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http")
|
||||
. "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
|
||||
// Удаляем параметр page если он есть
|
||||
$currentUrl = preg_replace('/([?&])page=[^&]*(&|$)/', '$1', $currentUrl);
|
||||
|
||||
return rtrim($currentUrl, '?&');
|
||||
}
|
||||
|
||||
}
|
@ -53,7 +53,7 @@ class MigrationService
|
||||
$dmr->delete($migrationInstance);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw new \Exception('Не удалось откатить миграции');
|
||||
throw new \Exception('Не удалось откатить миграции: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -644,4 +644,61 @@ class ModuleService
|
||||
return true;
|
||||
}
|
||||
|
||||
public function createCRUD(array $params, string $modulePath)
|
||||
{
|
||||
$slug = $params['slug'];
|
||||
$model = $params['model'];
|
||||
|
||||
$this->createModuleFileByTemplate(
|
||||
KERNEL_TEMPLATES_DIR . '/controllers/kernel_controller_template',
|
||||
$modulePath . '/controllers/' . $model . 'Controller.php',
|
||||
$params
|
||||
);
|
||||
$this->createModuleFileByTemplate(
|
||||
KERNEL_TEMPLATES_DIR . '/models/model_template',
|
||||
$modulePath . '/models/' . $model . '.php',
|
||||
$params
|
||||
);
|
||||
$this->createModuleFileByTemplate(
|
||||
KERNEL_TEMPLATES_DIR . '/models/forms/create_form_template',
|
||||
$modulePath . '/models/forms/Create' . $model . 'Form.php',
|
||||
$params
|
||||
);
|
||||
$this->createModuleFileByTemplate(
|
||||
KERNEL_TEMPLATES_DIR . '/services/service_template',
|
||||
$modulePath . '/services/' . $model . 'Service.php',
|
||||
$params
|
||||
);
|
||||
|
||||
mkdir($modulePath . '/views/' . strtolower($model));
|
||||
|
||||
$this->createModuleFileByTemplate(
|
||||
KERNEL_TEMPLATES_DIR . '/views/index_template',
|
||||
$modulePath . '/views/' . strtolower($model) . '/index.php',
|
||||
$params
|
||||
);
|
||||
$this->createModuleFileByTemplate(
|
||||
KERNEL_TEMPLATES_DIR . '/views/view_template',
|
||||
$modulePath . '/views/' . strtolower($model) . '/view.php',
|
||||
$params
|
||||
);
|
||||
$this->createModuleFileByTemplate(
|
||||
KERNEL_TEMPLATES_DIR . '/views/form_template',
|
||||
$modulePath . '/views/' . strtolower($model) . '/form.php',
|
||||
$params
|
||||
);
|
||||
}
|
||||
|
||||
public function createController(array $params, string $path): void
|
||||
{
|
||||
$slug = $params['slug'];
|
||||
$model = $params['model'];
|
||||
|
||||
$this->createModuleFileByTemplate(
|
||||
KERNEL_TEMPLATES_DIR . '/controllers/kernel_controller_template',
|
||||
$path . '/' . $model . 'Controller.php',
|
||||
$params
|
||||
);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user