/**
  * @ApiDoc(
  *  description="Get friends from facebook already subscribed in Tastd",
  *  statusCodes={200="Get My friends"},
  *  section="Friends")
  * @Route("/api/friends")
  * @Method({"GET"})
  * @throws CredentialNotFoundException
  * @return View
  */
 public function getAction()
 {
     $user = $this->getUser();
     $facebookCredential = $user->getCredentialByProvider(CredentialProvider::FACEBOOK);
     if (!$facebookCredential) {
         throw new CredentialNotFoundException();
     }
     $this->facebookClient->connect($facebookCredential->getToken());
     $ids = $this->facebookClient->getFriendsIds();
     $friends = $this->userRepository->getUsersByCredentialExternalIds(CredentialProvider::FACEBOOK, $ids);
     return $this->view(array('friends' => $friends, 'ids' => $ids));
 }
 /**
  * @param array $data
  *
  * @return Notification
  * @throws \Exception
  */
 public function create($data)
 {
     $userId = $data['user'];
     $user = $this->userRepository->get($userId);
     $credential = $user->getCredentialByProvider(CredentialProvider::FACEBOOK);
     $friends = array();
     if ($credential) {
         $this->facebookClient->connect($credential->getToken());
         $friendsIds = $this->facebookClient->getFriendsIds();
         $friends = $this->userRepository->getUsersByCredentialExternalIds(CredentialProvider::FACEBOOK, $friendsIds);
     }
     $notification = new Notification();
     $notification->setName(Notification::NEW_FACEBOOK_FRIEND);
     $notification->setContent(array('user' => $userId, 'userFullName' => $data['userFullName'], 'image' => $data['image']));
     $translatedMessage = $this->translator->trans($notification->getTranslationKey(), array('%name%' => $data['userFullName']));
     $notification->setMessage($translatedMessage);
     foreach ($friends as $friend) {
         $pushMessage = new PushMessage();
         $pushMessage->setNotification($notification);
         $pushMessage->setUser($friend);
         $notification->addPushMessage($pushMessage);
     }
     return $notification;
 }