public function convertDtoToAlbum(AlbumDto $albumDto) { $userBand = $this->userBandRepository->find($albumDto->bandId); $band = $userBand->getGlobalBand(); if ($band == null) { throw ModelException::thereIsNoGlobalObject($userBand, 'Band'); } $album = new Album($band, $albumDto->title, ViewHelper::parseDate($albumDto->releaseDate)); return $album; }
/** * Remove user band * @param $id * @throws \MetaPlayer\JsonException * @return void */ public function removeAction($id) { $userBand = $this->userBandRepository->find($id); if ($userBand == null) { $this->logger->error("There is no user band with id {$id}."); throw new JsonException("Invalid band id."); } $this->userBandRepository->remove($userBand)->flush(); }
public function addOrGetAction($json) { $albumDto = $this->parseJson($json); $userBand = $this->userBandRepository->find($albumDto->bandId); if ($userBand == null) { $this->logger->error("There is no user band with id = {$albumDto->bandId}."); throw new JsonException("Invalid id."); } if ($userBand->getUser() !== $this->securityManager->getUser()) { $user = $this->securityManager->getUser(); $this->logger->error("The user {$user} tried to access now own band with id = {$albumDto->bandId}."); throw new JsonException("Invalid id."); } $album = $this->userAlbumRepository->findOneByUserBandAndName($userBand, $albumDto->title); if ($album == null) { return $this->addAction($json); } else { $dto = $this->albumHelper->convertUserAlbumToDto($album); return new JsonViewModel($dto, $this->jsonUtils); } }