src/CasinoBundle/Entity/Team.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\CasinoBundle\Entity;
  3. use App\CmsBundle\Entity\IdTrait;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Doctrine\ORM\Mapping\OrderBy;
  8. /**
  9.  * @ORM\Entity(repositoryClass="App\CasinoBundle\Repository\TeamRepository")
  10.  * @ORM\HasLifecycleCallbacks()
  11.  */
  12. class Team
  13. {
  14.     use IdTrait,
  15.         NameTrait,
  16.         PriorityTrait;
  17.     /**
  18.      * @ORM\OneToMany(targetEntity="App\CasinoBundle\Entity\Author", mappedBy="team")
  19.      * @OrderBy({"priority" = "ASC"})
  20.      */
  21.     public $members;
  22.     public function __construct()
  23.     {
  24.         $this->members = new ArrayCollection();
  25.     }
  26.     /**
  27.      * @return Collection|Author[]
  28.      */
  29.     public function getMembers(): Collection
  30.     {
  31.         return $this->members;
  32.     }
  33.     public function addMember(Author $author): self
  34.     {
  35.         if (!$this->members->contains($author)) {
  36.             $this->members[] = $author;
  37.             $author->setTeam($this);
  38.         }
  39.         return $this;
  40.     }
  41.     public function removeMember(Author $author): self
  42.     {
  43.         if ($this->members->contains($author)) {
  44.             $this->members->removeElement($author);
  45.             if ($author->getTeam() === $this) {
  46.                 $author->setTeam(null);
  47.             }
  48.         }
  49.         return $this;
  50.     }
  51. }