src/Entity/Video.php line 29

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity;
  4. use App\Contracts\Video\VideoAvailability;
  5. use App\Repository\VideoRepository;
  6. use DateTime;
  7. use DateTimeImmutable;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Doctrine\Common\Collections\Collection;
  10. use Doctrine\ORM\Mapping\Column;
  11. use Doctrine\ORM\Mapping\Entity;
  12. use Doctrine\ORM\Mapping\GeneratedValue;
  13. use Doctrine\ORM\Mapping\HasLifecycleCallbacks;
  14. use Doctrine\ORM\Mapping\Id;
  15. use Doctrine\ORM\Mapping\ManyToOne;
  16. use Doctrine\ORM\Mapping\OneToMany;
  17. use Doctrine\ORM\Mapping\PrePersist;
  18. use Doctrine\ORM\Mapping\PreUpdate;
  19. use Doctrine\ORM\Mapping\UniqueConstraint;
  20. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  21. #[Entity(VideoRepository::class)]
  22. #[UniqueEntity('externalId''Video is already used')]
  23. #[UniqueConstraint('unique_external_id', ['external_id'])]
  24. #[HasLifecycleCallbacks]
  25. class Video
  26. {
  27.     #[Id]
  28.     #[GeneratedValue]
  29.     #[Column('id''bigint'options: ['unsigned' => true])]
  30.     private ?int $id null;
  31.     #[ManyToOne(targetEntityCreator::class, inversedBy'videoCollection')]
  32.     private Creator $creator;
  33.     #[Column(type'text')]
  34.     private string $url;
  35.     #[Column(type'string')]
  36.     private string $externalId;
  37.     #[Column(type'string')]
  38.     private string $title;
  39.     #[Column(type'text')]
  40.     private string $description;
  41.     #[Column(name'boost_code'type'string'nullabletrueoptions: [
  42.         'comment' => 'Boost code for boosting the video',
  43.     ])]
  44.     private ?string $boostCode;
  45.     #[Column(type'integer')]
  46.     private int $duration;
  47.     #[Column(type'bigint'options: ['unsigned' => true])]
  48.     private int $views;
  49.     #[Column(type'bigint'options: ['unsigned' => true])]
  50.     private int $likes;
  51.     #[Column(type'bigint'options: ['unsigned' => true])]
  52.     private int $comments;
  53.     #[Column(type'bigint'options: ['unsigned' => true])]
  54.     private int $shares;
  55.     #[Column(type'bigint'options: ['unsigned' => true'default' => 0])]
  56.     private int $saves 0;
  57.     #[Column(type'string'length20enumTypeVideoAvailability::class, options: ['default' => VideoAvailability::AVAILABLE->value])]
  58.     private VideoAvailability $availability VideoAvailability::AVAILABLE;
  59.     #[Column(name'unavailable_since'type'datetime_immutable'nullabletrue)]
  60.     private ?DateTimeImmutable $unavailableSince null;
  61.     #[Column(name'unavailable_reason'type'string'length64nullabletrue)]
  62.     private ?string $unavailableReason null;
  63.     #[OneToMany(mappedBy'video'targetEntityVideoStatisticsHistory::class)]
  64.     private Collection $videoStatisticsHistory;
  65.     #[Column(type'datetime')]
  66.     private DateTime $createdAt;
  67.     #[Column(type'datetime')]
  68.     private DateTime $updatedAt;
  69.     #[Column(type'datetime_immutable')]
  70.     private ?DateTimeImmutable $platformCreatedAt null;
  71.     public function __construct()
  72.     {
  73.         $this->videoStatisticsHistory = new ArrayCollection();
  74.     }
  75.     #[PrePersist]
  76.     public function prePersist(): void
  77.     {
  78.         $this->createdAt = new DateTime();
  79.         $this->updatedAt = new DateTime();
  80.     }
  81.     #[PreUpdate]
  82.     public function preUpdate(): void
  83.     {
  84.         $this->updatedAt = new DateTime();
  85.     }
  86.     public function getId(): ?int
  87.     {
  88.         return $this->id;
  89.     }
  90.     public function getCreator(): Creator
  91.     {
  92.         return $this->creator;
  93.     }
  94.     public function setCreator(Creator $creator): static
  95.     {
  96.         $this->creator $creator;
  97.         return $this;
  98.     }
  99.     public function getBoostCode(): ?string
  100.     {
  101.         return $this->boostCode;
  102.     }
  103.     public function setBoostCode(?string $boostCode): static
  104.     {
  105.         $this->boostCode $boostCode;
  106.         return $this;
  107.     }
  108.     public function getExternalId(): string
  109.     {
  110.         return $this->externalId;
  111.     }
  112.     public function setExternalId(string $id): static
  113.     {
  114.         $this->externalId $id;
  115.         return $this;
  116.     }
  117.     public function setUrl(string $url): self
  118.     {
  119.         $this->url $url;
  120.         return $this;
  121.     }
  122.     public function getVideoStatisticsHistory(): Collection
  123.     {
  124.         return $this->videoStatisticsHistory;
  125.     }
  126.     public function getUrl(): string
  127.     {
  128.         return $this->url;
  129.     }
  130.     public function getTitle(): string
  131.     {
  132.         return $this->title;
  133.     }
  134.     public function setTitle(string $title): static
  135.     {
  136.         $this->title $title;
  137.         return $this;
  138.     }
  139.     public function getDescription(): string
  140.     {
  141.         return $this->description;
  142.     }
  143.     public function setDescription(string $description): static
  144.     {
  145.         $this->description $description;
  146.         return $this;
  147.     }
  148.     public function getDuration(): int
  149.     {
  150.         return $this->duration;
  151.     }
  152.     public function setDuration(int $duration): static
  153.     {
  154.         $this->duration $duration;
  155.         return $this;
  156.     }
  157.     public function getViews(): int
  158.     {
  159.         return $this->views;
  160.     }
  161.     public function setViews(int $views): static
  162.     {
  163.         $this->views $views;
  164.         return $this;
  165.     }
  166.     public function getLikes(): int
  167.     {
  168.         return $this->likes;
  169.     }
  170.     public function setLikes(int $likes): static
  171.     {
  172.         $this->likes $likes;
  173.         return $this;
  174.     }
  175.     public function getComments(): int
  176.     {
  177.         return $this->comments;
  178.     }
  179.     public function setComments(int $comments): static
  180.     {
  181.         $this->comments $comments;
  182.         return $this;
  183.     }
  184.     public function getShares(): int
  185.     {
  186.         return $this->shares;
  187.     }
  188.     public function setShares(int $shares): static
  189.     {
  190.         $this->shares $shares;
  191.         return $this;
  192.     }
  193.     public function getSaves(): int
  194.     {
  195.         return $this->saves;
  196.     }
  197.     public function setSaves(int $saves): static
  198.     {
  199.         $this->saves $saves;
  200.         return $this;
  201.     }
  202.     public function getAvailability(): VideoAvailability
  203.     {
  204.         return $this->availability;
  205.     }
  206.     public function isUnavailable(): bool
  207.     {
  208.         return $this->availability === VideoAvailability::UNAVAILABLE;
  209.     }
  210.     public function getUnavailableSince(): ?DateTimeImmutable
  211.     {
  212.         return $this->unavailableSince;
  213.     }
  214.     public function getUnavailableReason(): ?string
  215.     {
  216.         return $this->unavailableReason;
  217.     }
  218.     /** Mark the post as confirmed-gone. Stamps unavailable_since once, never overwrites it. */
  219.     public function markUnavailable(string $reason): static
  220.     {
  221.         $this->availability VideoAvailability::UNAVAILABLE;
  222.         $this->unavailableReason $reason;
  223.         $this->unavailableSince ??= new DateTimeImmutable();
  224.         return $this;
  225.     }
  226.     /** Clear the flag — e.g. a creator un-privated the post and it is fetchable again. */
  227.     public function markAvailable(): static
  228.     {
  229.         $this->availability VideoAvailability::AVAILABLE;
  230.         $this->unavailableSince null;
  231.         $this->unavailableReason null;
  232.         return $this;
  233.     }
  234.     public function setCreatedAt(DateTime $createdAt): static
  235.     {
  236.         $this->createdAt $createdAt;
  237.         return $this;
  238.     }
  239.     public function getCreatedAt(): DateTime
  240.     {
  241.         return $this->createdAt;
  242.     }
  243.     public function setUpdatedAt(DateTime $updatedAt): static
  244.     {
  245.         $this->updatedAt $updatedAt;
  246.         return $this;
  247.     }
  248.     public function getUpdatedAt(): DateTime
  249.     {
  250.         return $this->updatedAt;
  251.     }
  252.     public function getPlatformCreatedAt(): ?DateTimeImmutable
  253.     {
  254.         return $this->platformCreatedAt;
  255.     }
  256.     public function setPlatformCreatedAt(?DateTimeImmutable $platformCreatedAt): static
  257.     {
  258.         $this->platformCreatedAt $platformCreatedAt;
  259.         return $this;
  260.     }
  261. }