src/Entity/Tower.php line 18

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\TowerRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
  9. use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext;
  10. use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
  11. use Symfony\Component\Uid\Uuid;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. use function Symfony\Component\String\u;
  14. #[ORM\Entity(repositoryClassTowerRepository::class)]
  15. class Tower implements \JsonSerializable
  16. {
  17.     #[ORM\Id]
  18.     #[ORM\Column(type'uuid'uniquetrue)]
  19.     #[ORM\GeneratedValue(strategy'CUSTOM')]
  20.     #[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')]
  21.     private $id;
  22.     #[ORM\Column(length255)]
  23.     private ?string $type null;
  24.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  25.     private ?string $description null;
  26.     #[ORM\Column(length255nullabletrue)]
  27.     private ?string $address null;
  28.     #[ORM\Column]
  29.     private ?\DateTimeImmutable $createdAt null;
  30.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  31.     private ?\DateTime $updatedAt null;
  32.     #[ORM\ManyToOne(inversedBy'towers')]
  33.     private ?City $city null;
  34.     #[ORM\Column]
  35.     #[Assert\GreaterThanOrEqual(
  36.         value0,
  37.         message"A altura não pode ser negativa."
  38.     )]
  39.     private ?int $height null;
  40.     #[ORM\OneToMany(mappedBy'tower'targetEntitySpot::class)]
  41.     private Collection $spots;
  42.     #[ORM\OneToMany(mappedBy'tower'targetEntityRent::class)]
  43.     private Collection $rents;
  44.     #[ORM\Column(length255)]
  45.     private ?string $name null;
  46.     #[ORM\Column(length255nullabletrue)]
  47.     #[Assert\GreaterThanOrEqual(
  48.         value0,
  49.         message"O preço não pode ser negativo."
  50.     )]
  51.     private ?string $price null;
  52.     #[ORM\OneToMany(mappedBy'tower'targetEntityPhoto::class, cascade: ['persist''remove'])]
  53.     private Collection $photos;
  54.     #[ORM\OneToMany(mappedBy'tower'targetEntityDocument::class, cascade: ['persist''remove'])]
  55.     private Collection $documents;
  56.     public function getName(): ?string
  57.     {
  58.         return $this->name;
  59.     }
  60.     public function setName(string $name): self
  61.     {
  62.         $this->name $name;
  63.         return $this;
  64.     }
  65.     public function getPrice(): ?string
  66.     {
  67.         return $this->price ?? 0;
  68.     }
  69.     public function setPrice(?string $price): self
  70.     {
  71.         $this->price $price;
  72.         return $this;
  73.     }
  74.     /**
  75.      * @return Collection<int, Photo>
  76.      */
  77.     public function getPhotos(): Collection
  78.     {
  79.         return $this->photos;
  80.     }
  81.     public function addPhoto(Photo $photo): self
  82.     {
  83.         if (!$this->photos->contains($photo)) {
  84.             $this->photos->add($photo);
  85.             $photo->setTower($this);
  86.         }
  87.         return $this;
  88.     }
  89.     public function removePhoto(Photo $photo): self
  90.     {
  91.         if ($this->photos->removeElement($photo)) {
  92.             // set the owning side to null (unless already changed)
  93.             if ($photo->getTower() === $this) {
  94.                 $photo->setTower(null);
  95.             }
  96.         }
  97.         return $this;
  98.     }
  99.    
  100.     public function __construct()
  101.     {
  102.         $this->createdAt = new \DateTimeImmutable();
  103.         $this->updatedAt = new \DateTime();
  104.         $this->spots = new ArrayCollection();
  105.         $this->rents = new ArrayCollection();
  106.         $this->photos = new ArrayCollection();
  107.         $this->documents = new ArrayCollection();
  108.     }
  109.     public function getId(): ?Uuid
  110.     {
  111.         return $this->id;
  112.     }
  113.     public function getType(): ?string
  114.     {
  115.         return $this->type;
  116.     }
  117.     public function setType(string $type): self
  118.     {
  119.         $this->type $type;
  120.         return $this;
  121.     }
  122.     public function getDescription(): ?string
  123.     {
  124.         return $this->description ?? "";
  125.     }
  126.     public function setDescription(?string $description): self
  127.     {
  128.         $this->description $description;
  129.         return $this;
  130.     }
  131.     public function getAddress(): ?string
  132.     {
  133.         return $this->address ?? "";
  134.     }
  135.     public function setAddress(?string $address): self
  136.     {
  137.         $this->address $address;
  138.         return $this;
  139.     }
  140.     public function getCreatedAt(): ?\DateTimeImmutable
  141.     {
  142.         return $this->createdAt;
  143.     }
  144.     public function setCreatedAt(\DateTimeImmutable $createdAt): self
  145.     {
  146.         $this->createdAt $createdAt;
  147.         return $this;
  148.     }
  149.     public function getUpdatedAt(): ?\DateTimeInterface
  150.     {
  151.         return $this->updatedAt;
  152.     }
  153.     public function setUpdatedAt(\DateTimeInterface $updatedAt): self
  154.     {
  155.         $this->updatedAt $updatedAt;
  156.         return $this;
  157.     }
  158.     public function getCity(): ?City
  159.     {
  160.         return $this->city;
  161.     }
  162.     public function setCity(?City $city): self
  163.     {
  164.         $this->city $city;
  165.         return $this;
  166.     }
  167.     public function getHeight(): ?int
  168.     {
  169.         return $this->height;
  170.     }
  171.     public function setHeight(int $height): self
  172.     {
  173.         $this->height $height;
  174.         return $this;
  175.     }
  176.     /**
  177.      * @return Collection<int, Spot>
  178.      */
  179.     public function getSpots(): Collection
  180.     {
  181.         return $this->spots;
  182.     }
  183.     public function addSpot(Spot $spot): self
  184.     {
  185.         if (!$this->spots->contains($spot)) {
  186.             $this->spots->add($spot);
  187.             $spot->setTower($this);
  188.         }
  189.         return $this;
  190.     }
  191.     public function removeSpot(Spot $spot): self
  192.     {
  193.         if ($this->spots->removeElement($spot)) {
  194.             // set the owning side to null (unless already changed)
  195.             if ($spot->getTower() === $this) {
  196.                 $spot->setTower(null);
  197.             }
  198.         }
  199.         return $this;
  200.     }
  201.      /**
  202.      * @return Collection<int, Rent>
  203.      */
  204.     public function getRents(): Collection
  205.     {
  206.         return $this->rents;
  207.     }
  208.     public function addRent(Rent $rent): self
  209.     {
  210.         if (!$this->rents->contains($rent)) {
  211.             $this->rents->add($rent);
  212.             $rent->setTower($this);
  213.         }
  214.         return $this;
  215.     }
  216.     public function removeRent(Rent $rent): self
  217.     {
  218.         if ($this->rents->removeElement($rent)) {
  219.             // set the owning side to null (unless already changed)
  220.             if ($rent->getTower() === $this) {
  221.                 $rent->setTower(null);
  222.             }
  223.         }
  224.         return $this;
  225.     }
  226.     public function __toString()
  227.     {
  228.         return $this->getType() . ' - ' $this->getCity()->getName() .', '$this->getCity()->getState() . ' - ' $this->getAddress() . ' - ' $this->getHeight() . 'm';
  229.     }
  230.     public function jsonSerialize()
  231.     {
  232.         return [
  233.             'id' => $this->getId(),
  234.             'type' => $this->getType(),
  235.             'type' => $this->getType(),
  236.             'type_folder' => u($this->getType())->snake(),
  237.             'description' => $this->getDescription(),
  238.             'address' => $this->getAddress(),
  239.             'city' => $this->getCity()->getName(),
  240.             'state' => $this->getCity()->getState(),
  241.             'height' => $this->getHeight(),
  242.             'spots' => $this->getSpots(),
  243.             'photos' => $this->getPhotos(),
  244.         ];
  245.     }
  246.     /**
  247.      * @return Collection<int, Document>
  248.      */
  249.     public function getDocuments(): Collection
  250.     {
  251.         return $this->documents;
  252.     }
  253.     public function addDocument(Document $document): self
  254.     {
  255.         if (!$this->documents->contains($document)) {
  256.             $this->documents->add($document);
  257.             $document->setTower($this);
  258.         }
  259.         return $this;
  260.     }
  261.     public function removeDocument(Document $document): self
  262.     {
  263.         if ($this->documents->removeElement($document)) {
  264.             // set the owning side to null (unless already changed)
  265.             if ($document->getTower() === $this) {
  266.                 $document->setTower(null);
  267.             }
  268.         }
  269.         return $this;
  270.     }
  271. }
  272. class TowerType
  273. {
  274.     const ESTAIADA 'Estaiada';
  275.     const AUTOPORTANTE_LINEAR 'Autoportante Linear';
  276.     const AUTOPORTANTE_MISTA 'Autoportante Mista';
  277.     const AUTOPORTANTE_TRIANGULAR 'Autoportante Triangular';
  278. }