<?php
namespace App\Entity;
use App\Repository\HomepageRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\HttpFoundation\File\UploadedFile;
/**
* @ORM\Entity(repositoryClass=HomepageRepository::class)
* @ORM\HasLifecycleCallbacks
*/
class Homepage
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $background;
/**
* @Assert\Image(maxSize="2M")
*/
private $file;
private $temp;
/**
* @ORM\Column(type="string", length=255)
*/
private $title1;
/**
* @ORM\Column(type="string", length=255)
*/
private $subTitle1;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $title3;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $subTitle3;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $title4;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $subTitle4;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $title5;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $subTitle5;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $title6;
/**
* @ORM\Column(type="text", length=255, nullable=true)
*/
private $subTitle6;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $title7;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $subTitle7;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $title8;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $subTitle8;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $title9;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $subTitle9;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $title10;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $subTitle10;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $keywords;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $description;
public function getId(): ?int
{
return $this->id;
}
public function getBackground(): ?string
{
return $this->background;
}
public function setBackground(string $background): self
{
$this->background = $background;
return $this;
}
public function setTemp($temp)
{
$this->temp = $temp;
return $this;
}
public function getTemp()
{
return $this->temp;
}
public function setFile(UploadedFile $file)
{
$this->file = $file;
if (!is_null($this->background)) {
$this->temp = $this->background;
$this->background = null;
}
return $this;
}
public function getFile()
{
return $this->file;
}
/**
* @ORM\PrePersist()
* @ORM\PreUpdate()
*/
public function preUpload()
{
if (is_null($this->file)) {
return;
}
$this->background = md5(uniqid()).'.'.$this->file->guessExtension();
}
/**
* @ORM\PostPersist()
* @ORM\PostUpdate()
*/
public function upload()
{
if (is_null($this->file)) {
return;
}
if (!is_null($this->temp)) {
$oldFile = $this->getUploadRootDir().'/'.$this->temp;
if (file_exists($oldFile)) {
@unlink($oldFile);
}
}
$this->file->move(
$this->getUploadRootDir(),$this->background
);
}
/**
* @ORM\PreRemove()
*/
public function preRemoveUpload()
{
$this->temp = $this->getUploadRootDir().'/'.$this->background;
}
/**
* @ORM\PostRemove()
*/
public function removeUpload()
{
if (file_exists($this->temp)) {
@unlink($this->temp);
}
}
public function getUploadDir()
{
return 'uploads/files/backgrounds/homepage';
}
protected function getUploadRootDir()
{
return __DIR__.'/../../../../public/'.$this->getUploadDir();
}
public function getBackgroundPath()
{
return $this->getUploadDir().'/'.$this->getBackground();
}
protected function removeThumb()
{
$tab = ['117x117', '160x100', '180x92', '214x214', '300x200','720x480','900x300', '1033x276'];
foreach ($tab as $type) {
$url = __DIR__.'/../../../../public/media/cache/'.$type.'/'.$this->getUploadDir().'/'.$this->temp;
if (file_exists($url)) {
@unlink($url);
}
}
}
public function getTitle1(): ?string
{
return $this->title1;
}
public function setTitle1(string $title1): self
{
$this->title1 = $title1;
return $this;
}
public function getSubTitle1(): ?string
{
return $this->subTitle1;
}
public function setSubTitle1(string $subTitle1): self
{
$this->subTitle1 = $subTitle1;
return $this;
}
public function getTitle3(): ?string
{
return $this->title3;
}
public function setTitle3(?string $title3): self
{
$this->title3 = $title3;
return $this;
}
public function getSubTitle3(): ?string
{
return $this->subTitle3;
}
public function setSubTitle3(?string $subTitle3): self
{
$this->subTitle3 = $subTitle3;
return $this;
}
public function getTitle4(): ?string
{
return $this->title4;
}
public function setTitle4(?string $title4): self
{
$this->title4 = $title4;
return $this;
}
public function getSubTitle4(): ?string
{
return $this->subTitle4;
}
public function setSubTitle4(?string $subTitle4): self
{
$this->subTitle4 = $subTitle4;
return $this;
}
public function getTitle5(): ?string
{
return $this->title5;
}
public function setTitle5(?string $title5): self
{
$this->title5 = $title5;
return $this;
}
public function getSubTitle5(): ?string
{
return $this->subTitle5;
}
public function setSubTitle5(?string $subTitle5): self
{
$this->subTitle5 = $subTitle5;
return $this;
}
public function getTitle6(): ?string
{
return $this->title6;
}
public function setTitle6(?string $title6): self
{
$this->title6 = $title6;
return $this;
}
public function getSubTitle6(): ?string
{
return $this->subTitle6;
}
public function setSubTitle6(?string $subTitle6): self
{
$this->subTitle6 = $subTitle6;
return $this;
}
public function getTitle7(): ?string
{
return $this->title7;
}
public function setTitle7(?string $title7): self
{
$this->title7 = $title7;
return $this;
}
public function getSubTitle7(): ?string
{
return $this->subTitle7;
}
public function setSubTitle7(?string $subTitle7): self
{
$this->subTitle7 = $subTitle7;
return $this;
}
public function getTitle8(): ?string
{
return $this->title8;
}
public function setTitle8(?string $title8): self
{
$this->title8 = $title8;
return $this;
}
public function getSubTitle8(): ?string
{
return $this->subTitle8;
}
public function setSubTitle8(?string $subTitle8): self
{
$this->subTitle8 = $subTitle8;
return $this;
}
public function getTitle9(): ?string
{
return $this->title9;
}
public function setTitle9(?string $title9): self
{
$this->title9 = $title9;
return $this;
}
public function getSubTitle9(): ?string
{
return $this->subTitle9;
}
public function setSubTitle9(?string $subTitle9): self
{
$this->subTitle9 = $subTitle9;
return $this;
}
public function getTitle10(): ?string
{
return $this->title10;
}
public function setTitle10(?string $title10): self
{
$this->title10 = $title10;
return $this;
}
public function getSubTitle10(): ?string
{
return $this->subTitle10;
}
public function setSubTitle10(?string $subTitle10): self
{
$this->subTitle10 = $subTitle10;
return $this;
}
public function getKeywords(): ?string
{
return $this->keywords;
}
public function setKeywords(?string $keywords): self
{
$this->keywords = $keywords;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
}