ShowController.php 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace Muzich\PlaylistBundle\Controller;
  3. use Muzich\CoreBundle\lib\Controller;
  4. use Muzich\CoreBundle\Entity\Playlist;
  5. use Muzich\CoreBundle\lib\AutoplayManager;
  6. class ShowController extends Controller
  7. {
  8. public function userAction($user_slug)
  9. {
  10. if (!($viewed_user = $this->findUserWithSlug($user_slug)))
  11. {
  12. throw $this->createNotFoundException();
  13. }
  14. return $this->render('MuzichPlaylistBundle:Show:user.html.twig', array(
  15. 'viewed_user' => $viewed_user,
  16. 'playlists' => $this->getPlaylistManager()->getUserPublicsOrOwnedorPickedPlaylists($viewed_user, $this->getUserOrNullIfVisitor())
  17. ));
  18. }
  19. public function showAction($user_slug, $playlist_id)
  20. {
  21. if (!($viewed_user = $this->findUserWithSlug($user_slug)))
  22. throw $this->createNotFoundException();
  23. if (!($playlist = $this->getPlaylistManager()->findOneAccessiblePlaylistWithId($playlist_id, $this->getUserOrNullIfVisitor())))
  24. return $this->redirect($this->generateUrl('playlists_user', array('user_slug' => $user_slug)));
  25. return $this->render('MuzichPlaylistBundle:Show:show.html.twig', array(
  26. 'playlist' => $playlist,
  27. 'viewed_user' => $viewed_user
  28. ));
  29. }
  30. public function getAutoplayDataAction($playlist_id, $offset = null)
  31. {
  32. $playlist_manager = $this->getPlaylistManager();
  33. if (!($playlist = $playlist_manager->findOneAccessiblePlaylistWithId($playlist_id, $this->getUserOrNullIfVisitor())))
  34. throw $this->createNotFoundException();
  35. $autoplaym = new AutoplayManager($playlist_manager->getPlaylistElements($playlist, $offset), $this->container);
  36. return $this->jsonResponse(array(
  37. 'status' => 'success',
  38. 'data' => $autoplaym->getList()
  39. ));
  40. }
  41. public function getAddElementPromptAction($element_id)
  42. {
  43. return $this->jsonSuccessResponse(
  44. $this->render('MuzichPlaylistBundle:Show:prompt.html.twig', array(
  45. 'form' => $this->getPlaylistForm()->createView(),
  46. 'element_id' => $element_id,
  47. 'playlists' => (!$this->isVisitor())?$this->getPlaylistManager()->getOwnedsOrPickedsPlaylists($this->getUser()):array()
  48. ))->getContent()
  49. );
  50. }
  51. }