<?php
namespace App\Entity;
use App\Entity\Traits\Address;
use App\Repository\RoomRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Serializer\Annotation\SerializedName;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Entity(repositoryClass=RoomRepository::class)
* @Vich\Uploadable
*/
class Room
{
use Address;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"room:read:id", "room:read", "event:read", "registration:read"})
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
* @Assert\NotBlank
* @Groups({"room:read:name", "room:read", "event:read", "registration:read"})
*/
private $name;
/**
* @ORM\Column(type="text")
* @Assert\NotBlank
* @Groups({"room:read:description"})
*/
private $description;
/**
* @ORM\Column(type="integer")
* @Assert\NotBlank
* @Groups({"room:read:capacity"})
*/
private $capacity;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"room:read:image"})
*/
private $image;
/**
* @ORM\ManyToOne(targetEntity=Company::class, inversedBy="rooms")
* @ORM\JoinColumn(nullable=false)
* @Groups({"room:read:company", "room:read"})
*/
private $company;
/**
* @ORM\Column(type="datetime")
*/
private $createdAt;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $updatedAt;
/**
* @ORM\OneToMany(targetEntity=Event::class, mappedBy="room", orphanRemoval=true)
*/
private $events;
/**
* @Vich\UploadableField(mapping="room_images", fileNameProperty="image")
* @Assert\File(
* mimeTypes={"image/jpeg", "image/gif", "image/png"},
* maxSize="700Ki",
* )
* @var File|null
*/
private $imageFile;
/**
* @return File|null
*/
public function getImageFile(): ?File
{
return $this->imageFile;
}
/**
* @param File|null $imageFile
* @return Room
*/
public function setImageFile(?File $imageFile = null): self
{
$this->imageFile = $imageFile;
if ($imageFile) {
// if 'updatedAt' is not defined in your entity, use another property
$this->updatedAt = new \DateTime('now');
}
return $this;
}
public function __construct()
{
$this->events = new ArrayCollection();
$this->createdAt = new \DateTime();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(string $description): self
{
$this->description = $description;
return $this;
}
public function getCapacity(): ?int
{
return $this->capacity;
}
public function setCapacity(int $capacity): self
{
$this->capacity = $capacity;
return $this;
}
public function getImage(): ?string
{
return $this->image;
}
public function setImage(string $image): self
{
$this->image = $image;
return $this;
}
public function getCompany(): ?company
{
return $this->company;
}
public function setCompany(?company $company): self
{
$this->company = $company;
return $this;
}
public function getCreatedAt(): ?\DateTime
{
return $this->createdAt;
}
public function setCreatedAt(\DateTime $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTime
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTime $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* @return Collection|Event[]
*/
public function getEvents(): Collection
{
return $this->events;
}
public function addEvent(Event $event): self
{
if (!$this->events->contains($event)) {
$this->events[] = $event;
$event->setRoom($this);
}
return $this;
}
public function removeEvent(Event $event): self
{
if ($this->events->removeElement($event)) {
// set the owning side to null (unless already changed)
if ($event->getRoom() === $this) {
$event->setRoom(null);
}
}
return $this;
}
public function __toString()
{
return $this->name . ' - ' . strtoupper($this->company) . ' (max: ' . $this->capacity . ')';
}
}