Exemplo n.º 1
0
 /**
  * @Route("/played", name="_played")
  * @Template()
  */
 public function playedAction()
 {
     $data = [];
     $idVideo = $this->getRequest()->request->get('videoid');
     if ($this->getRequest()->isXmlHttpRequest()) {
         $played = new Played();
         $played->setIdVideo($idVideo)->setDatePlayed(new \DateTime());
         $em = $this->getDoctrine()->getManager();
         $playedQuery = new PlayedQuery($em);
         if ($this->getUser()) {
             $played->setUser($this->getUser());
         }
         $playedQuery->persist($played);
         $data['video'] = $this->get('youtubeVideo')->setId($idVideo)->getResult();
         $title = $data['video']->items[0]->snippet->title;
         $result = $this->get('lastFmMusicSearch')->setTrack($title)->getResults();
         $trackMatches = $result->results->trackmatches;
         if (isset($trackMatches->track)) {
             $artistName = $trackMatches->track[0]->artist;
             $artistQuery = new ArtistQuery($this->get('doctrine_mongodb')->getManager());
             $artist = $artistQuery->setName($artistName)->getSingle();
             if (!$artist) {
                 $this->get('ArtistCreator')->setArtistName($artistName)->run();
             }
         }
         $response = new Response(json_encode($data));
         $response->headers->set('Content-Type', 'application/json');
         return $response;
     }
 }
Exemplo n.º 2
0
 /**
  * @Template()
  * @Cache(expires="tomorrow")
  */
 public function contentAction()
 {
     $em = $this->getDoctrine()->getManager();
     $playedQuery = new PlayedQuery($em);
     $videosPlayed = $playedQuery->getLastPlayed(12);
     /** @var MemcacheService $memcache */
     $memcache = $this->get('memcache');
     $selectedImages = $memcache->get('selectedImages');
     if (!$selectedImages) {
         $selectedImages = [];
         $images = glob('images/albums/*.png');
         $i = 0;
         while ($i < 70) {
             $image = array_rand($images);
             $selectedImages[] = $images[$image];
             unset($images[$image]);
             $i++;
         }
         $memcache->set('selectedImages', $selectedImages, 3600);
     }
     $data = ['videosPlayed' => $videosPlayed, 'tab' => 'home', 'images' => $selectedImages];
     if ($this->getUser()) {
         $data['user'] = $this->getUser();
         $data['connected'] = true;
     } else {
         $data['connected'] = false;
     }
     return $data;
 }
Exemplo n.º 3
0
 /**
  * @param int $limit
  * @param int $offset
  * @Template()
  * @return Response
  */
 public function videoPlayedAction($limit, $offset)
 {
     $user = $this->container->get('security.context')->getToken()->getUser();
     if ($user) {
         $em = $this->container->get('doctrine')->getManager();
         $playedQuery = new PlayedQuery($em);
         $data = [];
         $data['videosPlayed'] = $playedQuery->getLastPlayed($limit, $offset, $user);
         $data['connected'] = true;
     } else {
         $data['connected'] = false;
     }
     $data['html'] = $this->container->get('templating')->render('VidlisUserBundle:Profile:played.html.twig', $data);
     $data['offset'] = $offset + $limit;
     $response = new Response(json_encode($data));
     $response->headers->set('Content-Type', 'application/json');
     return $response;
 }