diff --git a/public/css/dashboard.css b/public/css/dashboard.css index 764af49..f517cb1 100644 --- a/public/css/dashboard.css +++ b/public/css/dashboard.css @@ -117,4 +117,11 @@ bottom: 0; height: 2%; background-color: lightgrey; +} + +.views { + position: absolute; + font-size: 1vw; + top: 69%; + right: 10%; } \ No newline at end of file diff --git a/public/css/watch.css b/public/css/watch.css index 413aa0e..26e4f75 100644 --- a/public/css/watch.css +++ b/public/css/watch.css @@ -12,8 +12,8 @@ #set { position: absolute; - top: 0px; - right: 0px; + top: 0; + right: 0; width: 23.5%; min-height: 100px; padding: 1%; @@ -22,4 +22,11 @@ #description { width: 73.5%; padding: 1%; + position: relative; +} + +.views { + position: absolute; + top: 7%; + right: 3%; } \ No newline at end of file diff --git a/src/Controller/DashboardController.php b/src/Controller/DashboardController.php index 0769858..080f780 100644 --- a/src/Controller/DashboardController.php +++ b/src/Controller/DashboardController.php @@ -9,6 +9,7 @@ use App\Entity\VideoLink; use App\Form\VideoLinkType; use App\Form\VideoType; use App\Mapper\CustomUuidMapper; +use App\Service\LoggingService; use App\Service\UserService; use App\Service\VideoLinkService; use App\Service\VideoService; @@ -27,6 +28,7 @@ class DashboardController extends AbstractController private $userService; private $videoService; private $videoLinkService; + private $loggingService; private $uuidMapper; @@ -34,12 +36,14 @@ class DashboardController extends AbstractController UserService $userService, VideoService $videoService, VideoLinkService $videoLinkService, + LoggingService $loggingService, CustomUuidMapper $uuidMapper ) { $this->userService = $userService; $this->videoService = $videoService; $this->videoLinkService = $videoLinkService; + $this->loggingService = $loggingService; $this->uuidMapper = $uuidMapper; } @@ -58,6 +62,7 @@ class DashboardController extends AbstractController foreach ($videos as $video) { $video->setCustomId($this->uuidMapper->toString($video->getId())); + $video->setViews($this->loggingService->getViews($video)); } return $this->render("dashboard/dashboard.html.twig", [ @@ -169,7 +174,6 @@ class DashboardController extends AbstractController try { $videoId = $this->uuidMapper->fromString($videoId); } catch (ConversionException $e) { - return new Response($videoId); return $this->redirectToRoute("app_links"); } diff --git a/src/Controller/WatchController.php b/src/Controller/WatchController.php index 7ef51c6..46a9871 100644 --- a/src/Controller/WatchController.php +++ b/src/Controller/WatchController.php @@ -2,7 +2,6 @@ namespace App\Controller; -use App\Entity\User; use App\Entity\Video; use App\Entity\VideoLink; use App\Mapper\CustomUuidMapper; @@ -55,7 +54,7 @@ class WatchController extends AbstractController $this->uuidMapper = $uuidMapper; } - private function isAllowed(?Video $video, ?User $user, VideoLink $link): int + private function isAllowed(?Video $video, VideoLink $link): int { if (!$link) { return self::NOT_ALLOWED; @@ -85,7 +84,7 @@ class WatchController extends AbstractController if (!$allowed) { $link = $this->videoLinkService->get($this->uuidMapper->fromString($linkId)); - $allowed = $this->isAllowed($video, $user, $link); + $allowed = $this->isAllowed($video, $link); } } catch (ConversionException $e) { throw new AccessDeniedHttpException(); @@ -200,6 +199,7 @@ class WatchController extends AbstractController } $data["video"]->setCustomId($videoId); + $data["video"]->setViews($this->loggingService->getViews($data["video"])); return $this->render("watch/watch.html.twig", [ "viewToken" => $viewToken, diff --git a/src/Entity/Video.php b/src/Entity/Video.php index 979088b..9bfcab4 100644 --- a/src/Entity/Video.php +++ b/src/Entity/Video.php @@ -77,6 +77,8 @@ class Video */ private $transcodingProgress = 0; + private $views = 0; + public function __construct() { $this->videoLinks = new ArrayCollection(); @@ -241,4 +243,15 @@ class Video return $this; } + + public function getViews(): ?int + { + return $this->views; + } + + public function setViews(int $views): self + { + $this->views = $views; + return $this; + } } diff --git a/src/Repository/ViewRepository.php b/src/Repository/ViewRepository.php index 9e8203d..4717d82 100644 --- a/src/Repository/ViewRepository.php +++ b/src/Repository/ViewRepository.php @@ -2,6 +2,7 @@ namespace App\Repository; +use App\Entity\Video; use App\Entity\View; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Persistence\ManagerRegistry; @@ -58,4 +59,14 @@ class ViewRepository extends ServiceEntityRepository { $this->_em->flush(); } + + public function countForVideo(Video $video): int + { + $qb = $this->createQueryBuilder("v"); + return $qb->select("count(v.id)") + ->andWhere("v.video = :video") + ->setParameter("video", $video->getId()->getBytes()) + ->andWhere($qb->expr()->isNotNull("v.validated")) + ->getQuery()->getSingleScalarResult(); + } } diff --git a/src/Service/LoggingService.php b/src/Service/LoggingService.php index 52960f2..72eba95 100644 --- a/src/Service/LoggingService.php +++ b/src/Service/LoggingService.php @@ -54,4 +54,10 @@ class LoggingService return true; } + + public function getViews(Video $video): int + { + //return $this->viewRepository->countByVideoAndNotNullValidated($video); + return $this->viewRepository->countForVideo($video); + } } \ No newline at end of file diff --git a/templates/dashboard/dashboard.html.twig b/templates/dashboard/dashboard.html.twig index 0758e90..8370c6f 100644 --- a/templates/dashboard/dashboard.html.twig +++ b/templates/dashboard/dashboard.html.twig @@ -70,6 +70,9 @@
{{ video.description }}
diff --git a/templates/watch/watch.html.twig b/templates/watch/watch.html.twig index 2c16048..3199f38 100644 --- a/templates/watch/watch.html.twig +++ b/templates/watch/watch.html.twig @@ -67,6 +67,9 @@{{ video.description }}