<?php
namespace App\Entity;
use App\Config\AssetConfig;
use App\Repository\MediaObjectRepository;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=MediaObjectRepository::class)
* @ORM\HasLifecycleCallbacks()
*/
class MediaObject
{
use RemoveImageTrait;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $filePath;
/**
* @ORM\ManyToOne(targetEntity=User::class)
*/
private $user;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $created;
/**
* @ORM\PostRemove()
*/
public function postRemoveEvent()
{
$this->removeImage($this->getFilePath());
// Remove video
$this->removeImage($this->getFilePath(), AssetConfig::VIDEO_UPLOAD_DIR);
}
public function __construct()
{
if (empty($this->getCreated())) {
$this->setCreated(new \DateTime());
}
}
public function getId(): ?int
{
return $this->id;
}
public function getFilePath(): ?string
{
return $this->filePath;
}
public function setFilePath(string $filePath): self
{
$this->filePath = $filePath;
return $this;
}
public function __toString()
{
return $this->getFilePath();
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getCreated(): ?\DateTimeInterface
{
return $this->created;
}
public function setCreated(?\DateTimeInterface $created): self
{
$this->created = $created;
return $this;
}
}