<?php
namespace App\Entity;
use App\Repository\CardRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=CardRepository::class)
*/
class Card
{
/**
* @ORM\Id
*
* @ORM\GeneratedValue
*
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\OneToOne(targetEntity=User::class, inversedBy="card", cascade={"persist", "remove"})
*
* @ORM\JoinColumn(nullable=false)
*/
private $user;
/**
* @ORM\OneToMany(targetEntity=CardItem::class, mappedBy="card" ,cascade={"persist", "remove"})
*/
private $items;
public function __construct()
{
$this->items = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(User $user): self
{
$this->user = $user;
return $this;
}
/**
* @return Collection|CardItem[]
*/
public function getItems(): Collection
{
return $this->items;
}
public function addItem(CardItem $item): self
{
if (!$this->items->contains($item)) {
$this->items[] = $item;
$item->setCard($this);
}
return $this;
}
public function removeItem(CardItem $item): self
{
if ($this->items->removeElement($item)) {
// set the owning side to null (unless already changed)
if ($item->getCard() === $this) {
$item->setCard(null);
}
}
return $this;
}
}