src/Entity/Spot.php line 106

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\SpotRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Symfony\Component\Uid\Uuid;
  6. use function Symfony\Component\String\u;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. #[ORM\Entity(repositoryClassSpotRepository::class)]
  9. class Spot implements \JsonSerializable
  10. {
  11.     #[ORM\Id]
  12.     #[ORM\Column(type'uuid'uniquetrue)]
  13.     #[ORM\GeneratedValue(strategy'CUSTOM')]
  14.     #[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')]
  15.     private $id;
  16.     #[ORM\ManyToOne(inversedBy'spots')]
  17.     private ?Tower $tower null;
  18.     #[ORM\ManyToOne(inversedBy'spots')]
  19.     private ?Rent $rent null;
  20.     #[ORM\Column]
  21.     #[Assert\LessThanOrEqual(
  22.         value'tower.height',
  23.         message"A altura do ponto não pode ser maior do que a altura da torre."
  24.       )]
  25.     private ?int $height null;
  26.     #[ORM\Column(length255)]
  27.     private ?string $direction null;
  28.     private $directionNames = [
  29.         'n' => 'Norte',
  30.         's' => 'Sul',
  31.         'l' => 'Leste',
  32.         'o' => 'Oeste',
  33.     ];
  34.     public function getId(): ?Uuid
  35.     {
  36.         return $this->id;
  37.     }
  38.     public function getTower(): ?Tower
  39.     {
  40.         return $this->tower;
  41.     }
  42.     public function setTower(?Tower $tower): self
  43.     {
  44.         $this->tower $tower;
  45.         return $this;
  46.     }
  47.     public function getRent(): ?Rent
  48.     {
  49.         return $this->rent;
  50.     }
  51.     public function setRent(?Rent $rent): self
  52.     {
  53.         $this->rent $rent;
  54.         return $this;
  55.     }
  56.     public function getHeight(): ?int
  57.     {
  58.         return $this->height;
  59.     }
  60.     public function setHeight(int $height): self
  61.     {
  62.         $this->height $height;
  63.         return $this;
  64.     }
  65.     public function getDirection(): ?string
  66.     {
  67.         return $this->direction;
  68.     }
  69.     public function setDirection(string $direction): self
  70.     {
  71.         $this->direction $direction;
  72.         return $this;
  73.     }
  74.     public function getDirectionName(): string
  75.     {
  76.         return $this->directionNames[$this->getDirection()];
  77.     }
  78.     public function __toString(): string
  79.     {
  80.         return "Direção: "$this->getDirectionName() . ' a ' $this->getHeight(). 'm';
  81.     }
  82.     public function jsonSerialize()
  83.     {
  84.         return [
  85.             'id' => $this->getId(),
  86.             'height' => $this->getHeight(),
  87.             'direction' => $this->getDirection(),
  88.             'directionName' => $this->getDirectionName(),
  89.             'rent' => $this->getRent(),
  90.         ];
  91.     }
  92. }