diff --git a/src/Bundle/ChillDocStoreBundle/Controller/DocumentAccompanyingCourseController.php b/src/Bundle/ChillDocStoreBundle/Controller/DocumentAccompanyingCourseController.php index 2df90e854..199f88c60 100644 --- a/src/Bundle/ChillDocStoreBundle/Controller/DocumentAccompanyingCourseController.php +++ b/src/Bundle/ChillDocStoreBundle/Controller/DocumentAccompanyingCourseController.php @@ -37,10 +37,10 @@ class DocumentAccompanyingCourseController extends AbstractController protected TranslatorInterface $translator; - private PaginatorFactory $paginatorFactory; - private AccompanyingCourseDocumentRepository $courseRepository; + private PaginatorFactory $paginatorFactory; + /** * DocumentAccompanyingCourseController constructor. */ @@ -142,13 +142,12 @@ class DocumentAccompanyingCourseController extends AbstractController $pagination->getCurrentPageFirstItemNumber() ); - return $this->render( 'ChillDocStoreBundle:AccompanyingCourseDocument:index.html.twig', [ 'documents' => $documents, 'accompanyingCourse' => $course, - 'pagination' => $pagination + 'pagination' => $pagination, ] ); } diff --git a/src/Bundle/ChillDocStoreBundle/Controller/DocumentPersonController.php b/src/Bundle/ChillDocStoreBundle/Controller/DocumentPersonController.php index 051584f3c..fcb3a4958 100644 --- a/src/Bundle/ChillDocStoreBundle/Controller/DocumentPersonController.php +++ b/src/Bundle/ChillDocStoreBundle/Controller/DocumentPersonController.php @@ -163,7 +163,8 @@ class DocumentPersonController extends AbstractController $person, [], $pagination->getItemsPerPage(), - $pagination->getCurrentPageFirstItemNumber()); + $pagination->getCurrentPageFirstItemNumber() + ); $event = new PrivacyEvent($person, [ 'element_class' => PersonDocument::class, @@ -176,7 +177,7 @@ class DocumentPersonController extends AbstractController [ 'documents' => $documents, 'person' => $person, - 'pagination' => $pagination + 'pagination' => $pagination, ] ); } diff --git a/src/Bundle/ChillDocStoreBundle/Entity/Document.php b/src/Bundle/ChillDocStoreBundle/Entity/Document.php index aa737e4b0..e26469573 100644 --- a/src/Bundle/ChillDocStoreBundle/Entity/Document.php +++ b/src/Bundle/ChillDocStoreBundle/Entity/Document.php @@ -77,6 +77,11 @@ class Document implements HasScopeInterface, TrackCreationInterface, TrackUpdate */ private $scope; + /** + * @ORM\ManyToOne(targetEntity="Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate") + */ + private $template; + /** * @ORM\Column(type="text") * @Assert\Length( @@ -92,12 +97,6 @@ class Document implements HasScopeInterface, TrackCreationInterface, TrackUpdate */ private $user; - /** - * @ORM\ManyToOne(targetEntity="Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate") - */ - private $template; - - public function getCategory(): ?DocumentCategory { return $this->category; @@ -133,6 +132,11 @@ class Document implements HasScopeInterface, TrackCreationInterface, TrackUpdate return $this->scope; } + public function getTemplate(): ?DocGeneratorTemplate + { + return $this->template; + } + public function getTitle(): ?string { return $this->title; @@ -143,11 +147,6 @@ class Document implements HasScopeInterface, TrackCreationInterface, TrackUpdate return $this->user; } - public function getTemplate(): ?DocGeneratorTemplate - { - return $this->template; - } - public function setCategory(DocumentCategory $category): self { $this->category = $category; @@ -183,6 +182,13 @@ class Document implements HasScopeInterface, TrackCreationInterface, TrackUpdate return $this; } + public function setTemplate(?DocGeneratorTemplate $template): self + { + $this->template = $template; + + return $this; + } + public function setTitle(string $title): self { $this->title = $title; @@ -196,11 +202,4 @@ class Document implements HasScopeInterface, TrackCreationInterface, TrackUpdate return $this; } - - public function setTemplate(?DocGeneratorTemplate $template): self - { - $this->template = $template; - return $this; - } - } diff --git a/src/Bundle/ChillDocStoreBundle/Form/PersonDocumentType.php b/src/Bundle/ChillDocStoreBundle/Form/PersonDocumentType.php index 0efcbe86a..3655fb18b 100644 --- a/src/Bundle/ChillDocStoreBundle/Form/PersonDocumentType.php +++ b/src/Bundle/ChillDocStoreBundle/Form/PersonDocumentType.php @@ -90,12 +90,12 @@ class PersonDocumentType extends AbstractType }, ]); - if ($isScopeConcerned && $this->parameterBag->get('chill_main')['acl']['form_show_scopes']) { - $builder->add('scope', ScopePickerType::class, [ - 'center' => $options['center'], - 'role' => $options['role'], - ]); - } + if ($isScopeConcerned && $this->parameterBag->get('chill_main')['acl']['form_show_scopes']) { + $builder->add('scope', ScopePickerType::class, [ + 'center' => $options['center'], + 'role' => $options['role'], + ]); + } } public function configureOptions(OptionsResolver $resolver) diff --git a/src/Bundle/ChillDocStoreBundle/Repository/AccompanyingCourseDocumentRepository.php b/src/Bundle/ChillDocStoreBundle/Repository/AccompanyingCourseDocumentRepository.php index 9dd04185e..57c898b68 100644 --- a/src/Bundle/ChillDocStoreBundle/Repository/AccompanyingCourseDocumentRepository.php +++ b/src/Bundle/ChillDocStoreBundle/Repository/AccompanyingCourseDocumentRepository.php @@ -30,19 +30,13 @@ class AccompanyingCourseDocumentRepository implements ObjectRepository $this->repository = $em->getRepository(AccompanyingCourseDocument::class); } - public function find($id): ?AccompanyingCourseDocument - { - return $this->repository->find($id); - } - public function buildQueryByCourse(AccompanyingPeriod $course): QueryBuilder { $qb = $this->repository->createQueryBuilder('d'); $qb ->where($qb->expr()->eq('d.course', ':course')) - ->setParameter('course', $course) - ; + ->setParameter('course', $course); return $qb; } @@ -54,6 +48,11 @@ class AccompanyingCourseDocumentRepository implements ObjectRepository return $qb->getQuery()->getSingleScalarResult(); } + public function find($id): ?AccompanyingCourseDocument + { + return $this->repository->find($id); + } + public function findAll(): array { return $this->repository->findAll(); @@ -73,5 +72,4 @@ class AccompanyingCourseDocumentRepository implements ObjectRepository { return AccompanyingCourseDocument::class; } - -} \ No newline at end of file +} diff --git a/src/Bundle/ChillDocStoreBundle/Repository/PersonDocumentACLAwareRepository.php b/src/Bundle/ChillDocStoreBundle/Repository/PersonDocumentACLAwareRepository.php index 010da47a3..0f85a74b2 100644 --- a/src/Bundle/ChillDocStoreBundle/Repository/PersonDocumentACLAwareRepository.php +++ b/src/Bundle/ChillDocStoreBundle/Repository/PersonDocumentACLAwareRepository.php @@ -1,5 +1,14 @@ security = $security; } - public function findByPerson(Person $person, array $orderBy = [], int $limit = 20, int $offset = 0): array + public function buildQueryByPerson(Person $person): QueryBuilder { - $qb = $this->buildQueryByPerson($person)->select('d'); + $qb = $this->em->getRepository(PersonDocument::class)->createQueryBuilder('d'); - $this->addACL($qb, $person); + $qb + ->where($qb->expr()->eq('d.person', ':person')) + ->setParameter('person', $person); - foreach ($orderBy as list($field, $order)) { - $qb->addOrderBy($field, $order); - } - - $qb->setFirstResult($offset)->setMaxResults($limit); - - return $qb->getQuery()->getResult(); + return $qb; } public function countByPerson(Person $person): int @@ -53,21 +58,23 @@ class PersonDocumentACLAwareRepository implements PersonDocumentACLAwareReposito return $qb->getQuery()->getSingleScalarResult(); } - public function buildQueryByPerson(Person $person): QueryBuilder + public function findByPerson(Person $person, array $orderBy = [], int $limit = 20, int $offset = 0): array { - $qb = $this->em->getRepository(PersonDocument::class)->createQueryBuilder('d'); + $qb = $this->buildQueryByPerson($person)->select('d'); - $qb - ->where($qb->expr()->eq('d.person', ':person')) - ->setParameter('person', $person) - ; + $this->addACL($qb, $person); - return $qb; + foreach ($orderBy as [$field, $order]) { + $qb->addOrderBy($field, $order); + } + + $qb->setFirstResult($offset)->setMaxResults($limit); + + return $qb->getQuery()->getResult(); } private function addACL(QueryBuilder $qb, Person $person): void { - $center = $this->centerResolverDispatcher->resolveCenter($person); $reachableScopes = $this->authorizationHelper @@ -78,8 +85,6 @@ class PersonDocumentACLAwareRepository implements PersonDocumentACLAwareReposito ); $qb->andWhere($qb->expr()->in('d.scope', ':scopes')) - ->setParameter('scopes', $reachableScopes) - ; + ->setParameter('scopes', $reachableScopes); } - } diff --git a/src/Bundle/ChillDocStoreBundle/Repository/PersonDocumentACLAwareRepositoryInterface.php b/src/Bundle/ChillDocStoreBundle/Repository/PersonDocumentACLAwareRepositoryInterface.php index f4f654b18..85b0288c0 100644 --- a/src/Bundle/ChillDocStoreBundle/Repository/PersonDocumentACLAwareRepositoryInterface.php +++ b/src/Bundle/ChillDocStoreBundle/Repository/PersonDocumentACLAwareRepositoryInterface.php @@ -1,12 +1,21 @@ addSql('ALTER TABLE chill_doc.person_document DROP CONSTRAINT FK_41DA53C5DA0FB8'); + $this->addSql('ALTER TABLE chill_doc.person_document DROP CONSTRAINT FK_41DA53C3174800F'); + $this->addSql('ALTER TABLE chill_doc.person_document DROP CONSTRAINT FK_41DA53C65FF1AEC'); + $this->addSql('ALTER TABLE chill_doc.person_document DROP template_id'); + $this->addSql('ALTER TABLE chill_doc.person_document DROP createdAt'); + $this->addSql('ALTER TABLE chill_doc.person_document DROP updatedAt'); + $this->addSql('ALTER TABLE chill_doc.person_document DROP createdBy_id'); + $this->addSql('ALTER TABLE chill_doc.person_document DROP updatedBy_id'); + $this->addSql('ALTER TABLE chill_doc.accompanyingcourse_document DROP CONSTRAINT FK_A45098F65DA0FB8'); + $this->addSql('ALTER TABLE chill_doc.accompanyingcourse_document DROP CONSTRAINT FK_A45098F63174800F'); + $this->addSql('ALTER TABLE chill_doc.accompanyingcourse_document DROP CONSTRAINT FK_A45098F665FF1AEC'); + $this->addSql('ALTER TABLE chill_doc.accompanyingcourse_document DROP template_id'); + $this->addSql('ALTER TABLE chill_doc.accompanyingcourse_document DROP createdAt'); + $this->addSql('ALTER TABLE chill_doc.accompanyingcourse_document DROP updatedAt'); + $this->addSql('ALTER TABLE chill_doc.accompanyingcourse_document DROP createdBy_id'); + $this->addSql('ALTER TABLE chill_doc.accompanyingcourse_document DROP updatedBy_id'); + } + public function getDescription(): string { return 'Implementations of create and update traits for Document entity + template property added'; @@ -46,24 +73,4 @@ final class Version20220131093117 extends AbstractMigration $this->addSql('CREATE INDEX IDX_41DA53C3174800F ON chill_doc.person_document (createdBy_id)'); $this->addSql('CREATE INDEX IDX_41DA53C65FF1AEC ON chill_doc.person_document (updatedBy_id)'); } - - public function down(Schema $schema): void - { - $this->addSql('ALTER TABLE chill_doc.person_document DROP CONSTRAINT FK_41DA53C5DA0FB8'); - $this->addSql('ALTER TABLE chill_doc.person_document DROP CONSTRAINT FK_41DA53C3174800F'); - $this->addSql('ALTER TABLE chill_doc.person_document DROP CONSTRAINT FK_41DA53C65FF1AEC'); - $this->addSql('ALTER TABLE chill_doc.person_document DROP template_id'); - $this->addSql('ALTER TABLE chill_doc.person_document DROP createdAt'); - $this->addSql('ALTER TABLE chill_doc.person_document DROP updatedAt'); - $this->addSql('ALTER TABLE chill_doc.person_document DROP createdBy_id'); - $this->addSql('ALTER TABLE chill_doc.person_document DROP updatedBy_id'); - $this->addSql('ALTER TABLE chill_doc.accompanyingcourse_document DROP CONSTRAINT FK_A45098F65DA0FB8'); - $this->addSql('ALTER TABLE chill_doc.accompanyingcourse_document DROP CONSTRAINT FK_A45098F63174800F'); - $this->addSql('ALTER TABLE chill_doc.accompanyingcourse_document DROP CONSTRAINT FK_A45098F665FF1AEC'); - $this->addSql('ALTER TABLE chill_doc.accompanyingcourse_document DROP template_id'); - $this->addSql('ALTER TABLE chill_doc.accompanyingcourse_document DROP createdAt'); - $this->addSql('ALTER TABLE chill_doc.accompanyingcourse_document DROP updatedAt'); - $this->addSql('ALTER TABLE chill_doc.accompanyingcourse_document DROP createdBy_id'); - $this->addSql('ALTER TABLE chill_doc.accompanyingcourse_document DROP updatedBy_id'); - } }