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); }