src/Entity/Rent.php line 186
<?phpnamespace App\Entity;use App\Repository\RentRepository;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\DBAL\Types\Types;use Doctrine\ORM\Mapping as ORM;use Symfony\Component\Uid\Uuid;use Symfony\Component\HttpFoundation\File\File;use Vich\UploaderBundle\Mapping\Annotation as Vich;use Symfony\Component\Validator\Constraints as Assert;#[ORM\Entity(repositoryClass: RentRepository::class)]#[Vich\Uploadable]class Rent implements \JsonSerializable{#[ORM\Id]#[ORM\Column(type: 'uuid', unique: true)]#[ORM\GeneratedValue(strategy: 'CUSTOM')]#[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')]private $id;#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]private ?\DateTimeInterface $startAt = null;#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]private ?\DateTimeInterface $finishAt = null;#[ORM\ManyToOne(inversedBy: 'rents')]private ?Company $company = null;#[ORM\OneToMany(mappedBy: 'rent', targetEntity: Spot::class, cascade: ['persist', 'remove'])]#[ORM\OrderBy(['height' => 'ASC'])]private Collection $spots;#[ORM\ManyToOne(inversedBy: 'rents')]#[ORM\JoinColumn(nullable: false)]private ?Tower $tower = null;#[Assert\File(mimeTypes: ["application/pdf", "application/x-pdf"])]#[Vich\UploadableField(mapping: 'contract', fileNameProperty: 'contractName', size: 'contractSize')]private ?File $contractFile = null;#[ORM\Column(length: 255, nullable: true)]private ?string $contractName = null;#[ORM\Column(nullable: true)]private ?int $contractSize = null;#[ORM\Column]private ?\DateTimeImmutable $createdAt = null;#[ORM\Column(type: Types::DATETIME_MUTABLE)]private ?\DateTime $updatedAt = null;#[Vich\UploadableField(mapping: 'photo', fileNameProperty: 'photoName', size: 'photoSize')]private ?File $photoFile = null;#[ORM\Column(length: 255, nullable: true)]private ?string $photoName = null;#[ORM\Column(nullable: true)]private ?int $photoSize = null;private ?string $link = null;#[ORM\Column(length: 255, nullable: true)]private ?string $price = null;public ?int $maxHeight = 0;public function getLink(): ?string{return $this->link;}public function setLink(string $link){$this->link = $link;}public function __construct(){$this->spots = new ArrayCollection();$this->createdAt = new \DateTimeImmutable();$this->updatedAt = new \DateTime();}public function getId(): ?Uuid{return $this->id;}public function getStartAt(): ?\DateTimeInterface{return $this->startAt;}public function setStartAt(?\DateTimeInterface $startAt): self{$this->startAt = $startAt;return $this;}public function getFinishAt(): ?\DateTimeInterface{return $this->finishAt;}public function setFinishAt(?\DateTimeInterface $finishAt): self{$this->finishAt = $finishAt;return $this;}public function getCompany(): ?Company{return $this->company;}public function setCompany(?Company $company): self{$this->company = $company;return $this;}/*** @return Collection<int, Spot>*/public function getSpots(): Collection{return $this->spots;}public function addSpot(Spot $spot): self{if (!$this->spots->contains($spot)) {$this->spots->add($spot);$spot->setRent($this);}return $this;}public function removeSpot(Spot $spot): self{if ($this->spots->removeElement($spot)) {// set the owning side to null (unless already changed)if ($spot->getRent() === $this) {$spot->setRent(null);}}return $this;}public function getSpotsAsString(): string{$spots = $this->getSpots();$lines = [];foreach ($spots as $spot) {$lines[] = $spot;}return implode('<br>', $lines);}public function getTower(): ?Tower{return $this->tower;}public function setTower(?Tower $tower): self{$this->tower = $tower;return $this;}public function jsonSerialize(){return ['id' => $this->getId(),'startAt' => $this->getStartAt()->format('d/m/Y'),'finishAt' => $this->getFinishAt()->format('d/m/Y'),'company' => $this->getCompany()->getName(),'link' => $this->getLink(),];}public function setContractFile(?File $contractFile = null): void{$this->contractFile = $contractFile;if (null !== $contractFile) {$this->updatedAt = new \DateTimeImmutable();}}public function getContractFile(): ?File{return $this->contractFile;}public function getContractNameWithFolder(): ?string{if(empty($this->contractName))return $this->contractName;$folder = "/contracts/".$this->getCreatedAt()->format('Y/m/');return $folder . $this->contractName;}public function getContractName(): ?string{return $this->contractName;}public function setContractName(?string $contractName): self{$this->contractName = $contractName;return $this;}public function getContractSize(): ?int{return $this->contractSize;}public function setContractSize(?int $contractSize): self{$this->contractSize = $contractSize;return $this;}public function getCreatedAt(): ?\DateTimeImmutable{return $this->createdAt;}public function setCreatedAt(\DateTimeImmutable $createdAt): self{$this->createdAt = $createdAt;return $this;}public function getUpdatedAt(): ?\DateTimeInterface{return $this->updatedAt;}public function setUpdatedAt(\DateTimeInterface $updatedAt): self{$this->updatedAt = $updatedAt;return $this;}public function setPhotoFile(?File $photoFile = null): void{$this->photoFile = $photoFile;if (null !== $photoFile) {$this->updatedAt = new \DateTimeImmutable();}}public function getPhotoFile(): ?File{return $this->photoFile;}public function getPhotoNameWithFolder(): ?string{if(empty($this->photoName))return $this->photoName;$folder = "/photos/".$this->getCreatedAt()->format('Y/m/');return $folder . $this->photoName;}public function getPhotoName(): ?string{return $this->photoName;}public function setPhotoName(string $photoName): self{$this->photoName = $photoName;return $this;}public function getPhotoSize(): ?int{return $this->photoSize;}public function setPhotoSize(?int $photoSize): self{$this->photoSize = $photoSize;return $this;}public function getRentValue(): ?string{$totalSpots = $this->getSpots()->count();$price = empty($this->getPrice()) ? $this->getTower()->getPrice() : $this->getPrice();return ($price * $totalSpots) ?? 0;}public function getPrice(): ?string{return $this->price ?? 0;}public function setPrice(string $price): self{$this->price = $price;return $this;}}