/**
  * @param Association $association
  * @return AssociationDto
  */
 public function convertAssociationToDto(Association $association)
 {
     $dto = new AssociationDto();
     $dto->id = $association->getId();
     $dto->popularity = $association->getPopularity();
     $dto->socialId = $association->getSocialId();
     return $dto;
 }
 /**
  * Tries to find the same association. Returns found or the specified.
  * Persist new entity.
  * @param Association $association
  * @return \MetaPlayer\Model\Association
  */
 public function tryFindTheSame(Association $association)
 {
     $duplicate = $this->findOneBy(array('socialNetwork' => $association->getSocialNetwork(), 'socialId' => $association->getSocialId(), 'track' => $association->getTrack()));
     if ($duplicate == null) {
         $this->persist($association);
         return $association;
     }
     return $duplicate;
 }
 /**
  * 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;
 }