ShowController.php 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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()->getUserPublicsOrOwnedPlaylists($viewed_user, $this->getUser(true))
  17. ));
  18. }
  19. public function showAction($user_slug, $playlist_id)
  20. {
  21. if (!($playlist = $this->getPlaylistManager()->findOneAccessiblePlaylistWithId($playlist_id, $this->getUser(true))))
  22. throw $this->createNotFoundException();
  23. return $this->render('MuzichPlaylistBundle:Show:show.html.twig', array(
  24. 'playlist' => $playlist
  25. ));
  26. }
  27. public function getAutoplayDataAction($playlist_id, $offset = null)
  28. {
  29. $playlist_manager = $this->getPlaylistManager();
  30. if (!($playlist = $playlist_manager->findOneAccessiblePlaylistWithId($playlist_id, $this->getUser(true))))
  31. throw $this->createNotFoundException();
  32. $autoplaym = new AutoplayManager($playlist_manager->getPlaylistElements($playlist, $offset), $this->container);
  33. return $this->jsonResponse(array(
  34. 'status' => 'success',
  35. 'data' => $autoplaym->getList()
  36. ));
  37. }
  38. public function getAddElementPromptAction($element_id)
  39. {
  40. return $this->jsonSuccessResponse(
  41. $this->render('MuzichPlaylistBundle:Show:prompt.html.twig', array(
  42. 'form' => $this->getPlaylistForm()->createView(),
  43. 'element_id' => $element_id,
  44. 'playlists' => (!$this->isVisitor())?$this->getPlaylistManager()->getOwnedsPlaylists($this->getUser()):array()
  45. ))->getContent()
  46. );
  47. }
  48. }