src/Entity/VideoEvent.php line 90

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Dto\VideoEventInput;
  5. use App\Repository\VideoEventRepository;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Gedmo\Mapping\Annotation as Gedmo;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. /**
  11.  * @ORM\Entity(repositoryClass=VideoEventRepository::class)
  12.  * @ApiResource(
  13.  *     input=VideoEventInput::class,
  14.  *     routePrefix="dmlkZW9fZXZlbnQ",
  15.  *     normalizationContext={"video_event:read"},
  16.  *     denormalizationContext={"video_event:write"},
  17.  *     collectionOperations={
  18.  *          "post_video_event_update"={
  19.  *              "method"="POST",
  20.  *              "security"="is_granted('ROLE_USER')",
  21.  *              "controller"="App\Controller\Api\VideoEventsController::create",
  22.  *              "path"="/events/update",
  23.  *              "openapi_context"={"summary"="Triggers creation of an event"},
  24.  *              "defaults"={
  25.  *                  "event_type"="App\Entity\VideoEvent::EVENT_UPDATE"
  26.  *              }
  27.  *          },
  28.  *          "post_video_event_play"={
  29.  *              "method"="POST",
  30.  *              "controller"="App\Controller\Api\VideoEventsController::create",
  31.  *              "path"="/events/play",
  32.  *              "security"="is_granted('ROLE_USER')",
  33.  *              "openapi_context"={"summary"="Triggers creation of an event"},
  34.  *              "defaults"={
  35.  *                  "event_type"="App\Entity\VideoEvent::EVENT_PLAY"
  36.  *              }
  37.  *          },
  38.  *          "post_video_event_stop"={
  39.  *              "method"="POST",
  40.  *              "controller"="App\Controller\Api\VideoEventsController::create",
  41.  *              "path"="/events/stop",
  42.  *              "security"="is_granted('ROLE_USER')",
  43.  *              "openapi_context"={"summary"="Triggers creation of an event"},
  44.  *              "defaults"={
  45.  *                  "event_type"="App\Entity\VideoEvent::EVENT_STOP"
  46.  *              }
  47.  *          },
  48.  *          "post_video_event_pause"={
  49.  *              "method"="POST",
  50.  *              "controller"="App\Controller\Api\VideoEventsController::create",
  51.  *              "path"="/events/pause",
  52.  *              "security"="is_granted('ROLE_USER')",
  53.  *              "openapi_context"={"summary"="Triggers creation of an event"},
  54.  *              "defaults"={
  55.  *                  "event_type"="App\Entity\VideoEvent::EVENT_PAUSE"
  56.  *              }
  57.  *          },
  58.  *          "post_video_event_validate"={
  59.  *              "method"="POST",
  60.  *              "controller"="App\Controller\Api\VideoEventsController::create",
  61.  *              "path"="/events/validate",
  62.  *              "security"="is_granted('ROLE_USER')",
  63.  *              "openapi_context"={"summary"="Triggers creation of an event"},
  64.  *              "defaults"={
  65.  *                  "event_type"="App\Entity\VideoEvent::EVENT_VALIDATE"
  66.  *              }
  67.  *          },
  68.  *          "post_video_event_unvalidate"={
  69.  *              "method"="POST",
  70.  *              "controller"="App\Controller\Api\VideoEventsController::create",
  71.  *              "path"="/events/unvalidate",
  72.  *              "security"="is_granted('ROLE_USER')",
  73.  *              "openapi_context"={"summary"="Triggers creation of an event"},
  74.  *              "defaults"={
  75.  *                  "event_type"="App\Entity\VideoEvent::EVENT_UNVALIDATE"
  76.  *              }
  77.  *          }
  78.  *     },
  79.  *     itemOperations={
  80.  *          "get"={
  81.  *              "security"="is_granted('ROLE_ADMIN')",
  82.  *              "path"="/events/{id}"
  83.  *          }
  84.  *     }
  85.  * )
  86.  */
  87. class VideoEvent
  88. {
  89.     const EVENT_PLAY 'play';
  90.     const EVENT_PAUSE 'pause';
  91.     const EVENT_STOP 'stop';
  92.     const EVENT_UPDATE 'update';
  93.     const EVENTS_VIDEOS = [
  94.         self::EVENT_PLAY,
  95.         self::EVENT_PAUSE,
  96.         self::EVENT_STOP,
  97.         self::EVENT_UPDATE,
  98.     ];
  99.     
  100.     const EVENT_UNVALIDATE 'unvalidate';
  101.     const EVENT_VALIDATE 'validate';
  102.     const EVENTS_VALIDATES = [
  103.         self::EVENT_VALIDATE,
  104.         self::EVENT_UNVALIDATE,
  105.     ];
  106.     const VALUES = [
  107.       self::EVENT_PLAY => 1,
  108.       self::EVENT_PAUSE => 0,
  109.       self::EVENT_STOP => 0,
  110.       self::EVENT_UPDATE => 0,
  111.       self::EVENT_VALIDATE => 1,
  112.       self::EVENT_UNVALIDATE => 0,
  113.     ];
  114.     /**
  115.      * @ORM\Id
  116.      * @ORM\GeneratedValue
  117.      * @ORM\Column(type="integer")
  118.      * @Groups({"video_event:read"})
  119.      */
  120.     private $id;
  121.     /**
  122.      * @ORM\Column(type="string", length=255)
  123.      */
  124.     private $type;
  125.     /**
  126.      * @ORM\Column(type="integer")
  127.      */
  128.     private $value 0;
  129.     /**
  130.      * @ORM\Column(type="datetime")
  131.      * @Gedmo\Timestampable(on="create")
  132.      */
  133.     private $createdAt;
  134.     /**
  135.      * @ORM\ManyToOne(targetEntity=Video::class, inversedBy="videoEvents")
  136.      * @ORM\JoinColumn(nullable=false)
  137.      * @Groups({"video_event:write"})
  138.      */
  139.     private $video;
  140.     /**
  141.      * @ORM\ManyToOne(targetEntity=TvUser::class, inversedBy="videoEvents")
  142.      * @ORM\JoinColumn(nullable=true)
  143.      */
  144.     private $tvUser;
  145.     /**
  146.      * @ORM\ManyToOne(targetEntity=User::class, inversedBy="videoEvents")
  147.      * @ORM\JoinColumn(nullable=true)
  148.      * @Assert\NotNull
  149.      */
  150.     private $user;
  151.     /**
  152.      * @ORM\ManyToOne(targetEntity=Playlist::class)
  153.      * @ORM\JoinColumn(nullable=false)
  154.      * @Groups({"video_event:write"})
  155.      */
  156.     private $playlist;
  157.     /**
  158.      * @ORM\Column(type="integer")
  159.      * @Groups({"video_event:write"})
  160.      */
  161.     private $timecode = -1;
  162.     public function getId(): ?int
  163.     {
  164.         return $this->id;
  165.     }
  166.     public function getType(): ?string
  167.     {
  168.         return $this->type;
  169.     }
  170.     public function setType(string $type): self
  171.     {
  172.         $this->type $type;
  173.         return $this;
  174.     }
  175.     public function getValue(): ?int
  176.     {
  177.         return $this->value;
  178.     }
  179.     public function setValue(int $value): self
  180.     {
  181.         $this->value $value;
  182.         return $this;
  183.     }
  184.     public function getCreatedAt(): ?\DateTimeInterface
  185.     {
  186.         return $this->createdAt;
  187.     }
  188.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  189.     {
  190.         $this->createdAt $createdAt;
  191.         return $this;
  192.     }
  193.     public function getVideo(): ?Video
  194.     {
  195.         return $this->video;
  196.     }
  197.     public function setVideo(?Video $video): self
  198.     {
  199.         $this->video $video;
  200.         return $this;
  201.     }
  202.     public function getTvUser(): ?TvUser
  203.     {
  204.         return $this->tvUser;
  205.     }
  206.     public function setTvUser(?TvUser $tvUser): self
  207.     {
  208.         $this->tvUser $tvUser;
  209.         return $this;
  210.     }
  211.     public function getUser(): ?User
  212.     {
  213.         return $this->user;
  214.     }
  215.     public function setUser(?User $user): self
  216.     {
  217.         $this->user $user;
  218.         return $this;
  219.     }
  220.     public function getPlaylist(): ?Playlist
  221.     {
  222.         return $this->playlist;
  223.     }
  224.     public function setPlaylist(?Playlist $playlist): self
  225.     {
  226.         $this->playlist $playlist;
  227.         return $this;
  228.     }
  229.     public function getTimecode(): ?int
  230.     {
  231.         return $this->timecode;
  232.     }
  233.     public function setTimecode(int $timecode): self
  234.     {
  235.         $this->timecode $timecode;
  236.         return $this;
  237.     }
  238. }