<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Dto\VideoEventInput;
use App\Repository\VideoEventRepository;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass=VideoEventRepository::class)
* @ApiResource(
* input=VideoEventInput::class,
* routePrefix="dmlkZW9fZXZlbnQ",
* normalizationContext={"video_event:read"},
* denormalizationContext={"video_event:write"},
* collectionOperations={
* "post_video_event_update"={
* "method"="POST",
* "security"="is_granted('ROLE_USER')",
* "controller"="App\Controller\Api\VideoEventsController::create",
* "path"="/events/update",
* "openapi_context"={"summary"="Triggers creation of an event"},
* "defaults"={
* "event_type"="App\Entity\VideoEvent::EVENT_UPDATE"
* }
* },
* "post_video_event_play"={
* "method"="POST",
* "controller"="App\Controller\Api\VideoEventsController::create",
* "path"="/events/play",
* "security"="is_granted('ROLE_USER')",
* "openapi_context"={"summary"="Triggers creation of an event"},
* "defaults"={
* "event_type"="App\Entity\VideoEvent::EVENT_PLAY"
* }
* },
* "post_video_event_stop"={
* "method"="POST",
* "controller"="App\Controller\Api\VideoEventsController::create",
* "path"="/events/stop",
* "security"="is_granted('ROLE_USER')",
* "openapi_context"={"summary"="Triggers creation of an event"},
* "defaults"={
* "event_type"="App\Entity\VideoEvent::EVENT_STOP"
* }
* },
* "post_video_event_pause"={
* "method"="POST",
* "controller"="App\Controller\Api\VideoEventsController::create",
* "path"="/events/pause",
* "security"="is_granted('ROLE_USER')",
* "openapi_context"={"summary"="Triggers creation of an event"},
* "defaults"={
* "event_type"="App\Entity\VideoEvent::EVENT_PAUSE"
* }
* },
* "post_video_event_validate"={
* "method"="POST",
* "controller"="App\Controller\Api\VideoEventsController::create",
* "path"="/events/validate",
* "security"="is_granted('ROLE_USER')",
* "openapi_context"={"summary"="Triggers creation of an event"},
* "defaults"={
* "event_type"="App\Entity\VideoEvent::EVENT_VALIDATE"
* }
* },
* "post_video_event_unvalidate"={
* "method"="POST",
* "controller"="App\Controller\Api\VideoEventsController::create",
* "path"="/events/unvalidate",
* "security"="is_granted('ROLE_USER')",
* "openapi_context"={"summary"="Triggers creation of an event"},
* "defaults"={
* "event_type"="App\Entity\VideoEvent::EVENT_UNVALIDATE"
* }
* }
* },
* itemOperations={
* "get"={
* "security"="is_granted('ROLE_ADMIN')",
* "path"="/events/{id}"
* }
* }
* )
*/
class VideoEvent
{
const EVENT_PLAY = 'play';
const EVENT_PAUSE = 'pause';
const EVENT_STOP = 'stop';
const EVENT_UPDATE = 'update';
const EVENTS_VIDEOS = [
self::EVENT_PLAY,
self::EVENT_PAUSE,
self::EVENT_STOP,
self::EVENT_UPDATE,
];
const EVENT_UNVALIDATE = 'unvalidate';
const EVENT_VALIDATE = 'validate';
const EVENTS_VALIDATES = [
self::EVENT_VALIDATE,
self::EVENT_UNVALIDATE,
];
const VALUES = [
self::EVENT_PLAY => 1,
self::EVENT_PAUSE => 0,
self::EVENT_STOP => 0,
self::EVENT_UPDATE => 0,
self::EVENT_VALIDATE => 1,
self::EVENT_UNVALIDATE => 0,
];
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"video_event:read"})
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $type;
/**
* @ORM\Column(type="integer")
*/
private $value = 0;
/**
* @ORM\Column(type="datetime")
* @Gedmo\Timestampable(on="create")
*/
private $createdAt;
/**
* @ORM\ManyToOne(targetEntity=Video::class, inversedBy="videoEvents")
* @ORM\JoinColumn(nullable=false)
* @Groups({"video_event:write"})
*/
private $video;
/**
* @ORM\ManyToOne(targetEntity=TvUser::class, inversedBy="videoEvents")
* @ORM\JoinColumn(nullable=true)
*/
private $tvUser;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="videoEvents")
* @ORM\JoinColumn(nullable=true)
* @Assert\NotNull
*/
private $user;
/**
* @ORM\ManyToOne(targetEntity=Playlist::class)
* @ORM\JoinColumn(nullable=false)
* @Groups({"video_event:write"})
*/
private $playlist;
/**
* @ORM\Column(type="integer")
* @Groups({"video_event:write"})
*/
private $timecode = -1;
public function getId(): ?int
{
return $this->id;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(string $type): self
{
$this->type = $type;
return $this;
}
public function getValue(): ?int
{
return $this->value;
}
public function setValue(int $value): self
{
$this->value = $value;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getVideo(): ?Video
{
return $this->video;
}
public function setVideo(?Video $video): self
{
$this->video = $video;
return $this;
}
public function getTvUser(): ?TvUser
{
return $this->tvUser;
}
public function setTvUser(?TvUser $tvUser): self
{
$this->tvUser = $tvUser;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getPlaylist(): ?Playlist
{
return $this->playlist;
}
public function setPlaylist(?Playlist $playlist): self
{
$this->playlist = $playlist;
return $this;
}
public function getTimecode(): ?int
{
return $this->timecode;
}
public function setTimecode(int $timecode): self
{
$this->timecode = $timecode;
return $this;
}
}