src/Entity/Profile/Photo.php line 21

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