diff --git a/src/Bundle/ChillActivityBundle/Entity/Activity.php b/src/Bundle/ChillActivityBundle/Entity/Activity.php index e1341787f..6c4c03181 100644 --- a/src/Bundle/ChillActivityBundle/Entity/Activity.php +++ b/src/Bundle/ChillActivityBundle/Entity/Activity.php @@ -48,6 +48,9 @@ use Chill\MainBundle\Validator\Constraints\Entity\UserCircleConsistency; */ class Activity implements HasCenterInterface, HasScopeInterface { + const SENTRECEIVED_SENT = 'sent'; + const SENTRECEIVED_RECEIVED = 'received'; + /** * @ORM\Id * @ORM\Column(name="id", type="integer") @@ -71,9 +74,14 @@ class Activity implements HasCenterInterface, HasScopeInterface private \DateTime $durationTime; /** - * @ORM\Column(type="boolean") + * @ORM\Column(type="time") */ - private bool $attendee; + private \DateTime $travelTime; + + /** + * @ORM\ManyToOne(targetEntity="Chill\ActivityBundle\Entity\ActivityPresence") + */ + private ActivityPresence $attendee; /** * @ORM\ManyToMany(targetEntity="Chill\ActivityBundle\Entity\ActivityReason") @@ -101,25 +109,35 @@ class Activity implements HasCenterInterface, HasScopeInterface private CommentEmbeddable $comment; /** - * @ORM\OneToMany(targetEntity="Chill\PersonBundle\Entity\Person", mappedBy="person") + * @ORM\ManyToMany(targetEntity="Chill\PersonBundle\Entity\Person") */ private ArrayCollection $persons; /** - * @ORM\OneToMany(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdParty", mappedBy="thirdParty") + * @ORM\ManyToMany(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdParty") */ private ArrayCollection $thirdParties; /** - * @ORM\OneToMany(targetEntity="Chill\DocStoreBundle\Entity\Document", mappedBy="document") + * @ORM\ManyToMany(targetEntity="Chill\DocStoreBundle\Entity\Document") */ private ArrayCollection $documents; /** - * @ORM\Column(type="boolean") + * @ORM\ManyToMany(targetEntity="Chill\MainBundle\Entity\User") + */ + private ArrayCollection $users; + + /** + * @ORM\Column(type="boolean", options={"default"=false}) */ private bool $emergency = false; + /** + * @ORM\Column(type="string", options={"default"=""}) + */ + private string $sentReceived = ''; + public function __construct() { $this->reasons = new ArrayCollection(); @@ -127,6 +145,7 @@ class Activity implements HasCenterInterface, HasScopeInterface $this->persons = new ArrayCollection(); $this->thirdParties = new ArrayCollection(); $this->documents = new ArrayCollection(); + $this->users = new ArrayCollection(); } /** @@ -191,20 +210,26 @@ class Activity implements HasCenterInterface, HasScopeInterface return $this->durationTime; } - /** - * Set attendee - */ - public function setAttendee(bool $attendee): self + public function setTravelTime(\DateTime $travelTime): self + { + $this->travelTime = $travelTime; + + return $this; + } + + public function getTravelTime(): \DateTime + { + return $this->travelTime; + } + + public function setAttendee(ActivityPresence $attendee): self { $this->attendee = $attendee; return $this; } - /** - * Get attendee - */ - public function getAttendee(): bool + public function getAttendee(): ActivityPresence { return $this->attendee; } @@ -382,6 +407,30 @@ class Activity implements HasCenterInterface, HasScopeInterface return $this; } + public function addUser(User $user): self + { + $this->users[] = $user; + + return $this; + } + + public function removeUser(User $user): void + { + $this->users->removeElement($user); + } + + public function getUsers(): ArrayCollection + { + return $this->users; + } + + public function setUsers(ArrayCollection $users): self + { + $this->users = $users; + + return $this; + } + public function isEmergency(): bool { return $this->getEmergency(); @@ -398,5 +447,17 @@ class Activity implements HasCenterInterface, HasScopeInterface return $this; } + + public function getSentReceived(): string + { + return $this->sentReceived; + } + + public function setSentReceived(string $sentReceived): self + { + $this->sentReceived = $sentReceived; + + return $this; + } } diff --git a/src/Bundle/ChillActivityBundle/Entity/ActivityPresence.php b/src/Bundle/ChillActivityBundle/Entity/ActivityPresence.php index bfae78878..ed9757549 100644 --- a/src/Bundle/ChillActivityBundle/Entity/ActivityPresence.php +++ b/src/Bundle/ChillActivityBundle/Entity/ActivityPresence.php @@ -49,17 +49,11 @@ class ActivityPresence */ private bool $active = true; - /** - * Get id - */ public function getId(): int { return $this->id; } - /** - * Set name - */ public function setName(array $name): self { $this->name = $name; diff --git a/src/Bundle/ChillActivityBundle/Entity/ActivityType.php b/src/Bundle/ChillActivityBundle/Entity/ActivityType.php index 1d02f09a0..fe5e87dec 100644 --- a/src/Bundle/ChillActivityBundle/Entity/ActivityType.php +++ b/src/Bundle/ChillActivityBundle/Entity/ActivityType.php @@ -128,6 +128,16 @@ class ActivityType */ private string $durationTimeLabel = ''; + /** + * @ORM\Column(type="smallint", nullable=false, options={"default"=1}) + */ + private int $travelTimeVisible = self::FIELD_OPTIONAL; + + /** + * @ORM\Column(type="string", nullable=false, options={"default"=""}) + */ + private string $travelTimeLabel = ''; + /** * @ORM\Column(type="smallint", nullable=false, options={"default"=1}) */ @@ -178,6 +188,16 @@ class ActivityType */ private string $documentsLabel = ''; + /** + * @ORM\Column(type="smallint", nullable=false, options={"default"=1}) + */ + private int $usersVisible = self::FIELD_OPTIONAL; + + /** + * @ORM\Column(type="string", nullable=false, options={"default"=""}) + */ + private string $usersLabel = ''; + /** * @ORM\Column(type="smallint", nullable=false, options={"default"=1}) */ @@ -413,6 +433,26 @@ class ActivityType $this->durationTimeLabel = $durationTimeLabel; } + public function getTravelTimeVisible(): int + { + return $this->travelTimeVisible; + } + + public function setTravelTimeVisible(int $TravelTimeVisible): void + { + $this->travelTimeVisible = $TravelTimeVisible; + } + + public function getTravelTimeLabel(): string + { + return $this->travelTimeLabel; + } + + public function setTravelTimeLabel(string $TravelTimeLabel): void + { + $this->travelTimeLabel = $TravelTimeLabel; + } + public function getAttendeeVisible(): int { return $this->attendeeVisible; @@ -513,6 +553,26 @@ class ActivityType $this->documentsLabel = $documentsLabel; } + public function getUsersVisible(): int + { + return $this->usersVisible; + } + + public function setUsersVisible(int $usersVisible): void + { + $this->usersVisible = $usersVisible; + } + + public function getUsersLabel(): string + { + return $this->usersLabel; + } + + public function setUsersLabel(string $usersLabel): void + { + $this->usersLabel = $usersLabel; + } + public function getEmergencyVisible(): int { return $this->emergencyVisible; diff --git a/src/Bundle/ChillActivityBundle/Form/ActivityTypeType.php b/src/Bundle/ChillActivityBundle/Form/ActivityTypeType.php index 028cbc307..96e50f690 100644 --- a/src/Bundle/ChillActivityBundle/Form/ActivityTypeType.php +++ b/src/Bundle/ChillActivityBundle/Form/ActivityTypeType.php @@ -43,7 +43,7 @@ class ActivityTypeType extends AbstractType $fields = [ 'persons', 'user', 'date', 'place', 'persons', - 'thirdParties', 'durationTime', 'attendee', + 'thirdParties', 'durationTime', 'travelTime', 'attendee', 'reasons', 'comment', 'sentReceived', 'documents', 'emergency', 'accompanyingPeriod', 'socialData' ]; diff --git a/src/Bundle/ChillActivityBundle/migrations/Version20210422073711.php b/src/Bundle/ChillActivityBundle/migrations/Version20210422073711.php new file mode 100644 index 000000000..8d5dcfa84 --- /dev/null +++ b/src/Bundle/ChillActivityBundle/migrations/Version20210422073711.php @@ -0,0 +1,52 @@ +addSql('CREATE SEQUENCE activitytpresence_id_seq INCREMENT BY 1 MINVALUE 1 START 6'); + $this->addSql('CREATE TABLE activitytpresence (id INT NOT NULL, name JSON NOT NULL, active BOOLEAN NOT NULL, PRIMARY KEY(id))'); + + $list = [ + 'Usager pésent', "Absence de l''usager", + "Refus de visite ou d''entretien", 'Domicile non trouvé', + 'Domicile erronéee' + ]; + for ($i = 1; $i <= count($list); $i++) { + $this->addSql("INSERT INTO activitytpresence VALUES(".$i.", json_build_object('fr', '".$list[$i-1]."'), true)"); + } + + $this->addSql('ALTER TABLE activity ADD emergency BOOLEAN NOT NULL DEFAULT false'); + $this->addSql('ALTER TABLE activity ADD sentReceived VARCHAR(255) NOT NULL DEFAULT \'\' '); + $this->addSql('ALTER TABLE activity ALTER attendee TYPE INT USING CASE WHEN attendee is false THEN 2 WHEN attendee is true THEN 1 ELSE null END'); + $this->addSql('ALTER TABLE activity RENAME COLUMN attendee TO attendee_id'); + $this->addSql('ALTER TABLE activity ADD CONSTRAINT FK_AC74095ABCFD782A FOREIGN KEY (attendee_id) REFERENCES activitytpresence (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + } + + public function down(Schema $schema) : void + { + $this->addSql('ALTER TABLE activity DROP emergency'); + $this->addSql('ALTER TABLE activity DROP CONSTRAINT FK_AC74095ABCFD782A'); + $this->addSql('ALTER TABLE activity ADD attendee BOOLEAN DEFAULT NULL'); + $this->addSql('ALTER TABLE activity DROP attendee_id'); + $this->addSql('ALTER TABLE activity DROP sentReceived'); + + $this->addSql('DROP SEQUENCE activitytpresence_id_seq CASCADE'); + $this->addSql('DROP TABLE activitytpresence'); + } +} diff --git a/src/Bundle/ChillActivityBundle/migrations/Version20210422123846.php b/src/Bundle/ChillActivityBundle/migrations/Version20210422123846.php new file mode 100644 index 000000000..a4b1c8f65 --- /dev/null +++ b/src/Bundle/ChillActivityBundle/migrations/Version20210422123846.php @@ -0,0 +1,65 @@ +addSql('CREATE TABLE activity_person (activity_id INT NOT NULL, person_id INT NOT NULL, PRIMARY KEY(activity_id, person_id))'); + $this->addSql('CREATE INDEX IDX_66AA317681C06096 ON activity_person (activity_id)'); + $this->addSql('CREATE INDEX IDX_66AA3176217BBB47 ON activity_person (person_id)'); + $this->addSql('CREATE TABLE activity_thirdparty (activity_id INT NOT NULL, thirdparty_id INT NOT NULL, PRIMARY KEY(activity_id, thirdparty_id))'); + $this->addSql('CREATE INDEX IDX_C6F0DE0381C06096 ON activity_thirdparty (activity_id)'); + $this->addSql('CREATE INDEX IDX_C6F0DE03C7D3A8E6 ON activity_thirdparty (thirdparty_id)'); + $this->addSql('CREATE TABLE activity_document (activity_id INT NOT NULL, document_id INT NOT NULL, PRIMARY KEY(activity_id, document_id))'); + $this->addSql('CREATE INDEX IDX_78633A7881C06096 ON activity_document (activity_id)'); + $this->addSql('CREATE INDEX IDX_78633A78C33F7837 ON activity_document (document_id)'); + $this->addSql('CREATE TABLE activity_user (activity_id INT NOT NULL, user_id INT NOT NULL, PRIMARY KEY(activity_id, user_id))'); + $this->addSql('CREATE INDEX IDX_8E570DDB81C06096 ON activity_user (activity_id)'); + $this->addSql('CREATE INDEX IDX_8E570DDBA76ED395 ON activity_user (user_id)'); + $this->addSql('ALTER TABLE activity_person ADD CONSTRAINT FK_66AA317681C06096 FOREIGN KEY (activity_id) REFERENCES activity (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE activity_person ADD CONSTRAINT FK_66AA3176217BBB47 FOREIGN KEY (person_id) REFERENCES chill_person_person (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE activity_thirdparty ADD CONSTRAINT FK_C6F0DE0381C06096 FOREIGN KEY (activity_id) REFERENCES activity (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE activity_thirdparty ADD CONSTRAINT FK_C6F0DE03C7D3A8E6 FOREIGN KEY (thirdparty_id) REFERENCES chill_3party.third_party (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE activity_document ADD CONSTRAINT FK_78633A7881C06096 FOREIGN KEY (activity_id) REFERENCES activity (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE activity_document ADD CONSTRAINT FK_78633A78C33F7837 FOREIGN KEY (document_id) REFERENCES Document (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE activity_user ADD CONSTRAINT FK_8E570DDB81C06096 FOREIGN KEY (activity_id) REFERENCES activity (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE activity_user ADD CONSTRAINT FK_8E570DDBA76ED395 FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); + + $this->addSql('ALTER TABLE activity ADD travelTime TIME(0) WITHOUT TIME ZONE NOT NULL'); + + $this->addSql('ALTER TABLE activitytype ADD travelTimeVisible SMALLINT DEFAULT 1 NOT NULL'); + $this->addSql('ALTER TABLE activitytype ADD travelTimeLabel VARCHAR(255) DEFAULT \'\' NOT NULL'); + $this->addSql('ALTER TABLE activitytype ADD usersVisible SMALLINT DEFAULT 1 NOT NULL'); + $this->addSql('ALTER TABLE activitytype ADD usersLabel VARCHAR(255) DEFAULT \'\' NOT NULL'); + } + + public function down(Schema $schema) : void + { + $this->addSql('DROP TABLE activity_person'); + $this->addSql('DROP TABLE activity_thirdparty'); + $this->addSql('DROP TABLE activity_document'); + $this->addSql('DROP TABLE activity_user'); + + $this->addSql('ALTER TABLE activity DROP travelTime'); + + $this->addSql('ALTER TABLE activitytype DROP travelTimeVisible'); + $this->addSql('ALTER TABLE activitytype DROP travelTimeLabel'); + $this->addSql('ALTER TABLE activitytype DROP usersVisible'); + $this->addSql('ALTER TABLE activitytype DROP usersLabel'); + } +}