Parcourir la source

Evolution #738: Playlist

Sevajol Bastien il y a 11 ans
Parent
révision
2f35233f3c

+ 12 - 4
src/Muzich/CoreBundle/Managers/PlaylistManager.php Voir le fichier

@@ -37,12 +37,20 @@ class PlaylistManager
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 56
   public function getNewPlaylist(User $owner)

+ 2 - 2
src/Muzich/PlaylistBundle/Controller/ShowController.php Voir le fichier

@@ -32,14 +32,14 @@ class ShowController extends Controller
32 32
     ));
33 33
   }
34 34
   
35
-  public function getAutoplayDataAction($playlist_id)
35
+  public function getAutoplayDataAction($playlist_id, $offset = null)
36 36
   {
37 37
     $playlist_manager = $this->getPlaylistManager();
38 38
     
39 39
     if (!($playlist = $playlist_manager->findOneAccessiblePlaylistWithId($playlist_id, $this->getUser(true))))
40 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 44
     return $this->jsonResponse(array(
45 45
       'status'    => 'success',

+ 2 - 2
src/Muzich/PlaylistBundle/Resources/config/routing.yml Voir le fichier

@@ -7,5 +7,5 @@ playlist:
7 7
   defaults: { _controller: MuzichPlaylistBundle:Show:show }
8 8
 
9 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 Voir le fichier

@@ -21,6 +21,9 @@
21 21
       <ul class="playlist_elements">
22 22
         {% for element in playlist.elements %}
23 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 27
             <a class="open_element" href="{{ path('element_get_one', { 'element_id' : element.id }) }}" data-id="{{ element.id }}">
25 28
               {{ element.name }}
26 29
             </a>