Update Project and User entities
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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<int, Project>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user