mirror of
				https://gitlab.com/Chill-Projet/chill-bundles.git
				synced 2025-10-31 17:28:23 +00:00 
			
		
		
		
	add scope to docs if required
This commit is contained in:
		| @@ -12,6 +12,7 @@ declare(strict_types=1); | ||||
| namespace Chill\PersonBundle\Service\DocGenerator; | ||||
|  | ||||
| use Chill\DocGeneratorBundle\Context\DocGeneratorContextWithAdminFormInterface; | ||||
| use Chill\DocGeneratorBundle\Context\DocGeneratorContextWithPublicFormInterface; | ||||
| use Chill\DocGeneratorBundle\Context\Exception\UnexpectedTypeException; | ||||
| use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate; | ||||
| use Chill\DocGeneratorBundle\Service\Context\BaseContextData; | ||||
| @@ -19,6 +20,8 @@ use Chill\DocStoreBundle\Entity\DocumentCategory; | ||||
| use Chill\DocStoreBundle\Entity\PersonDocument; | ||||
| use Chill\DocStoreBundle\Entity\StoredObject; | ||||
| use Chill\DocStoreBundle\Repository\DocumentCategoryRepository; | ||||
| use Chill\MainBundle\Form\ScopeType; | ||||
| use Chill\MainBundle\Security\Authorization\AuthorizationHelper; | ||||
| use Chill\MainBundle\Templating\TranslatableStringHelperInterface; | ||||
| use Chill\PersonBundle\Entity\Person; | ||||
| use DateTime; | ||||
| @@ -31,7 +34,7 @@ use Symfony\Contracts\Translation\TranslatorInterface; | ||||
|  | ||||
| use function array_key_exists; | ||||
|  | ||||
| class PersonContext implements DocGeneratorContextWithAdminFormInterface | ||||
| class PersonContext implements DocGeneratorContextWithAdminFormInterface, DocGeneratorContextWithPublicFormInterface | ||||
| { | ||||
|     private BaseContextData $baseContextData; | ||||
|  | ||||
| @@ -45,13 +48,16 @@ class PersonContext implements DocGeneratorContextWithAdminFormInterface | ||||
|  | ||||
|     private TranslatorInterface $translator; | ||||
|  | ||||
|     private AuthorizationHelper $authorizationHelper; | ||||
|  | ||||
|     public function __construct( | ||||
|         DocumentCategoryRepository $documentCategoryRepository, | ||||
|         NormalizerInterface $normalizer, | ||||
|         TranslatableStringHelperInterface $translatableStringHelper, | ||||
|         EntityManagerInterface $em, | ||||
|         TranslatorInterface $translator, | ||||
|         BaseContextData $baseContextData | ||||
|         BaseContextData $baseContextData, | ||||
|         AuthorizationHelper $authorizationHelper | ||||
|     ) { | ||||
|         $this->documentCategoryRepository = $documentCategoryRepository; | ||||
|         $this->normalizer = $normalizer; | ||||
| @@ -59,6 +65,7 @@ class PersonContext implements DocGeneratorContextWithAdminFormInterface | ||||
|         $this->em = $em; | ||||
|         $this->baseContextData = $baseContextData; | ||||
|         $this->translator = $translator; | ||||
|         $this->authorizationHelper = $authorizationHelper; | ||||
|     } | ||||
|  | ||||
|     public function adminFormReverseTransform(array $data): array | ||||
| @@ -178,6 +185,42 @@ class PersonContext implements DocGeneratorContextWithAdminFormInterface | ||||
|                 ); | ||||
|         } | ||||
|  | ||||
|         if ($this->showScopes()) { | ||||
|  | ||||
|             $scopes = $this->authorizationHelper->getReachableScopes(); | ||||
|  | ||||
|             if (count($scopes > 1)) | ||||
|             { | ||||
|                 $scope = $this->getFormData(); | ||||
|                 $doc->setScope($scope); | ||||
|  | ||||
|             } else { | ||||
|  | ||||
|                 $doc->setScope($scopes[0]); | ||||
|  | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         $this->em->persist($doc); | ||||
|     } | ||||
|  | ||||
|     public function showScopes(){ | ||||
|         return $this->parameterBag->get('chill_main')['acl']['form_show_scopes']; | ||||
|     } | ||||
|  | ||||
|     public function buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, $entity): void | ||||
|     { | ||||
|         $builder->add('Center', ScopeType::class, [ | ||||
|             'required' => true | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
|     public function hasPublicForm(DocGeneratorTemplate $template, $entity): bool | ||||
|     { | ||||
|         if ($this->showScopes()) { | ||||
|             return true; | ||||
|         } else { | ||||
|             return false; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user