mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Merge branch 'household_filiation' of gitlab.com:Chill-Projet/chill-bundles into household_filiation
This commit is contained in:
commit
80594ed186
@ -21,7 +21,6 @@ use Chill\MainBundle\Entity\Scope;
|
||||
use Chill\PersonBundle\Repository\AccompanyingPeriodACLAwareRepository;
|
||||
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
|
||||
use Symfony\Component\Workflow\Registry;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||
|
||||
class AccompanyingCourseApiController extends ApiController
|
||||
@ -32,8 +31,6 @@ class AccompanyingCourseApiController extends ApiController
|
||||
|
||||
private Registry $registry;
|
||||
|
||||
private AccompanyingPeriodACLAwareRepository $accompanyingPeriodACLAwareRepository;
|
||||
|
||||
public function __construct(
|
||||
EventDispatcherInterface $eventDispatcher,
|
||||
ValidatorInterface $validator,
|
||||
@ -197,12 +194,6 @@ $workflow = $this->registry->get($accompanyingPeriod);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/api/1.0/person/accompanying-course/by-person/{person_id}.{_format}",
|
||||
* name="chill_person_accompanyingperiod_by_person",
|
||||
* requirements={
|
||||
* "_format"="json"
|
||||
* })
|
||||
*
|
||||
* @ParamConverter("person", options={"id" = "person_id"})
|
||||
*/
|
||||
public function getAccompanyingPeriodsByPerson(Person $person){
|
||||
|
@ -8,9 +8,7 @@ use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Repository\Relationships\RelationshipRepository;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class RelationshipApiController extends ApiController
|
||||
{
|
||||
@ -24,9 +22,6 @@ class RelationshipApiController extends ApiController
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/api/1.0/relation/relationship/by-person/{person_id}.json",
|
||||
* name="chill_relation_relationship_by_person")
|
||||
*
|
||||
* @ParamConverter("person", options={"id" = "person_id"})
|
||||
*/
|
||||
public function getRelationshipsByPerson(Person $person)
|
||||
|
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\DataFixtures\ORM;
|
||||
|
||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
|
||||
class LoadRelationships extends Fixture implements DependentFixtureInterface
|
||||
{
|
||||
public function getDependencies()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function load(ObjectManager $manager)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -879,14 +879,10 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac
|
||||
'actions' => [
|
||||
'_entity' => [
|
||||
'methods' => [
|
||||
Request::METHOD_GET => true,
|
||||
Request::METHOD_HEAD => true,
|
||||
Request::METHOD_POST => true,
|
||||
Request::METHOD_PATCH => true
|
||||
],
|
||||
'roles' => [
|
||||
Request::METHOD_GET => 'ROLE_USER',
|
||||
Request::METHOD_HEAD => 'ROLE_USER',
|
||||
Request::METHOD_POST => 'ROLE_USER',
|
||||
Request::METHOD_PATCH => 'ROLE_USER'
|
||||
]
|
||||
|
@ -3,10 +3,16 @@
|
||||
namespace Chill\PersonBundle\Entity\Relationships;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Doctrine\ORM\Mapping\DiscriminatorColumn;
|
||||
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
|
||||
use Symfony\Component\Serializer\Annotation as Serializer;
|
||||
|
||||
/**
|
||||
* @ORM\Entity()
|
||||
* @ORM\Table(name="chill_person_relations")
|
||||
* @DiscriminatorMap(typeProperty="type", mapping={
|
||||
* "relation"=Relation::class
|
||||
* })
|
||||
*/
|
||||
class Relation
|
||||
{
|
||||
@ -15,17 +21,25 @@ class Relation
|
||||
* @ORM\GeneratedValue
|
||||
* @ORM\Column(type="integer")
|
||||
*/
|
||||
private $id;
|
||||
private ?int $id = null;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="json", nullable=true)
|
||||
* @Serializer\Groups({"read"})
|
||||
*/
|
||||
private $title = [];
|
||||
private array $title = [];
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="json", nullable=true)
|
||||
* @Serializer\Groups({"read"})
|
||||
*/
|
||||
private $reverseTitle = [];
|
||||
private array $reverseTitle = [];
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="boolean", nullable=true)
|
||||
* @Serializer\Groups({"read"})
|
||||
*/
|
||||
private bool $isActive = true;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
@ -55,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;
|
||||
}
|
||||
}
|
@ -2,50 +2,60 @@
|
||||
|
||||
namespace Chill\PersonBundle\Entity\Relationships;
|
||||
|
||||
use Chill\MainBundle\Doctrine\Model\TrackCreationInterface;
|
||||
use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Entity\Relationships\Relation;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
use Symfony\Component\Serializer\Annotation\Groups;
|
||||
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
|
||||
use Doctrine\ORM\Mapping\DiscriminatorColumn;
|
||||
use Symfony\Component\Serializer\Annotation as Serializer;
|
||||
|
||||
/**
|
||||
* @ORM\Entity()
|
||||
* @ORM\Table(name="chill_person_relationships")
|
||||
* @DiscriminatorColumn(name="relation_id", type="integer")
|
||||
* @DiscriminatorMap(typeProperty="type", mapping={
|
||||
* "relationship"=Relationship::class
|
||||
* })
|
||||
*
|
||||
*/
|
||||
class Relationship
|
||||
class Relationship implements TrackCreationInterface, TrackUpdateInterface
|
||||
{
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue
|
||||
* @ORM\Column(type="integer")
|
||||
* @Groups({"read"})
|
||||
* @Serializer\Groups({"read"})
|
||||
*/
|
||||
private $id;
|
||||
private ?int $id = null;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity=Person::class)
|
||||
* @ORM\JoinColumn(nullable=false)
|
||||
* @Assert\NotBlank()
|
||||
* @Groups({"read", "write"})
|
||||
* @Assert\NotNull()
|
||||
* @Serializer\Groups({"read", "write"})
|
||||
*/
|
||||
private $fromPerson;
|
||||
private ?Person $fromPerson = null;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity=Person::class)
|
||||
* @ORM\JoinColumn(nullable=false)
|
||||
* @Assert\NotBlank()
|
||||
* @Groups({"read", "write"})
|
||||
* @Assert\NotNull()
|
||||
* @Serializer\Groups({"read", "write"})
|
||||
*/
|
||||
private $toPerson;
|
||||
private ?Person $toPerson = null;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity=Relation::class)
|
||||
* @ORM\JoinColumn(nullable=false, name="relation_id", referencedColumnName="id")
|
||||
* @Assert\NotBlank()
|
||||
* @Groups({"read", "write"})
|
||||
* @Assert\NotNull()
|
||||
* @Serializer\Groups({"read", "write"})
|
||||
*/
|
||||
private $relation;
|
||||
private ?Relation $relation = null;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="boolean")
|
||||
@ -53,30 +63,30 @@ class Relationship
|
||||
* type="bool",
|
||||
* message="This must be of type boolean"
|
||||
* )
|
||||
* @Groups({"read"})
|
||||
* @Serializer\Groups({"read", "write"})
|
||||
*/
|
||||
private $reverse;
|
||||
private bool $reverse;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity=User::class)
|
||||
* @ORM\JoinColumn(nullable=false)
|
||||
*/
|
||||
private $createdBy;
|
||||
private ?User $createdBy = null;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="datetime_immutable")
|
||||
*/
|
||||
private $createdAt;
|
||||
private ?DateTimeImmutable $createdAt = null;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity=User::class)
|
||||
*/
|
||||
private $updatedBy;
|
||||
private ?User $updatedBy = null;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="datetime_immutable", nullable=true)
|
||||
*/
|
||||
private $updatedAt;
|
||||
private ?DateTimeImmutable $updatedAt = null;
|
||||
|
||||
|
||||
public function getId(): ?int
|
||||
@ -125,9 +135,9 @@ class Relationship
|
||||
return $this->createdBy;
|
||||
}
|
||||
|
||||
public function setCreatedBy(?User $createdBy): self
|
||||
public function setCreatedBy(?User $user): self
|
||||
{
|
||||
$this->createdBy = $createdBy;
|
||||
$this->createdBy = $user;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@ -137,7 +147,7 @@ class Relationship
|
||||
return $this->createdAt;
|
||||
}
|
||||
|
||||
public function setCreatedAt(\DateTimeImmutable $createdAt): self
|
||||
public function setCreatedAt(\DateTimeInterface $createdAt): self
|
||||
{
|
||||
$this->createdAt = $createdAt;
|
||||
|
||||
@ -161,7 +171,7 @@ class Relationship
|
||||
return $this->updatedAt;
|
||||
}
|
||||
|
||||
public function setUpdatedAt(?\DateTimeImmutable $updatedAt): self
|
||||
public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
|
||||
{
|
||||
$this->updatedAt = $updatedAt;
|
||||
|
||||
@ -179,4 +189,4 @@ class Relationship
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
@ -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')
|
||||
|
@ -1,38 +0,0 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\Serializer\Normalizer;
|
||||
|
||||
use Chill\PersonBundle\Entity\Relationships\Relationship;
|
||||
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
||||
use Symfony\Component\Serializer\Normalizer\ObjectToPopulateTrait;
|
||||
|
||||
class RelationshipNormalizer implements NormalizerInterface, NormalizerAwareInterface
|
||||
{
|
||||
use NormalizerAwareTrait;
|
||||
|
||||
use ObjectToPopulateTrait;
|
||||
|
||||
use DenormalizerAwareTrait;
|
||||
|
||||
public function normalize($relationship, ?string $format = null, array $context = [])
|
||||
{
|
||||
return [
|
||||
'type' => '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;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\Migrations\Person;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* isActive property added to Relation entity.
|
||||
*/
|
||||
final class Version20211029075117 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'isActive property added to Relation entity.';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->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');
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user