Browse Source

Evolution #738: Playlist

Sevajol Bastien 11 years ago
parent
commit
2f35233f3c

+ 12 - 4
src/Muzich/CoreBundle/Managers/PlaylistManager.php View File

37
     ;
37
     ;
38
   }
38
   }
39
   
39
   
40
-  public function getPlaylistElements(Playlist $playlist)
40
+  public function getPlaylistElements(Playlist $playlist, $offset = null)
41
   {
41
   {
42
-    return $this->entity_manager->getRepository('MuzichCoreBundle:Element')
43
-      ->getElementsWithIdsOrderingQueryBuilder($playlist->getElementsIds())
44
-      ->getQuery()->getResult()
42
+    $element_ids = $playlist->getElementsIds();
43
+    $query_builder = $this->entity_manager->getRepository('MuzichCoreBundle:Element')
44
+      ->getElementsWithIdsOrderingQueryBuilder($element_ids)
45
     ;
45
     ;
46
+    
47
+    if ($offset)
48
+    {
49
+      $query_builder->setFirstResult( $offset-1 )
50
+        ->setMaxResults( count($element_ids) );
51
+    }
52
+    
53
+    return  $query_builder->getQuery()->getResult();
46
   }
54
   }
47
   
55
   
48
   public function getNewPlaylist(User $owner)
56
   public function getNewPlaylist(User $owner)

+ 2 - 2
src/Muzich/PlaylistBundle/Controller/ShowController.php View File

32
     ));
32
     ));
33
   }
33
   }
34
   
34
   
35
-  public function getAutoplayDataAction($playlist_id)
35
+  public function getAutoplayDataAction($playlist_id, $offset = null)
36
   {
36
   {
37
     $playlist_manager = $this->getPlaylistManager();
37
     $playlist_manager = $this->getPlaylistManager();
38
     
38
     
39
     if (!($playlist = $playlist_manager->findOneAccessiblePlaylistWithId($playlist_id, $this->getUser(true))))
39
     if (!($playlist = $playlist_manager->findOneAccessiblePlaylistWithId($playlist_id, $this->getUser(true))))
40
       throw $this->createNotFoundException();
40
       throw $this->createNotFoundException();
41
     
41
     
42
-    $autoplaym = new AutoplayManager($playlist_manager->getPlaylistElements($playlist), $this->container);
42
+    $autoplaym = new AutoplayManager($playlist_manager->getPlaylistElements($playlist, $offset), $this->container);
43
     
43
     
44
     return $this->jsonResponse(array(
44
     return $this->jsonResponse(array(
45
       'status'    => 'success',
45
       'status'    => 'success',

+ 2 - 2
src/Muzich/PlaylistBundle/Resources/config/routing.yml View File

7
   defaults: { _controller: MuzichPlaylistBundle:Show:show }
7
   defaults: { _controller: MuzichPlaylistBundle:Show:show }
8
 
8
 
9
 playlist_datas_for_autoplay:
9
 playlist_datas_for_autoplay:
10
-  pattern: /ajax/autoplay/playlist/datas/{playlist_id}
11
-  defaults: { _controller: MuzichPlaylistBundle:Show:getAutoplayData }
10
+  pattern: /ajax/autoplay/playlist/datas/{playlist_id}/{offset}
11
+  defaults: { _controller: MuzichPlaylistBundle:Show:getAutoplayData, offset: null }

+ 3 - 0
src/Muzich/PlaylistBundle/Resources/views/Show/show.html.twig View File

21
       <ul class="playlist_elements">
21
       <ul class="playlist_elements">
22
         {% for element in playlist.elements %}
22
         {% for element in playlist.elements %}
23
           <li class="playlist_element">
23
           <li class="playlist_element">
24
+            <a class="autoplay_playlist" href="{{ path('playlist_datas_for_autoplay', { 'playlist_id' : playlist.id, 'offset' : loop.index0 }) }}">
25
+              play
26
+            </a>
24
             <a class="open_element" href="{{ path('element_get_one', { 'element_id' : element.id }) }}" data-id="{{ element.id }}">
27
             <a class="open_element" href="{{ path('element_get_one', { 'element_id' : element.id }) }}" data-id="{{ element.id }}">
25
               {{ element.name }}
28
               {{ element.name }}
26
             </a>
29
             </a>