src/Entity/Room.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\Address;
  4. use App\Repository\RoomRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\HttpFoundation\File\File;
  9. use Symfony\Component\Serializer\Annotation\SerializedName;
  10. use Symfony\Component\Serializer\Annotation\Groups;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  13. /**
  14.  * @ORM\Entity(repositoryClass=RoomRepository::class)
  15.  * @Vich\Uploadable
  16.  */
  17. class Room
  18. {
  19.     use Address;
  20.     /**
  21.      * @ORM\Id
  22.      * @ORM\GeneratedValue
  23.      * @ORM\Column(type="integer")
  24.      * @Groups({"room:read:id", "room:read", "event:read", "registration:read"})
  25.      */
  26.     private $id;
  27.     /**
  28.      * @ORM\Column(type="string", length=255)
  29.      * @Assert\NotBlank
  30.      * @Groups({"room:read:name", "room:read", "event:read", "registration:read"})
  31.      */
  32.     private $name;
  33.     /**
  34.      * @ORM\Column(type="text")
  35.      * @Assert\NotBlank
  36.      * @Groups({"room:read:description"})
  37.      */
  38.     private $description;
  39.     /**
  40.      * @ORM\Column(type="integer")
  41.      * @Assert\NotBlank
  42.      * @Groups({"room:read:capacity"})
  43.      */
  44.     private $capacity;
  45.     /**
  46.      * @ORM\Column(type="string", length=255, nullable=true)
  47.      * @Groups({"room:read:image"})
  48.      */
  49.     private $image;
  50.     /**
  51.      * @ORM\ManyToOne(targetEntity=Company::class, inversedBy="rooms")
  52.      * @ORM\JoinColumn(nullable=false)
  53.      * @Groups({"room:read:company", "room:read"})
  54.      */
  55.     private $company;
  56.     /**
  57.      * @ORM\Column(type="datetime")
  58.      */
  59.     private $createdAt;
  60.     /**
  61.      * @ORM\Column(type="datetime", nullable=true)
  62.      */
  63.     private $updatedAt;
  64.     /**
  65.      * @ORM\OneToMany(targetEntity=Event::class, mappedBy="room", orphanRemoval=true)
  66.      */
  67.     private $events;
  68.     /**
  69.      * @Vich\UploadableField(mapping="room_images", fileNameProperty="image")
  70.      * @Assert\File(
  71.      *     mimeTypes={"image/jpeg", "image/gif", "image/png"},
  72.      *     maxSize="700Ki",
  73.      * )
  74.      * @var File|null
  75.      */
  76.     private $imageFile;
  77.     /**
  78.      * @return File|null
  79.      */
  80.     public function getImageFile(): ?File
  81.     {
  82.         return $this->imageFile;
  83.     }
  84.     /**
  85.      * @param File|null $imageFile
  86.      * @return Room
  87.      */
  88.     public function setImageFile(?File $imageFile null): self
  89.     {
  90.         $this->imageFile $imageFile;
  91.         if ($imageFile) {
  92.             // if 'updatedAt' is not defined in your entity, use another property
  93.             $this->updatedAt = new \DateTime('now');
  94.         }
  95.         return $this;
  96.     }
  97.     public function __construct()
  98.     {
  99.         $this->events = new ArrayCollection();
  100.         $this->createdAt = new \DateTime();
  101.     }
  102.     public function getId(): ?int
  103.     {
  104.         return $this->id;
  105.     }
  106.     public function getName(): ?string
  107.     {
  108.         return $this->name;
  109.     }
  110.     public function setName(string $name): self
  111.     {
  112.         $this->name $name;
  113.         return $this;
  114.     }
  115.     public function getDescription(): ?string
  116.     {
  117.         return $this->description;
  118.     }
  119.     public function setDescription(string $description): self
  120.     {
  121.         $this->description $description;
  122.         return $this;
  123.     }
  124.     public function getCapacity(): ?int
  125.     {
  126.         return $this->capacity;
  127.     }
  128.     public function setCapacity(int $capacity): self
  129.     {
  130.         $this->capacity $capacity;
  131.         return $this;
  132.     }
  133.     public function getImage(): ?string
  134.     {
  135.         return $this->image;
  136.     }
  137.     public function setImage(string $image): self
  138.     {
  139.         $this->image $image;
  140.         return $this;
  141.     }
  142.     public function getCompany(): ?company
  143.     {
  144.         return $this->company;
  145.     }
  146.     public function setCompany(?company $company): self
  147.     {
  148.         $this->company $company;
  149.         return $this;
  150.     }
  151.     public function getCreatedAt(): ?\DateTime
  152.     {
  153.         return $this->createdAt;
  154.     }
  155.     public function setCreatedAt(\DateTime $createdAt): self
  156.     {
  157.         $this->createdAt $createdAt;
  158.         return $this;
  159.     }
  160.     public function getUpdatedAt(): ?\DateTime
  161.     {
  162.         return $this->updatedAt;
  163.     }
  164.     public function setUpdatedAt(?\DateTime $updatedAt): self
  165.     {
  166.         $this->updatedAt $updatedAt;
  167.         return $this;
  168.     }
  169.     /**
  170.      * @return Collection|Event[]
  171.      */
  172.     public function getEvents(): Collection
  173.     {
  174.         return $this->events;
  175.     }
  176.     public function addEvent(Event $event): self
  177.     {
  178.         if (!$this->events->contains($event)) {
  179.             $this->events[] = $event;
  180.             $event->setRoom($this);
  181.         }
  182.         return $this;
  183.     }
  184.     public function removeEvent(Event $event): self
  185.     {
  186.         if ($this->events->removeElement($event)) {
  187.             // set the owning side to null (unless already changed)
  188.             if ($event->getRoom() === $this) {
  189.                 $event->setRoom(null);
  190.             }
  191.         }
  192.         return $this;
  193.     }
  194.     public function __toString()
  195.     {
  196.         return $this->name ' - ' strtoupper($this->company) . ' (max: ' $this->capacity ')';
  197.     }
  198. }