src/Entity/Profile/Confirmation/ConfirmationRequest.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Profile\Confirmation;
  3. use App\Entity\Profile\Profile;
  4. use Carbon\CarbonImmutable;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Doctrine\ORM\PersistentCollection;
  9. #[ORM\Table(name'profile_confirmation_requests')]
  10. #[ORM\Entity]
  11. #[ORM\InheritanceType('SINGLE_TABLE')]
  12. #[ORM\DiscriminatorColumn(name'type'type'string'length12)]
  13. #[ORM\DiscriminatorMap(['approval' => ApprovalRequest::class, 'moderation' => ModerationRequest::class])]
  14. abstract class ConfirmationRequest
  15. {
  16.     /**
  17.      * Ожидает завершения системных процессов, чтобы перейти в статус WAITING
  18.      */
  19.     public const STATUS_PROCESSING 'PROCESSING';
  20.     /**
  21.      * Ожидает действий модератора
  22.      */
  23.     public const STATUS_WAITING 'WAITING';
  24.     public const STATUS_REJECTED 'REJECTED';
  25.     public const STATUS_APPROVED 'APPROVED';
  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)]
  32.     protected Profile $profile;
  33.     #[ORM\Column(type'string'columnDefinition"ENUM('PROCESSING', 'WAITING', 'REJECTED', 'APPROVED')")]
  34.     protected string $status;
  35.     #[ORM\Column(type'integer'nullabletrue)]
  36.     protected ?int $reason;
  37.     #[ORM\Column(type'string'nullabletrue)]
  38.     protected ?string $comment;
  39.     #[ORM\Column(type'json'nullabletrue)]
  40.     protected ?array $data;
  41.     #[ORM\Column(name'face_photo_path'type'string'length128nullabletrue)]
  42.     protected ?string $facePhotoPath null;
  43.     /** @var Photo[] */
  44.     #[ORM\OneToMany(targetEntityPhoto::class, mappedBy'confirmationRequest'cascade: ['all'], orphanRemovaltrue)]
  45.     protected Collection $photos;
  46.     /** @var PersistentCollection|Video[] */
  47.     #[ORM\OneToMany(targetEntityVideo::class, mappedBy'confirmationRequest'cascade: ['all'], orphanRemovaltrue)]
  48.     protected Collection $videos;
  49.     #[ORM\Column(name'updated_at'type'datetimetz_immutable'nullabletrue)]
  50.     protected ?\DateTimeImmutable $updatedAt;
  51.     public function __construct(Profile $profile)
  52.     {
  53.         $this->profile $profile;
  54.         $this->updatedAt CarbonImmutable::now();
  55.         $this->status self::STATUS_WAITING;
  56.         $this->photos = new ArrayCollection();
  57.         $this->videos = new ArrayCollection();
  58.         $this->data null;
  59.     }
  60.     public function checkProcessingFiles(): void
  61.     {
  62.         if ($this->profile->hasFilesInProcess()) {
  63.             $this->status self::STATUS_PROCESSING;
  64.         }
  65.     }
  66.     public function getId(): int
  67.     {
  68.         return $this->id;
  69.     }
  70.     public function getProfile(): Profile
  71.     {
  72.         return $this->profile;
  73.     }
  74.     public function setProfile(Profile $profile): void
  75.     {
  76.         $this->profile $profile;
  77.     }
  78.     public function getStatus(): string
  79.     {
  80.         return $this->status;
  81.     }
  82.     public function setStatus(string $status): void
  83.     {
  84.         $this->status $status;
  85.     }
  86.     public function getUpdatedAt(): \DateTimeImmutable
  87.     {
  88.         return $this->updatedAt;
  89.     }
  90.     public function setUpdatedAt(\DateTimeImmutable $updatedAt): void
  91.     {
  92.         $this->updatedAt $updatedAt;
  93.     }
  94.     public function finishProcessing(): void
  95.     {
  96.         if (self::STATUS_PROCESSING === $this->status) {
  97.             $this->status self::STATUS_WAITING;
  98.         }
  99.     }
  100.     public function isWaiting(): bool
  101.     {
  102.         return $this->status === self::STATUS_WAITING || $this->status === self::STATUS_PROCESSING;
  103.     }
  104.     public function isApproved(): bool
  105.     {
  106.         return $this->status == self::STATUS_APPROVED;
  107.     }
  108.     public function isRejected(): bool
  109.     {
  110.         return $this->status == self::STATUS_REJECTED;
  111.     }
  112. //    public function isApprovalRejected(): bool
  113. //    {
  114. //        return $this->approvalRequest && $this->approvalRequest->getStatus() == ApprovalRequest::STATUS_REJECTED;
  115. //    }
  116.     public function approve(): void
  117.     {
  118.         $this->status self::STATUS_APPROVED;
  119.         $this->updatedAt CarbonImmutable::now();
  120.     }
  121.     public function reject(?int $reason null, ?string $comment null): void
  122.     {
  123.         $this->status self::STATUS_REJECTED;
  124.         $this->updatedAt CarbonImmutable::now();
  125.         if($reason) {
  126.             $this->reason $reason;
  127.             if ($comment)
  128.                 $this->comment $comment;
  129.         }
  130.     }
  131.     public function setReason(int $reason): void
  132.     {
  133.         $this->reason $reason;
  134.     }
  135.     public function setComment(?string $comment): void
  136.     {
  137.         $this->comment $comment;
  138.     }
  139.     public function getPhoto(): ?Photo
  140.     {
  141.         return $this->photos->count() ? $this->photos->first() : null;
  142.     }
  143.     public function setPhoto(Photo $photo): void
  144.     {
  145.         $this->photos->clear();
  146.         $this->photos->add($photo);
  147.     }
  148.     public function getVideo(): ?Video
  149.     {
  150.         return $this->videos->count() ? $this->videos->first() : null;
  151.     }
  152.     public function setVideo(Video $video): void
  153.     {
  154.         $this->videos->clear();
  155.         $this->videos->add($video);
  156.     }
  157.     public function getFacePhotoPath(): ?string
  158.     {
  159.         return $this->facePhotoPath;
  160.     }
  161.     public function setFacePhotoPath(?string $facePhotoPath): void
  162.     {
  163.         $this->facePhotoPath $facePhotoPath;
  164.     }
  165.     public function isMediaProcessed(): bool
  166.     {
  167.         if (self::STATUS_PROCESSING === $this->status) {
  168.             return false;
  169.         }
  170.         if (null === $this->getVideo()) {
  171.             return true;
  172.         }
  173.         return null !== $this->getVideo()->getPreviewPath();
  174.     }
  175.     public function isProfileMediaProcessed(): bool
  176.     {
  177.         if (self::STATUS_PROCESSING === $this->status) {
  178.             return false;
  179.         }
  180.         foreach ($this->profile->getVideos() as $video) {
  181.             if (null === $video->getPreviewPath()) {
  182.                 return false;
  183.             }
  184.         }
  185.         return true;
  186.     }
  187.     public function getData(): ?array
  188.     {
  189.         return $this->data;
  190.     }
  191.     public function setData(?array $data): void
  192.     {
  193.         $this->data $data;
  194.     }
  195. }