Implement basic wishlist
This commit is contained in:
parent
d80d667e0d
commit
f2dd4da50b
9 changed files with 315 additions and 0 deletions
|
@ -54,9 +54,15 @@ class User implements UserInterface
|
|||
*/
|
||||
private $offerings;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity=Wish::class, mappedBy="byUser")
|
||||
*/
|
||||
private $wishes;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->offerings = new ArrayCollection();
|
||||
$this->wishes = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
|
@ -193,4 +199,34 @@ class User implements UserInterface
|
|||
{
|
||||
return (string) $this->getUsername();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection|Wish[]
|
||||
*/
|
||||
public function getWishes(): Collection
|
||||
{
|
||||
return $this->wishes;
|
||||
}
|
||||
|
||||
public function addWish(Wish $wish): self
|
||||
{
|
||||
if (!$this->wishes->contains($wish)) {
|
||||
$this->wishes[] = $wish;
|
||||
$wish->setByUser($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeWish(Wish $wish): self
|
||||
{
|
||||
if ($this->wishes->removeElement($wish)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($wish->getByUser() === $this) {
|
||||
$wish->setByUser(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue