<?php
/**
* Created by simpson <simpsonwork@gmail.com>
* Date: 2019-03-21
* Time: 19:52
*/
namespace App\Entity\Profile;
use App\Entity\IMediaFile;
use App\Entity\Profile\Confirmation\ModerationRequest;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Table(name: 'profile_media_files')]
#[ORM\Index(name: 'idx_type', columns: ['type'])]
#[ORM\Index(name: 'idx_profile_type', columns: ['profile_id', 'type'])]
#[ORM\Entity]
#[ORM\InheritanceType('SINGLE_TABLE')]
#[ORM\DiscriminatorColumn(name: 'type', type: 'string', length: 12)]
#[ORM\DiscriminatorMap(['photo' => Photo::class, 'video' => Video::class, 'selfie' => Selfie::class, 'avatar' => Avatar::class, 'adm_apr_ph' => AdminApprovalPhoto::class])]
class Photo implements IMediaFile
{
public const TYPE_PHOTO = 'photo';
public const TYPE_AVATAR = 'avatar';
public const TYPE_SELFIE = 'selfie';
public const TYPE_VIDEO = 'video';
public const TYPE_ADMIN_APPROVAL_PHOTO = 'adm_apr_ph';
#[ORM\Id]
#[ORM\Column(name: 'id', type: 'integer')]
#[ORM\GeneratedValue(strategy: 'AUTO')]
protected int $id;
#[ORM\JoinColumn(name: 'profile_id', referencedColumnName: 'id')]
#[ORM\ManyToOne(targetEntity: Profile::class, inversedBy: 'photos')]
protected Profile $profile;
#[ORM\Column(name: 'path', type: 'string', length: 128)]
protected string $path;
#[ORM\Column(name: 'preview_path', type: 'string', length: 128, nullable: true)]
protected ?string $previewPath = null;
#[ORM\Column(name: 'is_main', type: 'boolean')]
protected bool $main;
/**
* Файл проверен и может появляться на паблике
*/
#[ORM\Column(name: 'is_confirmed', type: 'boolean', nullable: true)]
protected ?bool $confirmed = false;
#[ORM\ManyToOne(targetEntity: ModerationRequest::class)]
#[ORM\JoinColumn(name: 'confirmed_by', referencedColumnName: 'id', nullable: true)]
protected ?ModerationRequest $confirmedBy = null;
public function __construct(Profile $profile, string $path, bool $isMain = false)
{
$this->profile = $profile;
$this->path = $path;
$this->main = $isMain;
}
public function getId(): int
{
return $this->id;
}
public function getPath(): string
{
return $this->path;
}
public function isMain(): bool
{
return $this->main;
}
/**
* Check mail flag
*/
public function setMain(): void
{
$this->main = true;
}
/**
* Uncheck main flag
*/
public function unsetMain(): void
{
$this->main = false;
}
public function getType(): string
{
return self::TYPE_PHOTO;
}
public function setPath(string $path): void
{
$this->path = $path;
}
public function getPreviewPath(): ?string
{
return $this->previewPath;
}
public function setPreviewPath(?string $previewPath): void
{
$this->previewPath = $previewPath;
}
public function isConfirmed(): bool
{
return true === $this->confirmed;
}
public function passModeration(?ModerationRequest $moderationRequest = null): void
{
$this->confirmed = true;
$this->confirmedBy = $moderationRequest;
}
}