From 52dc878e140de8bbdbb348bc97b45b3aa76c4838 Mon Sep 17 00:00:00 2001 From: Daniel Subiabre Date: Mon, 25 Mar 2024 08:47:20 +0100 Subject: [PATCH] Update Project and User entities --- src/Entity/Project.php | 57 ++++++++++++++++++++++++++++++++++++++++++ src/Entity/User.php | 34 +++++++++++++++++++++++++ 2 files changed, 91 insertions(+) diff --git a/src/Entity/Project.php b/src/Entity/Project.php index b0faef1..89930af 100644 --- a/src/Entity/Project.php +++ b/src/Entity/Project.php @@ -34,8 +34,28 @@ class Project #[ORM\JoinColumn(nullable: false)] private ?Accounting $accounting = null; + #[ORM\ManyToOne(inversedBy: 'projects')] + #[ORM\JoinColumn(nullable: false)] + private ?User $owner = null; + + /** + * Project was migrated from Goteo v3 platform. + */ + #[API\ApiProperty(writable: false)] + #[ORM\Column] + private ?bool $migrated = null; + + /** + * The previous id of this Project in the Goteo v3 platform. + */ + #[API\ApiProperty(writable: false)] + #[ORM\Column(length: 255, nullable: true)] + private ?string $migratedReference = null; + public function __construct() { + $this->migrated = false; + $this->accounting = new Accounting(); $this->accounting->setOwnerClass(Project::class); } @@ -65,6 +85,43 @@ class Project public function setAccounting(Accounting $accounting): static { $this->accounting = $accounting; + $this->accounting->setOwnerClass(self::class); + + return $this; + } + + public function getOwner(): ?User + { + return $this->owner; + } + + public function setOwner(?User $owner): static + { + $this->owner = $owner; + + return $this; + } + + public function isMigrated(): ?bool + { + return $this->migrated; + } + + public function setMigrated(bool $migrated): static + { + $this->migrated = $migrated; + + return $this; + } + + public function getMigratedReference(): ?string + { + return $this->migratedReference; + } + + public function setMigratedReference(?string $migratedReference): static + { + $this->migratedReference = $migratedReference; return $this; } diff --git a/src/Entity/User.php b/src/Entity/User.php index 11dba7f..459dc89 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -110,6 +110,9 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface #[ORM\Column(length: 255, nullable: true)] private ?string $migratedReference = null; + #[ORM\OneToMany(mappedBy: 'owner', targetEntity: Project::class)] + private Collection $projects; + public function __construct() { $this->migrated = false; @@ -118,6 +121,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface $this->accounting->setOwnerClass(User::class); $this->tokens = new ArrayCollection(); + $this->projects = new ArrayCollection(); } public function getId(): ?int @@ -343,4 +347,34 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface return $this; } + + /** + * @return Collection + */ + public function getProjects(): Collection + { + return $this->projects; + } + + public function addProject(Project $project): static + { + if (!$this->projects->contains($project)) { + $this->projects->add($project); + $project->setOwner($this); + } + + return $this; + } + + public function removeProject(Project $project): static + { + if ($this->projects->removeElement($project)) { + // set the owning side to null (unless already changed) + if ($project->getOwner() === $this) { + $project->setOwner(null); + } + } + + return $this; + } }