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