From 85c4560f2226dfae7f5e8740efa270f492b92016 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Mon, 29 Mar 2021 17:03:12 +0200 Subject: [PATCH] Complete accompanying period entity --- .../Entity/AccompanyingPeriod.php | 249 ++++++++++++++---- .../migrations/Version20210329144338.php | 74 ++++++ 2 files changed, 275 insertions(+), 48 deletions(-) create mode 100644 src/Bundle/ChillPersonBundle/migrations/Version20210329144338.php diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php index 9761aa48d..700abda88 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php @@ -22,7 +22,10 @@ namespace Chill\PersonBundle\Entity; +use Chill\MainBundle\Entity\Scope; +use Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive; use Chill\PersonBundle\Entity\AccompanyingPeriod\Origin; +use Chill\ThirdPartyBundle\Entity\ThirdParty; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; @@ -37,6 +40,11 @@ use Chill\MainBundle\Entity\User; */ class AccompanyingPeriod { + const INTENSITY = [ + 'occasional' => 'ponctuel', + 'regular' => 'régulier' + ]; + /** * @var integer * @@ -69,7 +77,6 @@ class AccompanyingPeriod /** * @var Collection - * * @ORM\ManyToMany( * targetEntity="Chill\PersonBundle\Entity\Person", * mappedBy="accompanyingPeriods") @@ -86,23 +93,79 @@ class AccompanyingPeriod private $closingMotive = null; /** - * The user making the accompanying - * @var User - * - * @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\User") + * @ORM\ManyToOne(targetEntity=User::class) * @ORM\JoinColumn(nullable=true) */ private $user; /** - * @var Origin - * - * @ORM\ManyToOne( - * targetEntity="Chill\PersonBundle\Entity\AccompanyingPeriod\Origin") + * @ORM\ManyToOne(targetEntity=User::class) + * @ORM\JoinColumn(nullable=true) + */ + private $createdBy; + + /** + * @var string + * @ORM\Column(type="string", length=32, nullable=true) + */ + private $step = 'DRAFT'; + + /** + * @ORM\ManyToOne(targetEntity=Origin::class) * @ORM\JoinColumn(nullable=true) */ private $origin; + /** + * @var string + * @ORM\Column(type="string", nullable=true) + */ + private $intensity; + + /** + * @var Collection + * @ORM\ManyToMany( + * targetEntity=Scope::class, + * cascade={} + * ) + * @ORM\JoinTable( + * name="accompanying_periods_scopes", + * joinColumns={@ORM\JoinColumn(name="accompanying_period_id", referencedColumnName="id")}, + * inverseJoinColumns={@ORM\JoinColumn(name="scope_id", referencedColumnName="id")} + * ) + */ + private $scopes; + + /** + * @ORM\ManyToOne(targetEntity=Person::class) + * @ORM\JoinColumn(nullable=true) + */ + private $requestorPerson; + + /** + * @ORM\ManyToOne(targetEntity=ThirdParty::class) + * @ORM\JoinColumn(nullable=true) + */ + private $requestorThirdParty; + + /** + * @var bool + * @ORM\Column(type="boolean") + */ + private $requestorAnonymous = false; + + /** + * @var bool + * @ORM\Column(type="boolean") + */ + private $emergency = false; + + /** + * @var bool + * @ORM\Column(type="boolean") + */ + private $confidential = false; + /** * AccompanyingPeriod constructor. @@ -113,6 +176,7 @@ class AccompanyingPeriod public function __construct(\DateTime $dateOpening) { $this->setOpeningDate($dateOpening); $this->persons = new ArrayCollection(); + $this->scopes = new ArrayCollection(); } /** @@ -217,71 +281,45 @@ class AccompanyingPeriod return $this->remark; } - /** - * Set persons - */ - public function setPersons($persons): AccompanyingPeriod - { - $this->persons = $persons; - - return $this; - } - - /** - * Get Persons - */ public function getPersons(): Collection { return $this->persons; } - /** - * Return true if a given Person is associated - */ public function containsPerson(Person $person): bool { foreach ($this->persons as $p) { if ($p === $person) { return true; } } + return false; } /** - * Add person. - * * For consistency, you should use Person::addAccompanyingPeriod instead. * @see Person::addAccompanyingPeriod */ - public function addPerson(Person $person = null): AccompanyingPeriod + public function addPerson(Person $person = null): self { $this->persons[] = $person; return $this; } - /** - * Remove person. - */ public function removePerson(Person $person): void { $this->persons->removeElement($person); } - /** - * @return AccompanyingPeriod\ClosingMotive - */ - public function getClosingMotive() + public function getClosingMotive(): ?ClosingMotive { return $this->closingMotive; } - /** - * @param AccompanyingPeriod\ClosingMotive|null $closingMotive - * @return $this - */ - public function setClosingMotive(AccompanyingPeriod\ClosingMotive $closingMotive = null) + public function setClosingMotive(ClosingMotive $closingMotive = null): self { $this->closingMotive = $closingMotive; + return $this; } @@ -347,18 +385,11 @@ class AccompanyingPeriod } } - /** - * @return User|null - */ function getUser(): ?User { return $this->user; } - /** - * @param User $user - * @return AccompanyingPeriod - */ function setUser(User $user): self { $this->user = $user; @@ -371,9 +402,131 @@ class AccompanyingPeriod return $this->origin; } - public function setOrigin($origin): AccompanyingPeriod + public function setOrigin(Origin $origin): self { $this->origin = $origin; + return $this; } + + public function getRequestorPerson(): ?Person + { + return $this->requestorPerson; + } + + public function setRequestorPerson(Person $requestorPerson): self + { + $this->requestorPerson = ($this->requestorThirdParty === null) ? $requestorPerson : null; + + return $this; + } + + public function getRequestorThirdParty(): ?ThirdParty + { + return $this->requestorThirdParty; + } + + public function setRequestorThirdParty(ThirdParty $requestorThirdParty): self + { + $this->requestorThirdParty = ($this->requestorPerson === null) ? $requestorThirdParty : null; + + return $this; + } + + /** + * @return Person|ThirdParty + */ + public function getRequestor() + { + return $this->requestorPerson ?? $this->requestorThirdParty; + } + + public function isRequestorAnonymous(): bool + { + return $this->requestorAnonymous; + } + + public function setRequestorAnonymous(bool $requestorAnonymous): self + { + $this->requestorAnonymous = $requestorAnonymous; + + return $this; + } + + public function isEmergency(): bool + { + return $this->emergency; + } + + public function setEmergency(bool $emergency): self + { + $this->emergency = $emergency; + + return $this; + } + + public function isConfidential(): bool + { + return $this->confidential; + } + + public function setConfidential(bool $confidential): self + { + $this->confidential = $confidential; + + return $this; + } + + public function getCreatedBy(): ?User + { + return $this->createdBy; + } + + public function setCreatedBy(User $createdBy): self + { + $this->createdBy = $createdBy; + + return $this; + } + + public function getStep(): string + { + return $this->step; + } + + public function setStep(string $step): self + { + $this->step = $step; + + return $this; + } + + public function getIntensity(): string + { + return $this->intensity; + } + + public function setIntensity(string $intensity): self + { + $this->intensity = $intensity; + + return $this; + } + + public function getScopes(): Collection + { + return $this->scopes; + } + + public function addScope(Scope $scope): self + { + $this->scopes[] = $scope; + + return $this; + } + + public function removeScope(Scope $scope): void + { + $this->scopes->removeElement($scope); + } } diff --git a/src/Bundle/ChillPersonBundle/migrations/Version20210329144338.php b/src/Bundle/ChillPersonBundle/migrations/Version20210329144338.php new file mode 100644 index 000000000..a0cdf39cd --- /dev/null +++ b/src/Bundle/ChillPersonBundle/migrations/Version20210329144338.php @@ -0,0 +1,74 @@ +addSql('CREATE TABLE accompanying_periods_scopes (accompanying_period_id INT NOT NULL, scope_id INT NOT NULL, PRIMARY KEY(accompanying_period_id, scope_id))'); + + $this->addSql('CREATE INDEX IDX_87C4EAB032A7A428 ON accompanying_periods_scopes (accompanying_period_id)'); + $this->addSql('CREATE INDEX IDX_87C4EAB0682B5931 ON accompanying_periods_scopes (scope_id)'); + + $this->addSql('ALTER TABLE accompanying_periods_scopes ADD CONSTRAINT FK_87C4EAB032A7A428 FOREIGN KEY (accompanying_period_id) REFERENCES chill_person_accompanying_period (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE accompanying_periods_scopes ADD CONSTRAINT FK_87C4EAB0682B5931 FOREIGN KEY (scope_id) REFERENCES scopes (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + + $this->addSql('ALTER TABLE chill_person_accompanying_period ADD step VARCHAR(32) DEFAULT NULL'); + $this->addSql('ALTER TABLE chill_person_accompanying_period ADD intensity VARCHAR(255) DEFAULT NULL'); + $this->addSql('ALTER TABLE chill_person_accompanying_period ADD createdBy_id INT DEFAULT NULL'); + $this->addSql('ALTER TABLE chill_person_accompanying_period ADD requestorPerson_id INT DEFAULT NULL'); + $this->addSql('ALTER TABLE chill_person_accompanying_period ADD requestorThirdParty_id INT DEFAULT NULL'); + $this->addSql('ALTER TABLE chill_person_accompanying_period ADD requestorAnonymous BOOLEAN NOT NULL DEFAULT FALSE'); + $this->addSql('ALTER TABLE chill_person_accompanying_period ADD emergency BOOLEAN NOT NULL DEFAULT FALSE'); + $this->addSql('ALTER TABLE chill_person_accompanying_period ADD confidential BOOLEAN NOT NULL DEFAULT FALSE'); + + $this->addSql('ALTER TABLE chill_person_accompanying_period ADD CONSTRAINT FK_E260A8683174800F FOREIGN KEY (createdBy_id) REFERENCES users (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE chill_person_accompanying_period ADD CONSTRAINT FK_E260A86834269C3F FOREIGN KEY (requestorPerson_id) REFERENCES chill_person_person (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE chill_person_accompanying_period ADD CONSTRAINT FK_E260A868CFE4D554 FOREIGN KEY (requestorThirdParty_id) REFERENCES chill_3party.third_party (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + + $this->addSql('CREATE INDEX IDX_E260A8683174800F ON chill_person_accompanying_period (createdBy_id)'); + $this->addSql('CREATE INDEX IDX_E260A86834269C3F ON chill_person_accompanying_period (requestorPerson_id)'); + $this->addSql('CREATE INDEX IDX_E260A868CFE4D554 ON chill_person_accompanying_period (requestorThirdParty_id)'); + + } + + public function down(Schema $schema) : void + { + + $this->addSql('DROP TABLE accompanying_periods_scopes'); + + $this->addSql('ALTER TABLE chill_person_accompanying_period DROP CONSTRAINT FK_E260A8683174800F'); + $this->addSql('ALTER TABLE chill_person_accompanying_period DROP CONSTRAINT FK_E260A86834269C3F'); + $this->addSql('ALTER TABLE chill_person_accompanying_period DROP CONSTRAINT FK_E260A868CFE4D554'); + + $this->addSql('DROP INDEX IDX_E260A8683174800F'); + $this->addSql('DROP INDEX IDX_E260A86834269C3F'); + $this->addSql('DROP INDEX IDX_E260A868CFE4D554'); + + $this->addSql('ALTER TABLE chill_person_accompanying_period DROP step'); + $this->addSql('ALTER TABLE chill_person_accompanying_period DROP intensity'); + $this->addSql('ALTER TABLE chill_person_accompanying_period DROP createdBy_id'); + $this->addSql('ALTER TABLE chill_person_accompanying_period DROP requestorPerson_id'); + $this->addSql('ALTER TABLE chill_person_accompanying_period DROP requestorThirdParty_id'); + $this->addSql('ALTER TABLE chill_person_accompanying_period DROP requestorAnonymous'); + $this->addSql('ALTER TABLE chill_person_accompanying_period DROP emergency'); + $this->addSql('ALTER TABLE chill_person_accompanying_period DROP confidential'); + + } +}