phpcsfixes

This commit is contained in:
Julie Lenaerts 2022-02-11 11:28:32 +01:00 committed by Julien Fastré
parent bf0b7f1bb2
commit c8e5ba4738
8 changed files with 103 additions and 85 deletions

View File

@ -37,10 +37,10 @@ class DocumentAccompanyingCourseController extends AbstractController
protected TranslatorInterface $translator; protected TranslatorInterface $translator;
private PaginatorFactory $paginatorFactory;
private AccompanyingCourseDocumentRepository $courseRepository; private AccompanyingCourseDocumentRepository $courseRepository;
private PaginatorFactory $paginatorFactory;
/** /**
* DocumentAccompanyingCourseController constructor. * DocumentAccompanyingCourseController constructor.
*/ */
@ -142,13 +142,12 @@ class DocumentAccompanyingCourseController extends AbstractController
$pagination->getCurrentPageFirstItemNumber() $pagination->getCurrentPageFirstItemNumber()
); );
return $this->render( return $this->render(
'ChillDocStoreBundle:AccompanyingCourseDocument:index.html.twig', 'ChillDocStoreBundle:AccompanyingCourseDocument:index.html.twig',
[ [
'documents' => $documents, 'documents' => $documents,
'accompanyingCourse' => $course, 'accompanyingCourse' => $course,
'pagination' => $pagination 'pagination' => $pagination,
] ]
); );
} }

View File

@ -163,7 +163,8 @@ class DocumentPersonController extends AbstractController
$person, $person,
[], [],
$pagination->getItemsPerPage(), $pagination->getItemsPerPage(),
$pagination->getCurrentPageFirstItemNumber()); $pagination->getCurrentPageFirstItemNumber()
);
$event = new PrivacyEvent($person, [ $event = new PrivacyEvent($person, [
'element_class' => PersonDocument::class, 'element_class' => PersonDocument::class,
@ -176,7 +177,7 @@ class DocumentPersonController extends AbstractController
[ [
'documents' => $documents, 'documents' => $documents,
'person' => $person, 'person' => $person,
'pagination' => $pagination 'pagination' => $pagination,
] ]
); );
} }

View File

@ -77,6 +77,11 @@ class Document implements HasScopeInterface, TrackCreationInterface, TrackUpdate
*/ */
private $scope; private $scope;
/**
* @ORM\ManyToOne(targetEntity="Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate")
*/
private $template;
/** /**
* @ORM\Column(type="text") * @ORM\Column(type="text")
* @Assert\Length( * @Assert\Length(
@ -92,12 +97,6 @@ class Document implements HasScopeInterface, TrackCreationInterface, TrackUpdate
*/ */
private $user; private $user;
/**
* @ORM\ManyToOne(targetEntity="Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate")
*/
private $template;
public function getCategory(): ?DocumentCategory public function getCategory(): ?DocumentCategory
{ {
return $this->category; return $this->category;
@ -133,6 +132,11 @@ class Document implements HasScopeInterface, TrackCreationInterface, TrackUpdate
return $this->scope; return $this->scope;
} }
public function getTemplate(): ?DocGeneratorTemplate
{
return $this->template;
}
public function getTitle(): ?string public function getTitle(): ?string
{ {
return $this->title; return $this->title;
@ -143,11 +147,6 @@ class Document implements HasScopeInterface, TrackCreationInterface, TrackUpdate
return $this->user; return $this->user;
} }
public function getTemplate(): ?DocGeneratorTemplate
{
return $this->template;
}
public function setCategory(DocumentCategory $category): self public function setCategory(DocumentCategory $category): self
{ {
$this->category = $category; $this->category = $category;
@ -183,6 +182,13 @@ class Document implements HasScopeInterface, TrackCreationInterface, TrackUpdate
return $this; return $this;
} }
public function setTemplate(?DocGeneratorTemplate $template): self
{
$this->template = $template;
return $this;
}
public function setTitle(string $title): self public function setTitle(string $title): self
{ {
$this->title = $title; $this->title = $title;
@ -196,11 +202,4 @@ class Document implements HasScopeInterface, TrackCreationInterface, TrackUpdate
return $this; return $this;
} }
public function setTemplate(?DocGeneratorTemplate $template): self
{
$this->template = $template;
return $this;
}
} }

View File

@ -30,19 +30,13 @@ class AccompanyingCourseDocumentRepository implements ObjectRepository
$this->repository = $em->getRepository(AccompanyingCourseDocument::class); $this->repository = $em->getRepository(AccompanyingCourseDocument::class);
} }
public function find($id): ?AccompanyingCourseDocument
{
return $this->repository->find($id);
}
public function buildQueryByCourse(AccompanyingPeriod $course): QueryBuilder public function buildQueryByCourse(AccompanyingPeriod $course): QueryBuilder
{ {
$qb = $this->repository->createQueryBuilder('d'); $qb = $this->repository->createQueryBuilder('d');
$qb $qb
->where($qb->expr()->eq('d.course', ':course')) ->where($qb->expr()->eq('d.course', ':course'))
->setParameter('course', $course) ->setParameter('course', $course);
;
return $qb; return $qb;
} }
@ -54,6 +48,11 @@ class AccompanyingCourseDocumentRepository implements ObjectRepository
return $qb->getQuery()->getSingleScalarResult(); return $qb->getQuery()->getSingleScalarResult();
} }
public function find($id): ?AccompanyingCourseDocument
{
return $this->repository->find($id);
}
public function findAll(): array public function findAll(): array
{ {
return $this->repository->findAll(); return $this->repository->findAll();
@ -73,5 +72,4 @@ class AccompanyingCourseDocumentRepository implements ObjectRepository
{ {
return AccompanyingCourseDocument::class; return AccompanyingCourseDocument::class;
} }
} }

View File

@ -1,5 +1,14 @@
<?php <?php
/**
* 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.
*/
declare(strict_types=1);
namespace Chill\DocStoreBundle\Repository; namespace Chill\DocStoreBundle\Repository;
use Chill\DocStoreBundle\Entity\PersonDocument; use Chill\DocStoreBundle\Entity\PersonDocument;
@ -13,12 +22,12 @@ use Symfony\Component\Security\Core\Security;
class PersonDocumentACLAwareRepository implements PersonDocumentACLAwareRepositoryInterface class PersonDocumentACLAwareRepository implements PersonDocumentACLAwareRepositoryInterface
{ {
private EntityManagerInterface $em;
private AuthorizationHelperInterface $authorizationHelper; private AuthorizationHelperInterface $authorizationHelper;
private CenterResolverDispatcher $centerResolverDispatcher; private CenterResolverDispatcher $centerResolverDispatcher;
private EntityManagerInterface $em;
private Security $security; private Security $security;
public function __construct(EntityManagerInterface $em, AuthorizationHelperInterface $authorizationHelper, CenterResolverDispatcher $centerResolverDispatcher, Security $security) public function __construct(EntityManagerInterface $em, AuthorizationHelperInterface $authorizationHelper, CenterResolverDispatcher $centerResolverDispatcher, Security $security)
@ -29,19 +38,15 @@ class PersonDocumentACLAwareRepository implements PersonDocumentACLAwareReposito
$this->security = $security; $this->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)) { return $qb;
$qb->addOrderBy($field, $order);
}
$qb->setFirstResult($offset)->setMaxResults($limit);
return $qb->getQuery()->getResult();
} }
public function countByPerson(Person $person): int public function countByPerson(Person $person): int
@ -53,21 +58,23 @@ class PersonDocumentACLAwareRepository implements PersonDocumentACLAwareReposito
return $qb->getQuery()->getSingleScalarResult(); 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 $this->addACL($qb, $person);
->where($qb->expr()->eq('d.person', ':person'))
->setParameter('person', $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 private function addACL(QueryBuilder $qb, Person $person): void
{ {
$center = $this->centerResolverDispatcher->resolveCenter($person); $center = $this->centerResolverDispatcher->resolveCenter($person);
$reachableScopes = $this->authorizationHelper $reachableScopes = $this->authorizationHelper
@ -78,8 +85,6 @@ class PersonDocumentACLAwareRepository implements PersonDocumentACLAwareReposito
); );
$qb->andWhere($qb->expr()->in('d.scope', ':scopes')) $qb->andWhere($qb->expr()->in('d.scope', ':scopes'))
->setParameter('scopes', $reachableScopes) ->setParameter('scopes', $reachableScopes);
;
} }
} }

View File

@ -1,12 +1,21 @@
<?php <?php
/**
* 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.
*/
declare(strict_types=1);
namespace Chill\DocStoreBundle\Repository; namespace Chill\DocStoreBundle\Repository;
use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\Person;
interface PersonDocumentACLAwareRepositoryInterface interface PersonDocumentACLAwareRepositoryInterface
{ {
public function findByPerson(Person $person, array $orderBy = [], int $limit = 20, int $offset = 0): array;
public function countByPerson(Person $person): int; public function countByPerson(Person $person): int;
public function findByPerson(Person $person, array $orderBy = [], int $limit = 20, int $offset = 0): array;
} }

View File

@ -1,5 +1,12 @@
<?php <?php
/**
* 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.
*/
declare(strict_types=1); declare(strict_types=1);
namespace Chill\Migrations\DocStore; namespace Chill\Migrations\DocStore;
@ -8,10 +15,30 @@ use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration; use Doctrine\Migrations\AbstractMigration;
/** /**
* Implementations of create and update traits for Document entity + template property added * Implementations of create and update traits for Document entity + template property added.
*/ */
final class Version20220131093117 extends AbstractMigration final class Version20220131093117 extends AbstractMigration
{ {
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');
}
public function getDescription(): string public function getDescription(): string
{ {
return 'Implementations of create and update traits for Document entity + template property added'; 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_41DA53C3174800F ON chill_doc.person_document (createdBy_id)');
$this->addSql('CREATE INDEX IDX_41DA53C65FF1AEC ON chill_doc.person_document (updatedBy_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');
}
} }