src/Entity/Saloon/MediaFile.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Saloon;
  3. use App\Entity\IMediaFile;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Doctrine\ORM\Mapping\Index;
  6. use Symfony\Component\Serializer\Annotation\Groups;
  7. #[ORM\Table(name: 'saloon_media_files')]
  8. #[Index(name: 'idx_type', columns: ['type'])]
  9. #[Index(name: 'idx_saloon_type', columns: ['saloon_id', 'type'])]
  10. #[ORM\Entity]
  11. #[ORM\InheritanceType('SINGLE_TABLE')]
  12. #[ORM\DiscriminatorColumn(name: 'type', type: 'string', length: 12)]
  13. #[ORM\DiscriminatorMap(['photo' => Photo::class, 'thumbnail' => Thumbnail::class, 'video' => Video::class])]
  14. abstract class MediaFile implements IMediaFile
  15. {
  16.     public const TYPE_PHOTO = 'photo';
  17.     public const TYPE_THUMBNAIL = 'thumbnail';
  18.     public const TYPE_VIDEO = 'video';
  19.     #[ORM\Id]
  20.     #[ORM\Column(name: 'id', type: 'integer')]
  21.     #[ORM\GeneratedValue(strategy: 'AUTO')]
  22.     protected int $id;
  23.     #[ORM\JoinColumn(name: 'saloon_id', referencedColumnName: 'id')]
  24.     #[ORM\ManyToOne(targetEntity: Saloon::class)]
  25.     protected Saloon $saloon;
  26.     #[ORM\Column(name: 'path', type: 'string', length: 128)]
  27.     #[Groups(['listing', 'preview'])]
  28.     protected string $path;
  29.     #[ORM\Column(name: 'preview_path', type: 'string', length: 128, nullable: true)]
  30.     #[Groups(['preview'])]
  31.     protected ?string $previewPath = null;
  32.     public function __construct(Saloon $saloon, string $path)
  33.     {
  34.         $this->saloon = $saloon;
  35.         $this->path = $path;
  36.     }
  37.     public function getId(): int
  38.     {
  39.         return $this->id;
  40.     }
  41.     public function getPath(): string
  42.     {
  43.         return $this->path;
  44.     }
  45.     public function setPath(string $path): void
  46.     {
  47.         $this->path = $path;
  48.     }
  49.     public function getPreviewPath(): ?string
  50.     {
  51.         return $this->previewPath;
  52.     }
  53.     public function setPreviewPath(?string $previewPath): void
  54.     {
  55.         $this->previewPath = $previewPath;
  56.     }
  57.     #[Groups(['listing', 'preview'])]
  58.     abstract public function getType(): string;
  59. }