<?php
namespace Submarine\FilesBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Postroyka\AppBundle\Redis\RedisBaseProvider;
use Submarine\CoreBundle\Entity\SubmarineEntityInterface;
use Submarine\CoreBundle\Uploader\AbstractUploadEntity;
/**
* Изображение
*
* @ORM\Entity
* @ORM\Table(name="submarine_images")
*
* @ORM\HasLifecycleCallbacks()
*/
class Image extends AbstractUploadEntity implements FileInterface
{
/**
* @ORM\Id
* @ORM\Column(type="integer", name="id")
* @ORM\GeneratedValue
* @var integer
*/
private $id;
/**
* @ORM\Column(type="string")
* @var string
*/
private $title;
/**
* @ORM\Column(type="string", nullable=true)
* @var string
*/
private $description;
/**
* @ORM\Column(name="entity_name", type="string", length=128)
* @var string
*/
private $parentEntityName;
/**
* @ORM\Column(name="entity_id", type="integer")
* @var integer
*/
private $parentEntityId;
/**
* @ORM\Column(type="datetime", name="time_created")
* @var \DateTime
*/
private $createdAt;
/**
* @ORM\Column(type="smallint")
* @var integer
*/
private $position;
/**
* @ORM\Column(type="string")
* @var string
*/
protected $path;
/**
* @var \Symfony\Component\HttpFoundation\File\File
*/
protected $file;
/**
* @ORM\Column(type="string", length=10, nullable=true)
* @var string
*/
protected $ext;
/**
* @ORM\Column(type="integer")
* @var string
*/
protected $size;
/**
* Имя сущности
* @return string
*/
static public function entityName()
{
return __CLASS__;
}
public function __construct()
{
$this->createdAt = new \DateTime();
$this->position = 0;
$this->size = 0;
}
/**
* Получение Id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Установка заголовка
*
* @param string $title
* @return FileInterface
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Получение заголовка
*
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Установка описания
*
* @param string $description
*/
public function setDescription($description)
{
$this->description = $description;
}
/**
* Получение описания
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Установка родительской сущности
*
* @param SubmarineEntityInterface $entity
*/
public function setParentEntity(SubmarineEntityInterface $entity)
{
$this->parentEntityName = $entity->entityName();
$this->parentEntityId = $entity->getId();
}
/**
* Установка Id родительской сущности
*
* @param int $parentEntityId
*/
public function setParentEntityId($parentEntityId)
{
$this->parentEntityId = $parentEntityId;
}
/**
* Получение Id родительской сущности
*
* @return int
*/
public function getParentEntityId()
{
return $this->parentEntityId;
}
/**
* Установка имени родительской сущности
*
* @param string $parentEntityName
*/
public function setParentEntityName($parentEntityName)
{
$this->parentEntityName = $parentEntityName;
}
/**
* Получение имени родительской сущности
*
* @return string
*/
public function getParentEntityName()
{
return $this->parentEntityName;
}
/**
* Загрузка файла
*
* @param \Symfony\Component\HttpFoundation\File\File $file
*/
public function setFile(\Symfony\Component\HttpFoundation\File\File $file = null)
{
$this->file = $file;
if (null !== $file) {
$this->setExt($this->file->guessExtension());
$this->setSize($this->file->getSize());
if (!$this->getTitle()) {
$this->setTitle($this->file->getFilename());
}
}
}
/**
* Получение файла
*
* @return \Symfony\Component\HttpFoundation\File\File
*/
public function getFile()
{
return $this->file;
}
/**
* Получение пути к файлу
*
* @return string
*/
public function getFilePath()
{
return $this->path;
}
/**
* Установка пути к файлу
*
* @param string $filePath
*/
public function setFilePath($filePath)
{
$this->path = ltrim($filePath, '/');
}
/**
* Получение пути к файлу
*
* @return string
*/
public function getPath()
{
return $this->path;
}
/**
* Установка пути к файлу
* @param string $path
*/
public function setPath($path)
{
$this->path = ltrim($path, '/');
}
/**
* Получение расширения файла
*
* @return string
*/
public function getExt()
{
return $this->ext;
}
/**
* Установка расширения файла
*
* @param string $ext
*/
public function setExt($ext)
{
$this->ext = $ext;
}
/**
* Получение размера файла
*
* @return integer
*/
public function getSize()
{
return $this->size;
}
/**
* Установка размера файла
*
* @param integer $size
*/
public function setSize($size)
{
$this->size = $size;
}
/**
* Получение позиции файла
*
* @return integer
*/
public function getPosition()
{
return $this->position;
}
/**
* Установка позиции файла
*
* @param integer $position
*/
public function setPosition($position)
{
$this->position = $position;
}
/**
* Получение времени создания
*
* @return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* Установка времени создания
*
* @param \DateTime $createdAt
*/
public function setCreatedAt(\DateTime $createdAt)
{
$this->createdAt = $createdAt;
}
/**
* Получение времени создания
* @return \DateTime
*
* @deprecated Будет удален в Submarine 3.0 используй getCreatedAt()
*/
public function getTimeCreated()
{
return $this->createdAt;
}
/**
* @ORM\PreUpdate()
* @ORM\PrePersist()
*/
public function preUpdate()
{
RedisBaseProvider::clearKeysByPattern('*' . RedisBaseProvider::REDIS_HOMEPAGE_KEY);
}
}