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

View File

@ -0,0 +1,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();
}
}