Exemplo n.º 1
0
 /**
  * @param AssociationDto $dto
  * @param UserTrack $userTrack
  * @throws \MetaPlayer\Model\ModelException
  * @return \MetaPlayer\Model\Association
  */
 public function convertDtoToAssociation(AssociationDto $dto, UserTrack $userTrack)
 {
     $socialNetwork = $this->securityManager->getSocialNetwork();
     $track = $userTrack->getGlobalTrack();
     if ($track == null) {
         throw ModelException::thereIsNoGlobalObject($userTrack, 'Track');
     }
     return new Association($track, $socialNetwork, $dto->socialId);
 }
Exemplo n.º 2
0
 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;
 }
Exemplo n.º 3
0
 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;
 }
Exemplo n.º 4
0
 /**
  * Associates track with specified the association.
  * @param SocialNetwork $socialNetwork
  * @param Association $association
  * @return \MetaPlayer\Model\UserTrack
  * @throws ModelException
  */
 public function associate(SocialNetwork $socialNetwork, Association $association)
 {
     $prevAssoc = $this->getAssociation($socialNetwork);
     if (isset($prevAssoc)) {
         $prevAssoc->decrementPopularity();
     }
     switch ($socialNetwork) {
         case SocialNetwork::$MY:
             $this->myAssociation = $association;
             break;
         case SocialNetwork::$VK:
             $this->vkAssociation = $association;
             break;
         default:
             throw ModelException::unsupportedSocialNetwork($socialNetwork);
     }
     $association->incrementPopularity();
     return $this;
 }
Exemplo n.º 5
0
 private function checkAssociation(UserTrack $userTrack)
 {
     $association = $userTrack->getAssociation($this->securityManager->getSocialNetwork());
     if ($association == null) {
         $track = $userTrack->getGlobalTrack();
         if ($track == null) {
             throw ModelException::thereIsNoGlobalObject($userTrack, 'Track');
         }
         $association = $this->associationRepository->findOnePopularByTrack($userTrack->getGlobalTrack());
         if ($association != null) {
             $userTrack->associate($this->securityManager->getSocialNetwork(), $association);
         }
     }
 }
 public function listAction($trackId)
 {
     $userTrack = $this->userTrackRepository->find($trackId);
     if ($userTrack == null) {
         $this->logger->error("There is no user track with id = {$trackId}.");
         throw new JsonException("Invalid id.");
     }
     $track = $userTrack->getGlobalTrack();
     if ($track == null) {
         throw \MetaPlayer\Model\ModelException::thereIsNoGlobalObject($track, 'Track');
     }
     $result = array();
     $associations = $this->associationRepository->findByTrack($track);
     foreach ($associations as $association) {
         $result[] = $this->associationHelper->convertAssociationToDto($association);
     }
     return new JsonViewModel($result, $this->jsonUtils);
 }