src/Entity/MediaObject.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Config\AssetConfig;
  4. use App\Repository\MediaObjectRepository;
  5. use Doctrine\ORM\Mapping as ORM;
  6. /**
  7.  * @ORM\Entity(repositoryClass=MediaObjectRepository::class)
  8.  * @ORM\HasLifecycleCallbacks()
  9.  */
  10. class MediaObject
  11. {
  12.     use RemoveImageTrait;
  13.     /**
  14.      * @ORM\Id
  15.      * @ORM\GeneratedValue
  16.      * @ORM\Column(type="integer")
  17.      */
  18.     private $id;
  19.     /**
  20.      * @ORM\Column(type="string", length=255)
  21.      */
  22.     private $filePath;
  23.     /**
  24.      * @ORM\ManyToOne(targetEntity=User::class)
  25.      */
  26.     private $user;
  27.     /**
  28.      * @ORM\Column(type="datetime", nullable=true)
  29.      */
  30.     private $created;
  31.     /**
  32.      * @ORM\PostRemove()
  33.      */
  34.     public function postRemoveEvent()
  35.     {
  36.         $this->removeImage($this->getFilePath());
  37.         // Remove video
  38.         $this->removeImage($this->getFilePath(), AssetConfig::VIDEO_UPLOAD_DIR);
  39.     }
  40.     public function __construct()
  41.     {
  42.         if (empty($this->getCreated())) {
  43.             $this->setCreated(new \DateTime());
  44.         }
  45.     }
  46.     public function getId(): ?int
  47.     {
  48.         return $this->id;
  49.     }
  50.     public function getFilePath(): ?string
  51.     {
  52.         return $this->filePath;
  53.     }
  54.     public function setFilePath(string $filePath): self
  55.     {
  56.         $this->filePath $filePath;
  57.         return $this;
  58.     }
  59.     public function __toString()
  60.     {
  61.         return $this->getFilePath();
  62.     }
  63.     public function getUser(): ?User
  64.     {
  65.         return $this->user;
  66.     }
  67.     public function setUser(?User $user): self
  68.     {
  69.         $this->user $user;
  70.         return $this;
  71.     }
  72.     public function getCreated(): ?\DateTimeInterface
  73.     {
  74.         return $this->created;
  75.     }
  76.     public function setCreated(?\DateTimeInterface $created): self
  77.     {
  78.         $this->created $created;
  79.         return $this;
  80.     }
  81. }