/** * Creates user band using the specified band. * @param MetaPlayer\Model\Band $band * @param $source * @return MetaPlayer\Model\UserBand */ public function createUserBandByBand(\MetaPlayer\Model\Band $band, $source) { $userBand = new \MetaPlayer\Model\UserBand($this->securityManager->getUser(), $band->getName(), $band->getFoundDate(), $source, $band->getEndDate()); $userBand->setBand($band); $this->userBandRepository->persist($userBand); $this->userBandRepository->flush(); return $userBand; }
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; }
/** * 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; }
/** * 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); } }