<?php
namespace App\CasinoBundle\Entity;
use App\CmsBundle\Entity\TimeStampedTrait;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use DateTime;
/**
* Logo
*
* @ORM\Table(name="logo")
* @ORM\Entity
* @ORM\HasLifecycleCallbacks()
*/
class Logo
{
use TimeStampedTrait;
const WEBPATH = '/uploads/logos/';
const SERVER_PATH_TO_IMAGE_FOLDER = __DIR__ . '/../../../public/' . self::WEBPATH;
/**
* @var int
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="w_size", type="integer", nullable=true)
*/
private $widthSize;
/**
* @var string
*
* @ORM\Column(name="h_size", type="integer", nullable=true)
*/
private $heightSize;
/**
* @ORM\ManyToOne(targetEntity="App\CasinoBundle\Entity\Casino", inversedBy="logos", cascade={"persist"})
* @ORM\JoinColumn(nullable=false)
*/
private $casino;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $photo;
/**
* Unmapped property to handle file uploads
*/
private $file;
/**
* @var bool|null
*
* @ORM\Column(name="for_review", type="boolean", nullable=true)
*/
private $review;
/**
* @var bool|null
*
* @ORM\Column(name="for_catalog", type="boolean", nullable=true)
*/
private $catalog;
public function __toString(): string
{
return $this->photo;
}
public function __construct()
{
$this->setCreatedValues();
}
public function getId(): int
{
return $this->id;
}
public function setId(int $id): void
{
$this->id = $id;
}
public function getSize(): ?string
{
return $this->widthSize . 'x' . $this->heightSize;
}
public function setWidthSize(int $size): self
{
$this->widthSize = $size;
return $this;
}
public function setHeightSize(int $size): self
{
$this->heightSize = $size;
return $this;
}
public function getWidthSize(): ?int
{
return $this->widthSize;
}
public function getHeightSize(): ?int
{
return $this->heightSize;
}
public function getCasino(): ?Casino
{
return $this->casino;
}
public function setCasino(?Casino $casino): self
{
$this->casino = $casino;
return $this;
}
public function getPhoto(): ?string
{
return $this->photo;
}
public function setPhoto(?string $photo): self
{
$this->photo = $photo;
return $this;
}
/**
* @param UploadedFile $file
*/
public function setFile(UploadedFile $file = null)
{
$this->file = $file;
}
/**
* @return UploadedFile
*/
public function getFile()
{
return $this->file;
}
/**
* Manages the copying of the file to the relevant place on the server
* @ORM\PrePersist()
* @ORM\PreUpdate()
*/
public function upload()
{
// the file property can be empty if the field is not required
if (null === $this->getFile()) {
return;
}
// we use the original file name here but you should
// sanitize it at least to avoid any security issues
// move takes the target directory and target filename as params
$filename = $this->getFile()->getClientOriginalName();
$ext = explode('.', $filename);
$newFilename = (new DateTime())->getTimestamp() . '.' . end($ext);
$this->getFile()->move(
self::SERVER_PATH_TO_IMAGE_FOLDER,
$newFilename
);
// set the path property to the filename where you've saved the file
$this->photo = self::WEBPATH . $newFilename;
// clean up the file property as you won't need it anymore
$this->setFile(null);
}
/**
* Lifecycle callback to upload the file to the server.
*/
public function lifecycleFileUpload()
{
$this->upload();
}
/**
* Updates the hash value to force the preUpdate and postUpdate events to fire.
*/
public function refreshUpdated()
{
$this->setUpdated(new \DateTime());
}
public function setReview(?bool $value): self
{
$this->review = $value;
return $this;
}
public function getReview(?bool $value): ?bool
{
return $this->review;
}
public function setCatalog(?bool $value): self
{
$this->catalog = $value;
return $this;
}
public function getCatalog(?bool $value): ?bool
{
return $this->catalog;
}
}