public function convertDtoToTrack(TrackDto $dto)
 {
     $userAlbum = $this->userAlbumRepository->find($dto->albumId);
     $album = $userAlbum->getGlobalAlbum();
     if ($album == null) {
         throw ModelException::thereIsNoGlobalObject($userAlbum, 'Album');
     }
     $track = new Track($album, $dto->title, $dto->duration, $dto->serial);
     return $track;
 }
 /**
  * Creates user album (and band if it necessary) using the specified album.
  *
  * @param MetaPlayer\Model\Album $album
  * @param string $source
  * @return MetaPlayer\Model\UserAlbum
  */
 public function createUserAlbumByAlbum(\MetaPlayer\Model\Album $album, $source)
 {
     $band = $album->getBand();
     $userBand = $this->userBandRepository->findOneByBandAndUser($band, $this->securityManager->getUser());
     if ($userBand == null) {
         $userBand = $this->bandManager->createUserBandByBand($band, $source);
     }
     $userAlbum = new \MetaPlayer\Model\UserAlbum($userBand, $album->getTitle(), $album->getReleaseDate(), $source);
     $userAlbum->setAlbum($album);
     $this->userAlbumRepository->persistAndFlush($userAlbum);
     return $userAlbum;
 }
 public function removeAction($id)
 {
     $userAlbum = $this->userAlbumRepository->find($id);
     if ($userAlbum == null) {
         $this->logger->error("There is no user album with id {$id}.");
         throw new JsonException("Invalid album id.");
     }
     $this->userAlbumRepository->remove($userAlbum)->flush();
 }
 public function addOrGetAction($json)
 {
     $trackDto = $this->parseJson($json);
     $userAlbum = $this->userAlbumRepository->find($trackDto->albumId);
     if ($userAlbum == null) {
         $this->logger->error("There is no user album with id = {$trackDto->albumId}.");
         throw new JsonException("Invalid id.");
     }
     if ($this->securityManager->getUser() !== $userAlbum->getUser()) {
         $this->logger->error("The user {$this->securityManager->getUser()} tried to access now own album with id = {$trackDto->albumId}.");
         throw new JsonException("Invalid id.");
     }
     $track = $this->userTrackRepository->findOneByUserAlbumAndTitle($userAlbum, $trackDto->title);
     if ($track == null) {
         return $this->addAction($json);
     } else {
         $dto = $this->trackHelper->convertUserTrackToDto($track);
         return new JsonViewModel($dto, $this->jsonUtils);
     }
 }
 public function listAction()
 {
     return new \Oak\MVC\JsonViewModel($this->userAlbumRepository->findAll(), $this->jsonNativeSerializer);
 }