From ec0ea2def35e6996c0361bdf2fec70a303e8ab7f Mon Sep 17 00:00:00 2001 From: Daniel Subiabre Date: Tue, 7 Oct 2025 13:43:57 +0200 Subject: [PATCH] Add project collaboration entity --- migrations/Version20251007112311.php | 38 ++++++++ src/Entity/Project/Collaboration.php | 96 +++++++++++++++++++ src/Entity/Project/Project.php | 37 +++++++ .../Project/CollaborationRepository.php | 43 +++++++++ 4 files changed, 214 insertions(+) create mode 100644 migrations/Version20251007112311.php create mode 100644 src/Entity/Project/Collaboration.php create mode 100644 src/Repository/Project/CollaborationRepository.php diff --git a/migrations/Version20251007112311.php b/migrations/Version20251007112311.php new file mode 100644 index 0000000..84fb65d --- /dev/null +++ b/migrations/Version20251007112311.php @@ -0,0 +1,38 @@ +addSql(<<<'SQL' + CREATE TABLE project_collaboration (id INT AUTO_INCREMENT NOT NULL, project_id INT NOT NULL, title VARCHAR(255) NOT NULL, description LONGTEXT NOT NULL, is_fulfilled TINYINT(1) NOT NULL, locales JSON NOT NULL COMMENT '(DC2Type:json)', INDEX IDX_EAB7425166D1F9C (project_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB + SQL); + $this->addSql(<<<'SQL' + ALTER TABLE project_collaboration ADD CONSTRAINT FK_EAB7425166D1F9C FOREIGN KEY (project_id) REFERENCES project (id) + SQL); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql(<<<'SQL' + ALTER TABLE project_collaboration DROP FOREIGN KEY FK_EAB7425166D1F9C + SQL); + $this->addSql(<<<'SQL' + DROP TABLE project_collaboration + SQL); + } +} diff --git a/src/Entity/Project/Collaboration.php b/src/Entity/Project/Collaboration.php new file mode 100644 index 0000000..04a077e --- /dev/null +++ b/src/Entity/Project/Collaboration.php @@ -0,0 +1,96 @@ +id; + } + + public function getProject(): ?Project + { + return $this->project; + } + + public function setProject(?Project $project): static + { + $this->project = $project; + + return $this; + } + + public function getTitle(): ?string + { + return $this->title; + } + + public function setTitle(string $title): static + { + $this->title = $title; + + return $this; + } + + public function getDescription(): ?string + { + return $this->description; + } + + public function setDescription(string $description): static + { + $this->description = $description; + + return $this; + } + + public function isFulfilled(): ?bool + { + return $this->fulfilled; + } + + public function setFulfilled(bool $fulfilled): static + { + $this->fulfilled = $fulfilled; + + return $this; + } +} diff --git a/src/Entity/Project/Project.php b/src/Entity/Project/Project.php index cb8da5b..877e8f8 100644 --- a/src/Entity/Project/Project.php +++ b/src/Entity/Project/Project.php @@ -141,6 +141,12 @@ class Project implements UserOwnedInterface, AccountingOwnerInterface, Localized #[ORM\OneToMany(targetEntity: Support::class, mappedBy: 'project')] private Collection $supports; + /** + * @var Collection + */ + #[ORM\OneToMany(targetEntity: Collaboration::class, mappedBy: 'project')] + private Collection $collaborations; + public function __construct() { $this->accounting = Accounting::of($this); @@ -150,6 +156,7 @@ class Project implements UserOwnedInterface, AccountingOwnerInterface, Localized $this->updates = new ArrayCollection(); $this->supports = new ArrayCollection(); $this->categories = new ArrayCollection(); + $this->collaborations = new ArrayCollection(); } public function getId(): ?int @@ -475,4 +482,34 @@ class Project implements UserOwnedInterface, AccountingOwnerInterface, Localized return $this; } + + /** + * @return Collection + */ + public function getCollaborations(): Collection + { + return $this->collaborations; + } + + public function addCollaboration(Collaboration $collaboration): static + { + if (!$this->collaborations->contains($collaboration)) { + $this->collaborations->add($collaboration); + $collaboration->setProject($this); + } + + return $this; + } + + public function removeCollaboration(Collaboration $collaboration): static + { + if ($this->collaborations->removeElement($collaboration)) { + // set the owning side to null (unless already changed) + if ($collaboration->getProject() === $this) { + $collaboration->setProject(null); + } + } + + return $this; + } } diff --git a/src/Repository/Project/CollaborationRepository.php b/src/Repository/Project/CollaborationRepository.php new file mode 100644 index 0000000..b7f9a39 --- /dev/null +++ b/src/Repository/Project/CollaborationRepository.php @@ -0,0 +1,43 @@ + + */ +class CollaborationRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Collaboration::class); + } + + // /** + // * @return Collaboration[] Returns an array of Collaboration objects + // */ + // public function findByExampleField($value): array + // { + // return $this->createQueryBuilder('c') + // ->andWhere('c.exampleField = :val') + // ->setParameter('val', $value) + // ->orderBy('c.id', 'ASC') + // ->setMaxResults(10) + // ->getQuery() + // ->getResult() + // ; + // } + + // public function findOneBySomeField($value): ?Collaboration + // { + // return $this->createQueryBuilder('c') + // ->andWhere('c.exampleField = :val') + // ->setParameter('val', $value) + // ->getQuery() + // ->getOneOrNullResult() + // ; + // } +}