src/Entity/Group.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\GroupRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Entity(repositoryClass=GroupRepository::class)
  9.  * @ORM\Table(name="`group`")
  10.  */
  11. class Group
  12. {
  13.     /**
  14.      * @ORM\Id
  15.      * @ORM\GeneratedValue
  16.      * @ORM\Column(type="integer")
  17.      */
  18.     private $id;
  19.     /**
  20.      * @ORM\Column(type="string", length=255)
  21.      */
  22.     private $name;
  23.     /**
  24.      * @ORM\ManyToMany(targetEntity=User::class, inversedBy="groups")
  25.      */
  26.     private $member;
  27.     /**
  28.      * @ORM\Column(type="datetime")
  29.      */
  30.     private $created;
  31.     /**
  32.      * @ORM\OneToMany(targetEntity=Cars::class, mappedBy="parentGroup")
  33.      */
  34.     private $cars;
  35.     /**
  36.      * @ORM\ManyToOne(targetEntity=User::class, inversedBy="ownedGroups")
  37.      * @ORM\JoinColumn(nullable=false)
  38.      */
  39.     private $owner;
  40.     public function __construct()
  41.     {
  42.         $this->member = new ArrayCollection();
  43.         $this->cars = new ArrayCollection();
  44.         $this->created = new \DateTime();
  45.     }
  46.     public function getId(): ?int
  47.     {
  48.         return $this->id;
  49.     }
  50.     public function getName(): ?string
  51.     {
  52.         return $this->name;
  53.     }
  54.     public function setName(string $name): self
  55.     {
  56.         $this->name = $name;
  57.         return $this;
  58.     }
  59.     /**
  60.      * @return Collection<int, User>
  61.      */
  62.     public function getMember(): Collection
  63.     {
  64.         if($this->getOwner() != null){
  65.             $this->member->add($this->getOwner());
  66.         }
  67.         return $this->member;
  68.     }
  69.     public function addMember(User $member): self
  70.     {
  71.         if (!$this->member->contains($member)) {
  72.             $this->member[] = $member;
  73.         }
  74.         return $this;
  75.     }
  76.     public function removeMember(User $member): self
  77.     {
  78.         $this->member->removeElement($member);
  79.         return $this;
  80.     }
  81.     public function getCreated(): ?\DateTimeInterface
  82.     {
  83.         return $this->created;
  84.     }
  85.     public function setCreated(\DateTimeInterface $created): self
  86.     {
  87.         $this->created = $created;
  88.         return $this;
  89.     }
  90.     /**
  91.      * @return Collection<int, Cars>
  92.      */
  93.     public function getCars(): Collection
  94.     {
  95.         return $this->cars;
  96.     }
  97.     public function addCar(Cars $car): self
  98.     {
  99.         if (!$this->cars->contains($car)) {
  100.             $this->cars[] = $car;
  101.             $car->setParentGroup($this);
  102.         }
  103.         return $this;
  104.     }
  105.     public function removeCar(Cars $car): self
  106.     {
  107.         if ($this->cars->removeElement($car)) {
  108.             // set the owning side to null (unless already changed)
  109.             if ($car->getParentGroup() === $this) {
  110.                 $car->setParentGroup(null);
  111.             }
  112.         }
  113.         return $this;
  114.     }
  115.     public function __toString()
  116.     {
  117.         return $this->name;
  118.     }
  119.     public function getOwner(): ?User
  120.     {
  121.         return $this->owner;
  122.     }
  123.     public function setOwner(?User $owner): self
  124.     {
  125.         $this->owner = $owner;
  126.         return $this;
  127.     }
  128. }