em->getClassMetadata(StoredObject::class); $activityMetadata = $this->em->getClassMetadata(Activity::class); $query = new FetchQuery( self::KEY, sprintf("jsonb_build_object('id', doc_obj.%s, 'activity_id', activity.%s)", $storedObjectMetadata->getSingleIdentifierColumnName(), $activityMetadata->getSingleIdentifierColumnName()), '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); } public function isAllowedForPerson(Person $person): bool { return $this->security->isGranted(AccompanyingPeriodVoter::SEE, $person); } public function buildFetchQueryForPerson(Person $person, ?DateTimeImmutable $startDate = null, ?DateTimeImmutable $endDate = null, ?string $content = null, ?string $origin = null): FetchQueryInterface { return $this->activityDocumentACLAwareRepository ->buildFetchQueryActivityDocumentLinkedToAccompanyingPeriodFromPersonContext($person, $startDate, $endDate, $content); } }