diff --git a/public/css/dashboard.css b/public/css/dashboard.css index 7ef3a9a..c73ddc2 100644 --- a/public/css/dashboard.css +++ b/public/css/dashboard.css @@ -54,7 +54,7 @@ } .info { - padding: 1vw; + padding: 2% 4% 4%; } .disable { @@ -81,4 +81,18 @@ width: 100%; top: 55%; color: lightgray; +} + +.link { + position: absolute; + top: calc(9 / 16 * 100% + 12%); + right: 3%; +} + +.link a { + color: #9f44b4; +} + +.link:hover a { + color: grey; } \ No newline at end of file diff --git a/src/Controller/DashboardController.php b/src/Controller/DashboardController.php index b1352d4..76e5fb0 100644 --- a/src/Controller/DashboardController.php +++ b/src/Controller/DashboardController.php @@ -5,11 +5,14 @@ namespace App\Controller; use App\Entity\Video; +use App\Entity\VideoLink; use App\Form\VideoLinkType; +use App\Form\VideoType; use App\Mapper\CustomUuidMapper; use App\Service\UserService; use App\Service\VideoLinkService; use App\Service\VideoService; +use Doctrine\DBAL\Types\ConversionException; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Form\FormError; use Symfony\Component\HttpFoundation\Request; @@ -70,7 +73,7 @@ class DashboardController extends AbstractController } $video = new Video(); - $form = $this->createForm(VideoLinkType::class, $video); + $form = $this->createForm(VideoType::class, $video); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { @@ -81,6 +84,8 @@ class DashboardController extends AbstractController $form->addError(new FormError("")); } else { $this->videoService->addVideo($video, $file); + + return $this->redirectToRoute("app_dashboard"); } } @@ -92,7 +97,7 @@ class DashboardController extends AbstractController /** * @Route("/links", name="app_links") */ - public function links(): Response + public function showLinks(): Response { if (!$this->isGranted("ROLE_USER")) { // not logged in @@ -106,4 +111,56 @@ class DashboardController extends AbstractController "links" => $links ]); } + + /** + * @Route("/links/new", name="app_new_link") + */ + public function newLink(Request $request): Response + { + if (!$this->isGranted("ROLE_USER")) { + // not logged in + return $this->redirectToRoute("app_login"); + } + + $videoId = $request->query->get("video"); + if (!$videoId) { + return $this->redirectToRoute("app_links"); + } + + try { + $videoId = $this->uuidMapper->fromString($videoId); + } catch (ConversionException $e) { + return $this->redirectToRoute("app_links"); + } + + $video = $this->videoService->get($videoId); + if (!$video) { + return $this->redirectToRoute("app_dashboard"); + } + + $videoLink = new VideoLink(); + $videoLink->setVideo($video); + $form = $this->createForm(VideoLinkType::class, $videoLink); + + $form->handleRequest($request); + if ($form->isSubmitted() && $form->isValid()) { + $videoLink = $form->getData(); + + $user = $this->userService->getLoggedInUser(); + $videoLink->setCreator($user); + + $videoLink->setCreated(); + + $this->videoLinkService->add($videoLink); + + return $this->redirectToRoute("app_links"); + } + + $video->setCustomId($this->uuidMapper->toString($video->getId())); + + return $this->render("dashboard/newlink.html.twig", [ + "video" => $video, + "form" => $form->createView() + ]); + } } \ No newline at end of file diff --git a/src/Entity/VideoLink.php b/src/Entity/VideoLink.php index 7b5b4c9..e859ead 100644 --- a/src/Entity/VideoLink.php +++ b/src/Entity/VideoLink.php @@ -83,9 +83,9 @@ class VideoLink return $this->created; } - public function setCreated(DateTimeImmutable $created): self + public function setCreated(): self { - $this->created = $created; + $this->created = new DateTimeImmutable(); return $this; } @@ -102,7 +102,7 @@ class VideoLink return $this; } - public function getViewableUntil(): DateTime + public function getViewableUntil(): ?DateTime { return $this->viewableUntil; } @@ -113,7 +113,7 @@ class VideoLink return $this; } - public function getViewableFor(): int + public function getViewableFor(): ?int { return $this->viewableFor; } diff --git a/src/Form/VideoLinkType.php b/src/Form/VideoLinkType.php index 26901eb..529a3d1 100644 --- a/src/Form/VideoLinkType.php +++ b/src/Form/VideoLinkType.php @@ -6,7 +6,10 @@ namespace App\Form; use App\Entity\VideoLink; use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\Extension\Core\Type\DateType; +use Symfony\Component\Form\Extension\Core\Type\NumberType; use Symfony\Component\Form\Extension\Core\Type\SubmitType; +use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -15,6 +18,18 @@ class VideoLinkType extends AbstractType public function buildForm(FormBuilderInterface $builder, $options): void { $builder + ->add("maxViews", NumberType::class, [ + "required" => false + ]) + ->add("viewableFor", NumberType::class, [ + "required" => false + ]) + ->add("viewableUntil", DateType::class, [ + "required" => false + ]) + ->add("comment", TextType::class, [ + "required" => false + ]) ->add("submit", SubmitType::class); } diff --git a/src/Repository/VideoLinkRepository.php b/src/Repository/VideoLinkRepository.php index d951bbc..465c4c0 100644 --- a/src/Repository/VideoLinkRepository.php +++ b/src/Repository/VideoLinkRepository.php @@ -47,4 +47,15 @@ class VideoLinkRepository extends ServiceEntityRepository ; } */ + + public function save(VideoLink $videoLink) + { + $this->_em->persist($videoLink); + $this->_em->flush(); + } + + public function update() + { + $this->_em->flush(); + } } diff --git a/src/Service/VideoLinkService.php b/src/Service/VideoLinkService.php index 799a619..8db367d 100644 --- a/src/Service/VideoLinkService.php +++ b/src/Service/VideoLinkService.php @@ -26,4 +26,9 @@ class VideoLinkService { return $this->videoLinkRepository->findByCreator($user); } + + public function add($videoLink): void + { + $this->videoLinkRepository->save($videoLink); + } } \ No newline at end of file diff --git a/templates/dashboard/dashboard.html.twig b/templates/dashboard/dashboard.html.twig index d67b298..1f3a15f 100644 --- a/templates/dashboard/dashboard.html.twig +++ b/templates/dashboard/dashboard.html.twig @@ -27,6 +27,11 @@ {% endif %}
{{ video.description }}
diff --git a/templates/dashboard/newlink.html.twig b/templates/dashboard/newlink.html.twig
new file mode 100644
index 0000000..a7b1095
--- /dev/null
+++ b/templates/dashboard/newlink.html.twig
@@ -0,0 +1,16 @@
+{% extends 'base.html.twig' %}
+
+{% block title %}Links{% endblock %}
+{% block stylesheets %}
+
+{% endblock %}
+
+{% block body %}
+
+ {{ video.name }}
+
+ {{ form(form) }}
+{% endblock %}
\ No newline at end of file