src/Entity/Profile/Photo.php line 22

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by simpson <simpsonwork@gmail.com>
  4.  * Date: 2019-03-21
  5.  * Time: 19:52
  6.  */
  7. namespace App\Entity\Profile;
  8. use App\Entity\IMediaFile;
  9. use App\Entity\Profile\Confirmation\ModerationRequest;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. #[ORM\Table(name'profile_media_files')]
  13. #[ORM\Index(name'idx_type'columns: ['type'])]
  14. #[ORM\Index(name'idx_profile_type'columns: ['profile_id''type'])]
  15. #[ORM\Entity]
  16. #[ORM\InheritanceType('SINGLE_TABLE')]
  17. #[ORM\DiscriminatorColumn(name'type'type'string'length12)]
  18. #[ORM\DiscriminatorMap(['photo' => Photo::class, 'video' => Video::class, 'selfie' => Selfie::class, 'avatar' => Avatar::class, 'adm_apr_ph' => AdminApprovalPhoto::class])]
  19. class Photo implements IMediaFile
  20. {
  21.     public const TYPE_PHOTO 'photo';
  22.     public const TYPE_AVATAR 'avatar';
  23.     public const TYPE_SELFIE 'selfie';
  24.     public const TYPE_VIDEO 'video';
  25.     public const TYPE_ADMIN_APPROVAL_PHOTO 'adm_apr_ph';
  26.     #[ORM\Id]
  27.     #[ORM\Column(name'id'type'integer')]
  28.     #[ORM\GeneratedValue(strategy'AUTO')]
  29.     protected int $id;
  30.     #[ORM\JoinColumn(name'profile_id'referencedColumnName'id')]
  31.     #[ORM\ManyToOne(targetEntityProfile::class, inversedBy'photos')]
  32.     protected Profile $profile;
  33.     #[ORM\Column(name'path'type'string'length128)]
  34.     #[Groups(['listing''preview'])]
  35.     protected string $path;
  36.     #[ORM\Column(name'preview_path'type'string'length128nullabletrue)]
  37.     #[Groups(['preview'])]
  38.     protected ?string $previewPath null;
  39.     #[ORM\Column(name'is_main'type'boolean')]
  40.     protected bool $main;
  41.     /**
  42.      * Файл проверен и может появляться на паблике
  43.      */
  44.     #[ORM\Column(name'is_confirmed'type'boolean'nullabletrue)]
  45.     protected ?bool $confirmed false;
  46.     #[ORM\ManyToOne(targetEntityModerationRequest::class)]
  47.     #[ORM\JoinColumn(name'confirmed_by'referencedColumnName'id'nullabletrue)]
  48.     protected ?ModerationRequest $confirmedBy null;
  49.     public function __construct(Profile $profilestring $pathbool $isMain false)
  50.     {
  51.         $this->profile $profile;
  52.         $this->path $path;
  53.         $this->main $isMain;
  54.     }
  55.     public function getId(): int
  56.     {
  57.         return $this->id;
  58.     }
  59.     public function getPath(): string
  60.     {
  61.         return $this->path;
  62.     }
  63.     public function isMain(): bool
  64.     {
  65.         return $this->main;
  66.     }
  67.     /**
  68.      * Check mail flag
  69.      */
  70.     public function setMain(): void
  71.     {
  72.         $this->main true;
  73.     }
  74.     /**
  75.      * Uncheck main flag
  76.      */
  77.     public function unsetMain(): void
  78.     {
  79.         $this->main false;
  80.     }
  81.     #[Groups(['listing''preview'])]
  82.     public function getType(): string
  83.     {
  84.         return self::TYPE_PHOTO;
  85.     }
  86.     public function setPath(string $path): void
  87.     {
  88.         $this->path $path;
  89.     }
  90.     public function getPreviewPath(): ?string
  91.     {
  92.         return $this->previewPath;
  93.     }
  94.     public function setPreviewPath(?string $previewPath): void
  95.     {
  96.         $this->previewPath $previewPath;
  97.     }
  98.     public function isConfirmed(): bool
  99.     {
  100.         return true === $this->confirmed;
  101.     }
  102.     public function passModeration(?ModerationRequest $moderationRequest null): void
  103.     {
  104.         $this->confirmed true;
  105.         $this->confirmedBy $moderationRequest;
  106.     }
  107. }