src/Entity/Card.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CardRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Entity(repositoryClass=CardRepository::class)
  9.  */
  10. class Card
  11. {
  12.     /**
  13.      * @ORM\Id
  14.      *
  15.      * @ORM\GeneratedValue
  16.      *
  17.      * @ORM\Column(type="integer")
  18.      */
  19.     private $id;
  20.     /**
  21.      * @ORM\OneToOne(targetEntity=User::class, inversedBy="card", cascade={"persist", "remove"})
  22.      *
  23.      * @ORM\JoinColumn(nullable=false)
  24.      */
  25.     private $user;
  26.     /**
  27.      * @ORM\OneToMany(targetEntity=CardItem::class, mappedBy="card" ,cascade={"persist", "remove"})
  28.      */
  29.     private $items;
  30.     public function __construct()
  31.     {
  32.         $this->items = new ArrayCollection();
  33.     }
  34.     public function getId(): ?int
  35.     {
  36.         return $this->id;
  37.     }
  38.     public function getUser(): ?User
  39.     {
  40.         return $this->user;
  41.     }
  42.     public function setUser(User $user): self
  43.     {
  44.         $this->user $user;
  45.         return $this;
  46.     }
  47.     /**
  48.      * @return Collection|CardItem[]
  49.      */
  50.     public function getItems(): Collection
  51.     {
  52.         return $this->items;
  53.     }
  54.     public function addItem(CardItem $item): self
  55.     {
  56.         if (!$this->items->contains($item)) {
  57.             $this->items[] = $item;
  58.             $item->setCard($this);
  59.         }
  60.         return $this;
  61.     }
  62.     public function removeItem(CardItem $item): self
  63.     {
  64.         if ($this->items->removeElement($item)) {
  65.             // set the owning side to null (unless already changed)
  66.             if ($item->getCard() === $this) {
  67.                 $item->setCard(null);
  68.             }
  69.         }
  70.         return $this;
  71.     }
  72. }