ShowController.php 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. ));
  28. }
  29. public function getAutoplayDataAction($playlist_id, $offset = null)
  30. {
  31. $playlist_manager = $this->getPlaylistManager();
  32. if (!($playlist = $playlist_manager->findOneAccessiblePlaylistWithId($playlist_id, $this->getUserOrNullIfVisitor())))
  33. throw $this->createNotFoundException();
  34. $autoplaym = new AutoplayManager($playlist_manager->getPlaylistElements($playlist, $offset), $this->container);
  35. return $this->jsonResponse(array(
  36. 'status' => 'success',
  37. 'data' => $autoplaym->getList()
  38. ));
  39. }
  40. public function getAddElementPromptAction($element_id)
  41. {
  42. return $this->jsonSuccessResponse(
  43. $this->render('MuzichPlaylistBundle:Show:prompt.html.twig', array(
  44. 'form' => $this->getPlaylistForm()->createView(),
  45. 'element_id' => $element_id,
  46. 'playlists' => (!$this->isVisitor())?$this->getPlaylistManager()->getOwnedsOrPickedsPlaylists($this->getUser()):array()
  47. ))->getContent()
  48. );
  49. }
  50. }