ShowController.php 3.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace Muzich\PlaylistBundle\Controller;
  3. use Muzich\CoreBundle\lib\Controller;
  4. use Muzich\CoreBundle\lib\AutoplayManager;
  5. use Muzich\CoreBundle\Security\Context as SecurityContext;
  6. use Muzich\CoreBundle\Form\Playlist\PrivateLinksForm;
  7. class ShowController extends Controller
  8. {
  9. public function userAction($user_slug)
  10. {
  11. if (($uncondition = $this->userHaveNonConditionToMakeAction(SecurityContext::ACTION_PLAYLIST_SHOW)) !== false)
  12. return $this->jsonResponseError($uncondition);
  13. if (!($viewed_user = $this->findUserWithSlug($user_slug)))
  14. throw $this->createNotFoundException();
  15. return $this->render('MuzichPlaylistBundle:Show:user.html.twig', array(
  16. 'viewed_user' => $viewed_user,
  17. 'playlists' => $this->getPlaylistManager()->getUserPublicsOrOwnedorPickedPlaylists($viewed_user, $this->getUserOrNullIfVisitor())
  18. ));
  19. }
  20. public function showAction($user_slug, $playlist_id)
  21. {
  22. if (($uncondition = $this->userHaveNonConditionToMakeAction(SecurityContext::ACTION_PLAYLIST_SHOW)) !== false)
  23. return $this->jsonResponseError($uncondition);
  24. if (!($viewed_user = $this->findUserWithSlug($user_slug)))
  25. throw $this->createNotFoundException();
  26. if (!($playlist = $this->getPlaylistManager()->findOneAccessiblePlaylistWithId($playlist_id, $this->getUserOrNullIfVisitor())))
  27. return $this->redirect($this->generateUrl('playlists_user', array('user_slug' => $user_slug)));
  28. return $this->render('MuzichPlaylistBundle:Show:show.html.twig', array(
  29. 'playlist' => $playlist,
  30. 'viewed_user' => $viewed_user,
  31. 'links_form' => $this->createForm(new PrivateLinksForm())->createView()
  32. ));
  33. }
  34. public function getAutoplayDataAction($playlist_id, $offset = null, $shuffle = false)
  35. {
  36. if (($uncondition = $this->userHaveNonConditionToMakeAction(SecurityContext::ACTION_PLAYLIST_DATA_AUTOPLAY)) !== false)
  37. return $this->jsonResponseError($uncondition);
  38. $playlist_manager = $this->getPlaylistManager();
  39. if (!($playlist = $playlist_manager->findOneAccessiblePlaylistWithId($playlist_id, $this->getUserOrNullIfVisitor())))
  40. return $this->jsonNotFoundResponse();
  41. $autoplaym = new AutoplayManager($playlist_manager->getPlaylistElements($playlist, $offset, $this->getUserId(true)), $this->container);
  42. if ($shuffle)
  43. $autoplaym->shuffle();
  44. return $this->jsonResponse(array(
  45. 'status' => 'success',
  46. 'data' => $autoplaym->getList()
  47. ));
  48. }
  49. public function getAddElementPromptAction($element_id)
  50. {
  51. if (($uncondition = $this->userHaveNonConditionToMakeAction(SecurityContext::ACTION_PLAYLIST_ADD_PROMPT)) !== false)
  52. return $this->jsonResponseError($uncondition);
  53. if (!($element = $this->getElementWithId($element_id)))
  54. return $this->jsonNotFoundResponse();
  55. return $this->jsonSuccessResponse(
  56. $this->render('MuzichPlaylistBundle:Show:prompt.html.twig', array(
  57. 'form' => $this->getPlaylistForm()->createView(),
  58. 'element' => $element,
  59. 'playlists' => (!$this->isVisitor())?$this->getPlaylistManager()->getOwnedsOrPickedsPlaylists($this->getUser()):array()
  60. ))->getContent()
  61. );
  62. }
  63. }