src/Entity/Image.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ImageRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. /**
  6.  * @ORM\Entity(repositoryClass=ImageRepository::class)
  7.  */
  8. class Image
  9. {
  10.     /**
  11.      * @ORM\Id
  12.      * @ORM\GeneratedValue
  13.      * @ORM\Column(type="integer")
  14.      */
  15.     private $id;
  16.     /**
  17.      * @ORM\Column(type="string", length=255, nullable=true)
  18.      */
  19.     private $path;
  20.     /**
  21.      * @ORM\Column(type="string", length=255, nullable=true)
  22.      */
  23.     private $fileId;
  24.     /**
  25.      * @ORM\Column(type="string", length=255, nullable=true)
  26.      */
  27.     private $telegramUserId;
  28.     /**
  29.      * @ORM\Column(type="string", length=500, nullable=true)
  30.      */
  31.     private $imageId;
  32.     public function getId(): ?int
  33.     {
  34.         return $this->id;
  35.     }
  36.     public function getPath(): ?string
  37.     {
  38.         return $this->path;
  39.     }
  40.     public function setPath(?string $path): self
  41.     {
  42.         $this->path $path;
  43.         return $this;
  44.     }
  45.     public function getFileId(): ?string
  46.     {
  47.         return $this->fileId;
  48.     }
  49.     public function setFileId(?string $fileId): self
  50.     {
  51.         $this->fileId $fileId;
  52.         return $this;
  53.     }
  54.     public function getTelegramUserId(): ?string
  55.     {
  56.         return $this->telegramUserId;
  57.     }
  58.     public function setTelegramUserId(?string $telegramUserId): self
  59.     {
  60.         $this->telegramUserId $telegramUserId;
  61.         return $this;
  62.     }
  63.     public function getImageId(): ?string
  64.     {
  65.         return $this->imageId;
  66.     }
  67.     public function setImageId(?string $imageId): self
  68.     {
  69.         $this->imageId $imageId;
  70.         return $this;
  71.     }
  72.     private $newPath;
  73.     public function getNewPath(): ?string
  74.     {
  75.         return $this->newPath;
  76.     }
  77.     public function setNewPath(?string $newPath): self
  78.     {
  79.         $this->newPath $newPath;
  80.         return $this;
  81.     }
  82.     public function isImage(): bool
  83.     {
  84.         $ext pathinfo($this->pathPATHINFO_EXTENSION);
  85.         return in_array(strtolower($ext), ['jpg''jpeg''png''gif''bmp''webp''svg']);
  86.     }
  87.     public function isVideo(): bool
  88.     {
  89.         $ext pathinfo($this->pathPATHINFO_EXTENSION);
  90.         return in_array(strtolower($ext), ['mp4''avi''mov''wmv''flv''mkv']);
  91.     }
  92.     public function getMediaType(): ?string
  93.     {
  94.         if ($this->isImage()) {
  95.             return 'image';
  96.         } elseif ($this->isVideo()) {
  97.             return 'video';
  98.         }
  99.         return null;
  100.     }
  101. }