-
Notifications
You must be signed in to change notification settings - Fork 0
/
HomeController.php
170 lines (143 loc) · 5.18 KB
/
HomeController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php
/**
* Created by PhpStorm.
* User: meltir
* Date: 3/19/2019
* Time: 8:15 PM
*/
namespace App\Controller;
use App\Entity\ImdbMovies;
use App\Entity\YtCategories;
use App\Entity\YtChannels;
use App\Entity\YtVideos;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use App\Entity\PagePost;
class HomeController extends AbstractController {
/**
* @Route("/", name="home", methods="GET")
* @return Response
*/
public function homepage() {
$repository = $this->getDoctrine()
->getRepository(PagePost::class);
$posts = $repository->findForThisPage('home');
return $this->render('home.html.twig',['posts'=>$posts]);
}
/**
* @Route("/contact", name="contact", methods="GET")
* @return Response
*/
public function contact() {
$repository = $this->getDoctrine()
->getRepository(PagePost::class);
$posts = $repository->findForThisPage('contact');
return $this->render('home.html.twig',['posts'=>$posts]);
}
/**
* @Route("/gallery", name="gallery", methods="GET")
* @return Response
*/
public function gallery() {
$repository = $this->getDoctrine()
->getRepository(PagePost::class);
$posts = $repository->findForThisPage('gallery');
return $this->render('gallery.html.twig',['galleries'=>$posts]);
}
/**
* @Route("/thoughts", name="thoughts", methods="GET")
* @return Response
*/
public function thoughts() {
$repository = $this->getDoctrine()
->getRepository(PagePost::class);
$posts = $repository->findForThisPage('thoughts');
return $this->render('thoughts.html.twig',['posts'=>$posts]);
}
/**
* @Route("/cv", name="cv", methods="GET")
* @return Response
*/
public function cv() {
$repository = $this->getDoctrine()
->getRepository(PagePost::class);
$posts = $repository->findForThisPage('cv');
return $this->render('cv.html.twig',['posts'=>$posts]);
}
/**
* @Route("/youtube/{category}/{page}", name="youtube_list", defaults={"page" = "1","category" = "dev"}, methods={"GET"})
* @param int $page
* @param YtCategories $category
* @ParamConverter("category",options={"mapping": {"category" = "slug"}})
* @return Response
*/
public function youtube(int $page, YtCategories $category) {
$per_page = 10;
$categories = $this->getDoctrine()
->getRepository(YtCategories::class)
->getActiveCategories();
$channels = $this->getDoctrine()
->getRepository(YtChannels::class)
->getChannelPage($page,$per_page, $category);
$pages = $this->getDoctrine()
->getRepository(YtChannels::class)
->countPages($per_page,$category);
$videos_repo = $this->getDoctrine()
->getRepository(YtVideos::class);
$videos = [];
foreach ($channels as $channel) {
$videos[$channel->getId()] = $videos_repo->getLatestVideosQuery($channel,4,1)->getResult();
}
return $this->render('youtube.html.twig',[
'paginator'=>[
'page'=>$page,
'pages'=>$pages,
'base_route'=>'youtube_list'
],
'channels'=>$channels,
'categories'=>$categories,
'current_category'=>$category,
'videos'=>$videos
]);
}
/**
* @Route("/youtube_channel_videos/{channel}/{page}", name="youtube_ajax_j" , condition="request.isXmlHttpRequest()", methods={"GET"})
* @param int $page
* @param YtChannels $channel
* @ParamConverter("channel",options={"mapping":{"channel" = "chan_id"}})
* @return Response
*/
public function next4videos($page,YtChannels $channel) {
$videos_repo = $this->getDoctrine()
->getRepository(YtVideos::class);
$videos = $videos_repo->getLatestVideosQuery($channel,4,$page)->getArrayResult();
if (count($videos)==0) return new Response('no results :(');
$response = new JsonResponse();
// var_dump($videos);
$videos_json = $this->get('serializer')->serialize($videos,'json');
$response->setData($videos_json);
return $response;
return $this->render('youtube_videos.html.twig',['videos'=>$videos,'channel'=>$channel]);
}
/**
* @Route("/imdb/{page}", name="imdb_list", defaults={"page":"1"}, methods={"GET"})
* @param $page
* @return Response
*/
public function imdb($page) {
$imdb_repo = $this->getDoctrine()->getRepository(ImdbMovies::class);
$movies = $imdb_repo->getMovies($page);
// print_r($movies);
return $this->render('imdb.html.twig',[
'movies'=>$movies,
'paginator'=>[
'page'=>$page,
'pages'=>$imdb_repo->countPages(),
'base_route'=>'imdb_list'
]
]);
}
}