src/Submarine/FilesBundle/Entity/Image.php line 18

Open in your IDE?
  1. <?php
  2. namespace Submarine\FilesBundle\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Postroyka\AppBundle\Redis\RedisBaseProvider;
  5. use Submarine\CoreBundle\Entity\SubmarineEntityInterface;
  6. use Submarine\CoreBundle\Uploader\AbstractUploadEntity;
  7. /**
  8.  * Изображение
  9.  *
  10.  * @ORM\Entity
  11.  * @ORM\Table(name="submarine_images")
  12.  *
  13.  * @ORM\HasLifecycleCallbacks()
  14.  */
  15. class Image extends AbstractUploadEntity implements FileInterface
  16. {
  17.     /**
  18.      * @ORM\Id
  19.      * @ORM\Column(type="integer", name="id")
  20.      * @ORM\GeneratedValue
  21.      * @var integer
  22.      */
  23.     private $id;
  24.     /**
  25.      * @ORM\Column(type="string")
  26.      * @var string
  27.      */
  28.     private $title;
  29.     /**
  30.      * @ORM\Column(type="string", nullable=true)
  31.      * @var string
  32.      */
  33.     private $description;
  34.     /**
  35.      * @ORM\Column(name="entity_name", type="string", length=128)
  36.      * @var string
  37.      */
  38.     private $parentEntityName;
  39.     /**
  40.      * @ORM\Column(name="entity_id", type="integer")
  41.      * @var integer
  42.      */
  43.     private $parentEntityId;
  44.     /**
  45.      * @ORM\Column(type="datetime", name="time_created")
  46.      * @var \DateTime
  47.      */
  48.     private $createdAt;
  49.     /**
  50.      * @ORM\Column(type="smallint")
  51.      * @var integer
  52.      */
  53.     private $position;
  54.     /**
  55.      * @ORM\Column(type="string")
  56.      * @var string
  57.      */
  58.     protected $path;
  59.     /**
  60.      * @var \Symfony\Component\HttpFoundation\File\File
  61.      */
  62.     protected $file;
  63.     /**
  64.      * @ORM\Column(type="string", length=10, nullable=true)
  65.      * @var string
  66.      */
  67.     protected $ext;
  68.     /**
  69.      * @ORM\Column(type="integer")
  70.      * @var string
  71.      */
  72.     protected $size;
  73.     /**
  74.      * Имя сущности
  75.      * @return string
  76.      */
  77.     static public function entityName()
  78.     {
  79.         return __CLASS__;
  80.     }
  81.     public function __construct()
  82.     {
  83.         $this->createdAt = new \DateTime();
  84.         $this->position 0;
  85.         $this->size 0;
  86.     }
  87.     /**
  88.      * Получение Id
  89.      *
  90.      * @return int
  91.      */
  92.     public function getId()
  93.     {
  94.         return $this->id;
  95.     }
  96.     /**
  97.      * Установка заголовка
  98.      *
  99.      * @param string $title
  100.      * @return FileInterface
  101.      */
  102.     public function setTitle($title)
  103.     {
  104.         $this->title $title;
  105.         return $this;
  106.     }
  107.     /**
  108.      * Получение заголовка
  109.      *
  110.      * @return string
  111.      */
  112.     public function getTitle()
  113.     {
  114.         return $this->title;
  115.     }
  116.     /**
  117.      * Установка описания
  118.      *
  119.      * @param string $description
  120.      */
  121.     public function setDescription($description)
  122.     {
  123.         $this->description $description;
  124.     }
  125.     /**
  126.      * Получение описания
  127.      *
  128.      * @return string
  129.      */
  130.     public function getDescription()
  131.     {
  132.         return $this->description;
  133.     }
  134.     /**
  135.      * Установка родительской сущности
  136.      *
  137.      * @param SubmarineEntityInterface $entity
  138.      */
  139.     public function setParentEntity(SubmarineEntityInterface $entity)
  140.     {
  141.         $this->parentEntityName $entity->entityName();
  142.         $this->parentEntityId $entity->getId();
  143.     }
  144.     /**
  145.      * Установка Id родительской сущности
  146.      *
  147.      * @param int $parentEntityId
  148.      */
  149.     public function setParentEntityId($parentEntityId)
  150.     {
  151.         $this->parentEntityId $parentEntityId;
  152.     }
  153.     /**
  154.      * Получение Id родительской сущности
  155.      *
  156.      * @return int
  157.      */
  158.     public function getParentEntityId()
  159.     {
  160.         return $this->parentEntityId;
  161.     }
  162.     /**
  163.      * Установка имени родительской сущности
  164.      *
  165.      * @param string $parentEntityName
  166.      */
  167.     public function setParentEntityName($parentEntityName)
  168.     {
  169.         $this->parentEntityName $parentEntityName;
  170.     }
  171.     /**
  172.      * Получение имени родительской сущности
  173.      *
  174.      * @return string
  175.      */
  176.     public function getParentEntityName()
  177.     {
  178.         return $this->parentEntityName;
  179.     }
  180.     /**
  181.      * Загрузка файла
  182.      *
  183.      * @param \Symfony\Component\HttpFoundation\File\File $file
  184.      */
  185.     public function setFile(\Symfony\Component\HttpFoundation\File\File $file null)
  186.     {
  187.         $this->file $file;
  188.         if (null !== $file) {
  189.             $this->setExt($this->file->guessExtension());
  190.             $this->setSize($this->file->getSize());
  191.             if (!$this->getTitle()) {
  192.                 $this->setTitle($this->file->getFilename());
  193.             }
  194.         }
  195.     }
  196.     /**
  197.      * Получение файла
  198.      *
  199.      * @return \Symfony\Component\HttpFoundation\File\File
  200.      */
  201.     public function getFile()
  202.     {
  203.         return $this->file;
  204.     }
  205.     /**
  206.      * Получение пути к файлу
  207.      *
  208.      * @return string
  209.      */
  210.     public function getFilePath()
  211.     {
  212.         return $this->path;
  213.     }
  214.     /**
  215.      * Установка пути к файлу
  216.      *
  217.      * @param string $filePath
  218.      */
  219.     public function setFilePath($filePath)
  220.     {
  221.         $this->path ltrim($filePath'/');
  222.     }
  223.     /**
  224.      * Получение пути к файлу
  225.      *
  226.      * @return string
  227.      */
  228.     public function getPath()
  229.     {
  230.         return $this->path;
  231.     }
  232.     /**
  233.      * Установка пути к файлу
  234.      * @param string $path
  235.      */
  236.     public function setPath($path)
  237.     {
  238.         $this->path ltrim($path'/');
  239.     }
  240.     /**
  241.      * Получение расширения файла
  242.      *
  243.      * @return string
  244.      */
  245.     public function getExt()
  246.     {
  247.         return $this->ext;
  248.     }
  249.     /**
  250.      * Установка расширения файла
  251.      *
  252.      * @param string $ext
  253.      */
  254.     public function setExt($ext)
  255.     {
  256.         $this->ext $ext;
  257.     }
  258.     /**
  259.      * Получение размера файла
  260.      *
  261.      * @return integer
  262.      */
  263.     public function getSize()
  264.     {
  265.         return $this->size;
  266.     }
  267.     /**
  268.      * Установка размера файла
  269.      *
  270.      * @param integer $size
  271.      */
  272.     public function setSize($size)
  273.     {
  274.         $this->size $size;
  275.     }
  276.     /**
  277.      * Получение позиции файла
  278.      *
  279.      * @return integer
  280.      */
  281.     public function getPosition()
  282.     {
  283.         return $this->position;
  284.     }
  285.     /**
  286.      * Установка позиции файла
  287.      *
  288.      * @param integer $position
  289.      */
  290.     public function setPosition($position)
  291.     {
  292.         $this->position $position;
  293.     }
  294.     /**
  295.      * Получение времени создания
  296.      *
  297.      * @return \DateTime
  298.      */
  299.     public function getCreatedAt()
  300.     {
  301.         return $this->createdAt;
  302.     }
  303.     /**
  304.      * Установка времени создания
  305.      *
  306.      * @param \DateTime $createdAt
  307.      */
  308.     public function setCreatedAt(\DateTime $createdAt)
  309.     {
  310.         $this->createdAt $createdAt;
  311.     }
  312.     /**
  313.      * Получение времени создания
  314.      * @return \DateTime
  315.      *
  316.      * @deprecated Будет удален в Submarine 3.0 используй getCreatedAt()
  317.      */
  318.     public function getTimeCreated()
  319.     {
  320.         return $this->createdAt;
  321.     }
  322.     /**
  323.      * @ORM\PreUpdate()
  324.      * @ORM\PrePersist()
  325.      */
  326.     public function preUpdate()
  327.     {
  328.         RedisBaseProvider::clearKeysByPattern('*' RedisBaseProvider::REDIS_HOMEPAGE_KEY);
  329.     }
  330. }