From bdd5093a6a268055904738ef16a3bbe478648b4f Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Tue, 24 Sep 2024 11:07:33 +0200 Subject: [PATCH] refs #724. Added RemoteCalendar and RemoteCalendarRule entities --- migrations/Version20240924090429.php | 41 ++++++ src/Entity/OrganizationalUnit.php | 4 + src/Entity/RemoteCalendar.php | 72 ++++++++++ src/Entity/RemoteCalendarRule.php | 131 ++++++++++++++++++ src/Repository/RemoteCalendarRepository.php | 43 ++++++ .../RemoteCalendarRuleRepository.php | 43 ++++++ 6 files changed, 334 insertions(+) create mode 100644 migrations/Version20240924090429.php create mode 100644 src/Entity/RemoteCalendar.php create mode 100644 src/Entity/RemoteCalendarRule.php create mode 100644 src/Repository/RemoteCalendarRepository.php create mode 100644 src/Repository/RemoteCalendarRuleRepository.php diff --git a/migrations/Version20240924090429.php b/migrations/Version20240924090429.php new file mode 100644 index 0000000..ba9563c --- /dev/null +++ b/migrations/Version20240924090429.php @@ -0,0 +1,41 @@ +addSql('CREATE TABLE remote_calendar (id INT AUTO_INCREMENT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, name VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_BD3BDE0AD17F50A6 (uuid), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE remote_calendar_rule (id INT AUTO_INCREMENT NOT NULL, remote_calendar_id INT DEFAULT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, busy_weekdays JSON NOT NULL COMMENT \'(DC2Type:json)\', busy_from_hour DATETIME NOT NULL, busy_to_hour DATETIME NOT NULL, is_remote_available TINYINT(1) NOT NULL, available_from_date DATE NOT NULL, available_to_date DATE NOT NULL, available_reason VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_EE93D058D17F50A6 (uuid), INDEX IDX_EE93D058C56641EE (remote_calendar_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('ALTER TABLE remote_calendar_rule ADD CONSTRAINT FK_EE93D058C56641EE FOREIGN KEY (remote_calendar_id) REFERENCES remote_calendar (id)'); + $this->addSql('ALTER TABLE organizational_unit ADD remote_calendar_id INT DEFAULT NULL'); + $this->addSql('ALTER TABLE organizational_unit ADD CONSTRAINT FK_749AEB2DC56641EE FOREIGN KEY (remote_calendar_id) REFERENCES remote_calendar (id)'); + $this->addSql('CREATE INDEX IDX_749AEB2DC56641EE ON organizational_unit (remote_calendar_id)'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE organizational_unit DROP FOREIGN KEY FK_749AEB2DC56641EE'); + $this->addSql('ALTER TABLE remote_calendar_rule DROP FOREIGN KEY FK_EE93D058C56641EE'); + $this->addSql('DROP TABLE remote_calendar'); + $this->addSql('DROP TABLE remote_calendar_rule'); + $this->addSql('DROP INDEX IDX_749AEB2DC56641EE ON organizational_unit'); + $this->addSql('ALTER TABLE organizational_unit DROP remote_calendar_id'); + } +} diff --git a/src/Entity/OrganizationalUnit.php b/src/Entity/OrganizationalUnit.php index 469a9f5..11cfa89 100644 --- a/src/Entity/OrganizationalUnit.php +++ b/src/Entity/OrganizationalUnit.php @@ -84,6 +84,10 @@ class OrganizationalUnit extends AbstractEntity #[ORM\OneToMany(mappedBy: 'organizationalUnit', targetEntity: SoftwareProfile::class)] private Collection $softwareProfiles; + #[ORM\ManyToOne(targetEntity: RemoteCalendar::class, inversedBy: 'organizationalUnits', cascade: ['persist'])] + #[ORM\JoinColumn(nullable: true)] + private ?RemoteCalendar $remoteCalendar = null; + public function __construct() { parent::__construct(); diff --git a/src/Entity/RemoteCalendar.php b/src/Entity/RemoteCalendar.php new file mode 100644 index 0000000..d15e499 --- /dev/null +++ b/src/Entity/RemoteCalendar.php @@ -0,0 +1,72 @@ + + */ + #[ORM\OneToMany(mappedBy: 'remoteCalendar', targetEntity: OrganizationalUnit::class)] + private Collection $organizationalUnits; + + /** + * @var Collection + */ + #[ORM\OneToMany(mappedBy: 'remoteCalendar', targetEntity: RemoteCalendarRule::class)] + private Collection $rules; + + public function __construct() + { + parent::__construct(); + $this->rules = new ArrayCollection(); + } + + public function getOrganizationalUnits(): Collection + { + return $this->organizationalUnits; + } + + public function setOrganizationalUnits(Collection $organizationalUnits): void + { + $this->organizationalUnits = $organizationalUnits; + } + + /** + * @return Collection + */ + public function getRules(): Collection + { + return $this->rules; + } + + public function addRule(RemoteCalendarRule $rule): static + { + if (!$this->rules->contains($rule)) { + $this->rules->add($rule); + $rule->setRemoteCalendar($this); + } + + return $this; + } + + public function removeRule(RemoteCalendarRule $rule): static + { + if ($this->rules->removeElement($rule)) { + // set the owning side to null (unless already changed) + if ($rule->getRemoteCalendar() === $this) { + $rule->setRemoteCalendar(null); + } + } + + return $this; + } +} diff --git a/src/Entity/RemoteCalendarRule.php b/src/Entity/RemoteCalendarRule.php new file mode 100644 index 0000000..92c4b1b --- /dev/null +++ b/src/Entity/RemoteCalendarRule.php @@ -0,0 +1,131 @@ +busyWeekdays; + } + + public function setBusyWeekdays(array $busyWeekdays): static + { + $this->busyWeekdays = $busyWeekdays; + + return $this; + } + + public function getBusyFromHour(): ?\DateTimeInterface + { + return $this->busyFromHour; + } + + public function setBusyFromHour(\DateTimeInterface $busyFromHour): static + { + $this->busyFromHour = $busyFromHour; + + return $this; + } + + public function getBusyToHour(): ?\DateTimeInterface + { + return $this->busyToHour; + } + + public function setBusyToHour(\DateTimeInterface $busyToHour): static + { + $this->busyToHour = $busyToHour; + + return $this; + } + + public function isRemoteAvailable(): ?bool + { + return $this->isRemoteAvailable; + } + + public function setRemoteAvailable(bool $isRemoteAvailable): static + { + $this->isRemoteAvailable = $isRemoteAvailable; + + return $this; + } + + public function getAvailableFromDate(): ?\DateTimeInterface + { + return $this->availableFromDate; + } + + public function setAvailableFromDate(\DateTimeInterface $availableFromDate): static + { + $this->availableFromDate = $availableFromDate; + + return $this; + } + + public function getAvailableToDate(): ?\DateTimeInterface + { + return $this->availableToDate; + } + + public function setAvailableToDate(\DateTimeInterface $availableToDate): static + { + $this->availableToDate = $availableToDate; + + return $this; + } + + public function getAvailableReason(): ?string + { + return $this->availableReason; + } + + public function setAvailableReason(string $availableReason): static + { + $this->availableReason = $availableReason; + + return $this; + } + + public function getRemoteCalendar(): ?RemoteCalendar + { + return $this->remoteCalendar; + } + + public function setRemoteCalendar(?RemoteCalendar $remoteCalendar): static + { + $this->remoteCalendar = $remoteCalendar; + + return $this; + } +} diff --git a/src/Repository/RemoteCalendarRepository.php b/src/Repository/RemoteCalendarRepository.php new file mode 100644 index 0000000..331c150 --- /dev/null +++ b/src/Repository/RemoteCalendarRepository.php @@ -0,0 +1,43 @@ + + */ +class RemoteCalendarRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, RemoteCalendar::class); + } + +// /** +// * @return RemoteCalendar[] Returns an array of RemoteCalendar objects +// */ +// public function findByExampleField($value): array +// { +// return $this->createQueryBuilder('r') +// ->andWhere('r.exampleField = :val') +// ->setParameter('val', $value) +// ->orderBy('r.id', 'ASC') +// ->setMaxResults(10) +// ->getQuery() +// ->getResult() +// ; +// } + +// public function findOneBySomeField($value): ?RemoteCalendar +// { +// return $this->createQueryBuilder('r') +// ->andWhere('r.exampleField = :val') +// ->setParameter('val', $value) +// ->getQuery() +// ->getOneOrNullResult() +// ; +// } +} diff --git a/src/Repository/RemoteCalendarRuleRepository.php b/src/Repository/RemoteCalendarRuleRepository.php new file mode 100644 index 0000000..1af754c --- /dev/null +++ b/src/Repository/RemoteCalendarRuleRepository.php @@ -0,0 +1,43 @@ + + */ +class RemoteCalendarRuleRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, RemoteCalendarRule::class); + } + +// /** +// * @return RemoteCalendarRule[] Returns an array of RemoteCalendarRule objects +// */ +// public function findByExampleField($value): array +// { +// return $this->createQueryBuilder('r') +// ->andWhere('r.exampleField = :val') +// ->setParameter('val', $value) +// ->orderBy('r.id', 'ASC') +// ->setMaxResults(10) +// ->getQuery() +// ->getResult() +// ; +// } + +// public function findOneBySomeField($value): ?RemoteCalendarRule +// { +// return $this->createQueryBuilder('r') +// ->andWhere('r.exampleField = :val') +// ->setParameter('val', $value) +// ->getQuery() +// ->getOneOrNullResult() +// ; +// } +}