mirror of
				https://gitlab.com/Chill-Projet/chill-bundles.git
				synced 2025-10-31 01:08:26 +00:00 
			
		
		
		
	WIP [genericDoc][activity] implementing generic doc for activities
This commit is contained in:
		| @@ -0,0 +1,110 @@ | ||||
| <?php | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| /* | ||||
|  * Chill is a software for social workers | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  */ | ||||
|  | ||||
| namespace Chill\ActivityBundle\Service\GenericDoc\Providers; | ||||
|  | ||||
| use Chill\ActivityBundle\Security\Authorization\ActivityVoter; | ||||
| use Chill\DocStoreBundle\Entity\StoredObject; | ||||
| use Chill\DocStoreBundle\GenericDoc\FetchQuery; | ||||
| use Chill\DocStoreBundle\GenericDoc\FetchQueryInterface; | ||||
| use Chill\DocStoreBundle\GenericDoc\GenericDocForAccompanyingPeriodProviderInterface; | ||||
| use Chill\PersonBundle\Entity\AccompanyingPeriod; | ||||
| use DateTimeImmutable; | ||||
| use Doctrine\DBAL\Types\Types; | ||||
| use Doctrine\ORM\EntityManagerInterface; | ||||
| use Doctrine\ORM\Mapping\MappingException; | ||||
| use Symfony\Component\Security\Core\Security; | ||||
|  | ||||
| final class AccompanyingPeriodActivityGenericDocProvider implements GenericDocForAccompanyingPeriodProviderInterface | ||||
| { | ||||
|     public const KEY = 'accompanying_period_activity_document'; | ||||
|  | ||||
|     private EntityManagerInterface  $em; | ||||
|  | ||||
|     private Security $security; | ||||
|  | ||||
|     public function __construct(Security $security, EntityManagerInterface $entityManager) | ||||
|     { | ||||
|         $this->em = $entityManager; | ||||
|         $this->security = $security; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param AccompanyingPeriod $accompanyingPeriod | ||||
|      * @param DateTimeImmutable|null $startDate | ||||
|      * @param DateTimeImmutable|null $endDate | ||||
|      * @param string|null $content | ||||
|      * @param string|null $origin | ||||
|      * @return FetchQueryInterface | ||||
|      * @throws MappingException | ||||
|      */ | ||||
|     public function buildFetchQueryForAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod, ?DateTimeImmutable $startDate = null, ?DateTimeImmutable $endDate = null, ?string $content = null, ?string $origin = null): FetchQueryInterface | ||||
|     { | ||||
|         $storedObjectMetadata = $this->em->getClassMetadata(StoredObject::class); | ||||
| //        $activityMetadata = $this->em->getClassMetadata(Activity::class); | ||||
|  | ||||
|         $query = new FetchQuery( | ||||
|             self::KEY, | ||||
|             "jsonb_build_object('id', doc_obj.id)", | ||||
|             'doc_obj.'.$storedObjectMetadata->getColumnName('createdAt'), | ||||
|             $storedObjectMetadata->getSchemaName().'.'.$storedObjectMetadata->getTableName().' AS doc_obj' | ||||
|         ); | ||||
|  | ||||
|         $query->addJoinClause( | ||||
|             'JOIN public.activity_storedobject activity_doc ON activity_doc.storedobject_id = doc_obj.id' | ||||
|         ); | ||||
|  | ||||
|         $query->addJoinClause( | ||||
|             'JOIN public.activity activity ON activity.id = activity_doc.activity_id' | ||||
|         ); | ||||
|  | ||||
|         $query->addWhereClause( | ||||
|             'activity.accompanyingperiod_id = ?', | ||||
|             [$accompanyingPeriod->getId()], | ||||
|             [Types::INTEGER] | ||||
|         ); | ||||
|  | ||||
|         if (null !== $startDate) { | ||||
|             $query->addWhereClause( | ||||
|                 sprintf('doc_obj.%s >= ?', $storedObjectMetadata->getColumnName('createdAt')), | ||||
|                 [$startDate], | ||||
|                 [Types::DATE_IMMUTABLE] | ||||
|             ); | ||||
|         } | ||||
|  | ||||
|         if (null !== $endDate) { | ||||
|             $query->addWhereClause( | ||||
|                 sprintf('doc_obj.%s < ?', $storedObjectMetadata->getColumnName('createdAt')), | ||||
|                 [$endDate], | ||||
|                 [Types::DATE_IMMUTABLE] | ||||
|             ); | ||||
|         } | ||||
|  | ||||
|         if (null !== $content) { | ||||
|             $query->addWhereClause( | ||||
|                 'doc_obj.title ilike ?', | ||||
|                 ['%' . $content . '%'], | ||||
|                 [Types::STRING] | ||||
|             ); | ||||
|         } | ||||
|  | ||||
|         return $query; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param AccompanyingPeriod $accompanyingPeriod | ||||
|      * @return bool | ||||
|      */ | ||||
|     public function isAllowedForAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod): bool | ||||
|     { | ||||
|         return $this->security->isGranted(ActivityVoter::SEE, $accompanyingPeriod); | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,45 @@ | ||||
| <?php | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| /* | ||||
|  * Chill is a software for social workers | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  */ | ||||
|  | ||||
| namespace Chill\ActivityBundle\Service\GenericDoc\Renderers; | ||||
|  | ||||
| use Chill\ActivityBundle\Service\GenericDoc\Providers\AccompanyingPeriodActivityGenericDocProvider; | ||||
| use Chill\DocStoreBundle\GenericDoc\GenericDocDTO; | ||||
| use Chill\DocStoreBundle\GenericDoc\Twig\GenericDocRendererInterface; | ||||
| use Chill\DocStoreBundle\Repository\StoredObjectRepository; | ||||
|  | ||||
| final class AccompanyingPeriodActivityGenericDocRenderer implements GenericDocRendererInterface | ||||
| { | ||||
|     private StoredObjectRepository $repository; | ||||
|  | ||||
|     public function __construct(StoredObjectRepository $storedObjectRepository) | ||||
|     { | ||||
|         $this->repository = $storedObjectRepository; | ||||
|     } | ||||
|  | ||||
|     public function supports(GenericDocDTO $genericDocDTO, $options = []): bool | ||||
|     { | ||||
|         return $genericDocDTO->key === AccompanyingPeriodActivityGenericDocProvider::KEY; | ||||
|     } | ||||
|  | ||||
|     public function getTemplate(GenericDocDTO $genericDocDTO, $options = []): string | ||||
|     { | ||||
|         return '@ChillCalendar/GenericDoc/activity_document.html.twig'; | ||||
|     } | ||||
|  | ||||
|     public function getTemplateData(GenericDocDTO $genericDocDTO, $options = []): array | ||||
|     { | ||||
|         return [ | ||||
|             'document' => $this->repository->find($genericDocDTO->identifiers['id']) | ||||
|         ]; | ||||
|     } | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user