mirror of
https://github.com/sigmasternchen/MyTube
synced 2025-03-15 21:08:55 +00:00
added view counter
This commit is contained in:
parent
6e5ac1b55c
commit
db66c98976
9 changed files with 60 additions and 6 deletions
|
@ -117,4 +117,11 @@
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
height: 2%;
|
height: 2%;
|
||||||
background-color: lightgrey;
|
background-color: lightgrey;
|
||||||
|
}
|
||||||
|
|
||||||
|
.views {
|
||||||
|
position: absolute;
|
||||||
|
font-size: 1vw;
|
||||||
|
top: 69%;
|
||||||
|
right: 10%;
|
||||||
}
|
}
|
|
@ -12,8 +12,8 @@
|
||||||
|
|
||||||
#set {
|
#set {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0px;
|
top: 0;
|
||||||
right: 0px;
|
right: 0;
|
||||||
width: 23.5%;
|
width: 23.5%;
|
||||||
min-height: 100px;
|
min-height: 100px;
|
||||||
padding: 1%;
|
padding: 1%;
|
||||||
|
@ -22,4 +22,11 @@
|
||||||
#description {
|
#description {
|
||||||
width: 73.5%;
|
width: 73.5%;
|
||||||
padding: 1%;
|
padding: 1%;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.views {
|
||||||
|
position: absolute;
|
||||||
|
top: 7%;
|
||||||
|
right: 3%;
|
||||||
}
|
}
|
|
@ -9,6 +9,7 @@ use App\Entity\VideoLink;
|
||||||
use App\Form\VideoLinkType;
|
use App\Form\VideoLinkType;
|
||||||
use App\Form\VideoType;
|
use App\Form\VideoType;
|
||||||
use App\Mapper\CustomUuidMapper;
|
use App\Mapper\CustomUuidMapper;
|
||||||
|
use App\Service\LoggingService;
|
||||||
use App\Service\UserService;
|
use App\Service\UserService;
|
||||||
use App\Service\VideoLinkService;
|
use App\Service\VideoLinkService;
|
||||||
use App\Service\VideoService;
|
use App\Service\VideoService;
|
||||||
|
@ -27,6 +28,7 @@ class DashboardController extends AbstractController
|
||||||
private $userService;
|
private $userService;
|
||||||
private $videoService;
|
private $videoService;
|
||||||
private $videoLinkService;
|
private $videoLinkService;
|
||||||
|
private $loggingService;
|
||||||
|
|
||||||
private $uuidMapper;
|
private $uuidMapper;
|
||||||
|
|
||||||
|
@ -34,12 +36,14 @@ class DashboardController extends AbstractController
|
||||||
UserService $userService,
|
UserService $userService,
|
||||||
VideoService $videoService,
|
VideoService $videoService,
|
||||||
VideoLinkService $videoLinkService,
|
VideoLinkService $videoLinkService,
|
||||||
|
LoggingService $loggingService,
|
||||||
CustomUuidMapper $uuidMapper
|
CustomUuidMapper $uuidMapper
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
$this->userService = $userService;
|
$this->userService = $userService;
|
||||||
$this->videoService = $videoService;
|
$this->videoService = $videoService;
|
||||||
$this->videoLinkService = $videoLinkService;
|
$this->videoLinkService = $videoLinkService;
|
||||||
|
$this->loggingService = $loggingService;
|
||||||
$this->uuidMapper = $uuidMapper;
|
$this->uuidMapper = $uuidMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,6 +62,7 @@ class DashboardController extends AbstractController
|
||||||
|
|
||||||
foreach ($videos as $video) {
|
foreach ($videos as $video) {
|
||||||
$video->setCustomId($this->uuidMapper->toString($video->getId()));
|
$video->setCustomId($this->uuidMapper->toString($video->getId()));
|
||||||
|
$video->setViews($this->loggingService->getViews($video));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->render("dashboard/dashboard.html.twig", [
|
return $this->render("dashboard/dashboard.html.twig", [
|
||||||
|
@ -169,7 +174,6 @@ class DashboardController extends AbstractController
|
||||||
try {
|
try {
|
||||||
$videoId = $this->uuidMapper->fromString($videoId);
|
$videoId = $this->uuidMapper->fromString($videoId);
|
||||||
} catch (ConversionException $e) {
|
} catch (ConversionException $e) {
|
||||||
return new Response($videoId);
|
|
||||||
return $this->redirectToRoute("app_links");
|
return $this->redirectToRoute("app_links");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
namespace App\Controller;
|
namespace App\Controller;
|
||||||
|
|
||||||
use App\Entity\User;
|
|
||||||
use App\Entity\Video;
|
use App\Entity\Video;
|
||||||
use App\Entity\VideoLink;
|
use App\Entity\VideoLink;
|
||||||
use App\Mapper\CustomUuidMapper;
|
use App\Mapper\CustomUuidMapper;
|
||||||
|
@ -55,7 +54,7 @@ class WatchController extends AbstractController
|
||||||
$this->uuidMapper = $uuidMapper;
|
$this->uuidMapper = $uuidMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function isAllowed(?Video $video, ?User $user, VideoLink $link): int
|
private function isAllowed(?Video $video, VideoLink $link): int
|
||||||
{
|
{
|
||||||
if (!$link) {
|
if (!$link) {
|
||||||
return self::NOT_ALLOWED;
|
return self::NOT_ALLOWED;
|
||||||
|
@ -85,7 +84,7 @@ class WatchController extends AbstractController
|
||||||
|
|
||||||
if (!$allowed) {
|
if (!$allowed) {
|
||||||
$link = $this->videoLinkService->get($this->uuidMapper->fromString($linkId));
|
$link = $this->videoLinkService->get($this->uuidMapper->fromString($linkId));
|
||||||
$allowed = $this->isAllowed($video, $user, $link);
|
$allowed = $this->isAllowed($video, $link);
|
||||||
}
|
}
|
||||||
} catch (ConversionException $e) {
|
} catch (ConversionException $e) {
|
||||||
throw new AccessDeniedHttpException();
|
throw new AccessDeniedHttpException();
|
||||||
|
@ -200,6 +199,7 @@ class WatchController extends AbstractController
|
||||||
}
|
}
|
||||||
|
|
||||||
$data["video"]->setCustomId($videoId);
|
$data["video"]->setCustomId($videoId);
|
||||||
|
$data["video"]->setViews($this->loggingService->getViews($data["video"]));
|
||||||
|
|
||||||
return $this->render("watch/watch.html.twig", [
|
return $this->render("watch/watch.html.twig", [
|
||||||
"viewToken" => $viewToken,
|
"viewToken" => $viewToken,
|
||||||
|
|
|
@ -77,6 +77,8 @@ class Video
|
||||||
*/
|
*/
|
||||||
private $transcodingProgress = 0;
|
private $transcodingProgress = 0;
|
||||||
|
|
||||||
|
private $views = 0;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->videoLinks = new ArrayCollection();
|
$this->videoLinks = new ArrayCollection();
|
||||||
|
@ -241,4 +243,15 @@ class Video
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getViews(): ?int
|
||||||
|
{
|
||||||
|
return $this->views;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setViews(int $views): self
|
||||||
|
{
|
||||||
|
$this->views = $views;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace App\Repository;
|
namespace App\Repository;
|
||||||
|
|
||||||
|
use App\Entity\Video;
|
||||||
use App\Entity\View;
|
use App\Entity\View;
|
||||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
use Doctrine\Persistence\ManagerRegistry;
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
|
@ -58,4 +59,14 @@ class ViewRepository extends ServiceEntityRepository
|
||||||
{
|
{
|
||||||
$this->_em->flush();
|
$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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,4 +54,10 @@ class LoggingService
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getViews(Video $video): int
|
||||||
|
{
|
||||||
|
//return $this->viewRepository->countByVideoAndNotNullValidated($video);
|
||||||
|
return $this->viewRepository->countForVideo($video);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -70,6 +70,9 @@
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<h5>{{ video.name }}</h5>
|
<h5>{{ video.name }}</h5>
|
||||||
|
<div class="views">
|
||||||
|
{{ video.views }} {{ video.views == 1 ? "View" : "Views" }}
|
||||||
|
</div>
|
||||||
<p>
|
<p>
|
||||||
{{ video.description }}
|
{{ video.description }}
|
||||||
</p>
|
</p>
|
||||||
|
|
|
@ -67,6 +67,9 @@
|
||||||
</div>
|
</div>
|
||||||
<div id="description" class="bg-light shadow-5-strong">
|
<div id="description" class="bg-light shadow-5-strong">
|
||||||
<h2>{{ video.name }}</h2>
|
<h2>{{ video.name }}</h2>
|
||||||
|
<div class="views">
|
||||||
|
{{ video.views }} {{ video.views == 1 ? "View" : "Views" }}
|
||||||
|
</div>
|
||||||
<p>
|
<p>
|
||||||
{{ video.description }}
|
{{ video.description }}
|
||||||
</p>
|
</p>
|
||||||
|
|
Loading…
Reference in a new issue