From 50fbc7fd158b9c038953433b338cdc5c3d70b8b6 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Fri, 29 Oct 2021 11:30:01 +0200 Subject: [PATCH] processing of review. still ACL left to do --- .../Controller/RelationshipApiController.php | 2 +- .../Entity/Relationships/Relation.php | 18 ++++++ .../Relationships/RelationRepository.php | 62 ++++++++----------- .../Relationships/RelationshipRepository.php | 50 ++++++++++----- .../Normalizer/RelationshipNormalizer.php | 38 ------------ .../migrations/Version20211029075117.php | 29 +++++++++ 6 files changed, 110 insertions(+), 89 deletions(-) delete mode 100644 src/Bundle/ChillPersonBundle/Serializer/Normalizer/RelationshipNormalizer.php create mode 100644 src/Bundle/ChillPersonBundle/migrations/Version20211029075117.php diff --git a/src/Bundle/ChillPersonBundle/Controller/RelationshipApiController.php b/src/Bundle/ChillPersonBundle/Controller/RelationshipApiController.php index 765d13d25..69809d6ee 100644 --- a/src/Bundle/ChillPersonBundle/Controller/RelationshipApiController.php +++ b/src/Bundle/ChillPersonBundle/Controller/RelationshipApiController.php @@ -25,7 +25,7 @@ class RelationshipApiController extends ApiController /** * @Route("/api/1.0/relation/relationship/by-person/{person_id}.json", - * name="chill_relation_relationship_by_person") + * name="chill_relationship_by_person") * * @ParamConverter("person", options={"id" = "person_id"}) */ diff --git a/src/Bundle/ChillPersonBundle/Entity/Relationships/Relation.php b/src/Bundle/ChillPersonBundle/Entity/Relationships/Relation.php index a0fefc877..7628863fe 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Relationships/Relation.php +++ b/src/Bundle/ChillPersonBundle/Entity/Relationships/Relation.php @@ -35,6 +35,12 @@ class Relation */ private array $reverseTitle = []; + /** + * @ORM\Column(type="boolean", nullable=true) + * @Serializer\Groups({"read"}) + */ + private bool $isActive = true; + public function getId(): ?int { return $this->id; @@ -63,4 +69,16 @@ class Relation return $this; } + + public function getIsActive(): bool + { + return $this->isActive; + } + + public function setIsActive(?bool $isActive): self + { + $this->isActive = $isActive; + + return $this; + } } \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/Repository/Relationships/RelationRepository.php b/src/Bundle/ChillPersonBundle/Repository/Relationships/RelationRepository.php index 8b5fbb743..b735138f4 100644 --- a/src/Bundle/ChillPersonBundle/Repository/Relationships/RelationRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/Relationships/RelationRepository.php @@ -2,49 +2,41 @@ namespace Chill\PersonBundle\Repository\Relationships; -use App\Entity\Relation; -use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; -use Doctrine\Persistence\ManagerRegistry; +use Chill\PersonBundle\Entity\Relationships\Relation; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\EntityRepository; +use Doctrine\Persistence\ObjectRepository; -/** - * @method Relation|null find($id, $lockMode = null, $lockVersion = null) - * @method Relation|null findOneBy(array $criteria, array $orderBy = null) - * @method Relation[] findAll() - * @method Relation[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) - */ -class RelationRepository extends ServiceEntityRepository +class RelationRepository implements ObjectRepository { - public function __construct(ManagerRegistry $registry) + private EntityRepository $repository; + + public function __construct(EntityManagerInterface $entityManager) { - parent::__construct($registry, Relation::class); + $this->repository = $entityManager->getRepository(Relation::class); + } + public function find($id): ?Relation + { + return $this->repository->find($id); } - // /** - // * @return Relation[] Returns an array of Relation objects - // */ - /* - public function findByExampleField($value) + public function findAll(): array { - return $this->createQueryBuilder('r') - ->andWhere('r.exampleField = :val') - ->setParameter('val', $value) - ->orderBy('r.id', 'ASC') - ->setMaxResults(10) - ->getQuery() - ->getResult() - ; + return $this->repository->findAll(); } - */ - /* - public function findOneBySomeField($value): ?Relation + public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array { - return $this->createQueryBuilder('r') - ->andWhere('r.exampleField = :val') - ->setParameter('val', $value) - ->getQuery() - ->getOneOrNullResult() - ; + return $this->repository->findBy($criteria, $orderBy, $limit, $offset); + } + + public function findOneBy(array $criteria): ?Relation + { + return $this->findOneBy($criteria); + } + + public function getClassName(): string + { + return MaritalStatus::class; } - */ } diff --git a/src/Bundle/ChillPersonBundle/Repository/Relationships/RelationshipRepository.php b/src/Bundle/ChillPersonBundle/Repository/Relationships/RelationshipRepository.php index 00546e424..3f105537a 100644 --- a/src/Bundle/ChillPersonBundle/Repository/Relationships/RelationshipRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/Relationships/RelationshipRepository.php @@ -3,30 +3,50 @@ namespace Chill\PersonBundle\Repository\Relationships; use Chill\PersonBundle\Entity\Relationships\Relationship; -use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\EntityRepository; use Doctrine\Persistence\ManagerRegistry; +use Doctrine\Persistence\ObjectRepository; -/** - * @method Relationship|null find($id, $lockMode = null, $lockVersion = null) - * @method Relationship|null findOneBy(array $criteria, array $orderBy = null) - * @method Relationship[] findAll() - * @method Relationship[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) - */ -class RelationshipRepository extends ServiceEntityRepository +class RelationshipRepository implements ObjectRepository { - public function __construct(ManagerRegistry $registry) + + private EntityRepository $repository; + + public function __construct(EntityManagerInterface $em) { - parent::__construct($registry, Relationship::class); + $this->repository = $em->getRepository(Relationship::class); } - // /** - // * @return Relationship[] Returns an array of Relationship objects linked to certain person. - // */ + public function find($id): ?Relationship + { + return $this->repository->find($id); + } + + public function findAll(): array + { + return $this->repository->findAll(); + } + + public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array + { + return $this->repository->findBy($criteria, $orderBy, $limit, $offset); + } + + public function findOneBy(array $criteria): ?Relationship + { + return $this->findOneBy($criteria); + } + + public function getClassName(): string + { + return MaritalStatus::class; + } - public function findByPerson($personId) + public function findByPerson($personId): array { // return all relationships of which person is part? or only where person is the fromPerson? - return $this->createQueryBuilder('r') + return $this->repository->createQueryBuilder('r') ->select('r, t') // entity Relationship ->join('r.relation', 't') ->where('r.fromPerson = :val') diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/RelationshipNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/RelationshipNormalizer.php deleted file mode 100644 index e410dd90b..000000000 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/RelationshipNormalizer.php +++ /dev/null @@ -1,38 +0,0 @@ - 'relationship', - 'id' => $this->normalizer->normalize($relationship->getId()), - 'fromPerson' => $this->normalizer->normalize($relationship->getFromPerson()), - 'toPerson' => $this->normalizer->normalize($relationship->getToPerson()), - 'relation' => $this->normalizer->normalize($relationship->getRelation()), - 'reverse' => $relationship->getReverse() - ]; - } - - public function supportsNormalization($data, ?string $format = null) - { - return $data instanceof Relationship; - } - -} \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/migrations/Version20211029075117.php b/src/Bundle/ChillPersonBundle/migrations/Version20211029075117.php new file mode 100644 index 000000000..9c3d5131e --- /dev/null +++ b/src/Bundle/ChillPersonBundle/migrations/Version20211029075117.php @@ -0,0 +1,29 @@ +addSql('ALTER TABLE chill_person_relations ADD isActive BOOLEAN NOT NULL'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE chill_person_relations DROP isActive'); + } +}