Implement basic wishlist

This commit is contained in:
Jannis Portmann 2021-05-04 11:52:20 +02:00
parent d80d667e0d
commit f2dd4da50b
9 changed files with 315 additions and 0 deletions

View file

@ -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;
}
}

63
src/Entity/Wish.php Normal file
View file

@ -0,0 +1,63 @@
<?php
namespace App\Entity;
use App\Repository\WishRepository;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=WishRepository::class)
*/
class Wish
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $title;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="wishes")
*/
private $byUser;
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
public function getByUser(): ?User
{
return $this->byUser;
}
public function setByUser(?User $byUser): self
{
$this->byUser = $byUser;
return $this;
}
public function __toString(): string
{
return (string) $this->getTitle();
}
}