/**
  * @ApiDoc(
  *  description="Option list",
  *  statusCodes={200="Option"},
  *  section="Option",
  *  filters={
  *      {"name"="user", "dataType"="string", "required"=true}
  *  })
  * @Route("/api/options")
  * @throws AccessDeniedException
  * @Method({"GET"})
  * @return View
  */
 public function getAllAction()
 {
     $request = $this->requestStack->getCurrentRequest();
     $me = $this->getUser();
     $user = $this->userRepository->get($request->query->get('user'));
     if ($user->getId() !== $me->getId()) {
         throw new AccessDeniedException();
     }
     $options = $this->optionRepository->getAllByUser($user);
     $this->cacheManager->tagController($request, CacheTag::OPTION);
     return $this->view(array('options' => $options));
 }
 /**
  * @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;
 }
 /**
  * @ApiDoc(
  *  description="Geonames",
  *  statusCodes={200="Geonames"},
  *  section="Geoname",
  *  filters={
  *      {"name"="asciiName", "dataType"="string", "required"="false"},
  *      {"name"="country", "dataType"="string", "required"="false"},
  *      {"name"="user", "dataType"="integer", "required"="false"},
  *      {"name"="orderBy", "dataType"="string", "required"="false", "pattern"="distance"},
  *      {"name"="lat", "dataType"="string", "required"="false"},
  *      {"name"="lng", "dataType"="string", "required"="false"},
  *      {"name"="featured", "dataType"="boolean", "required"="false"}
  *  })
  * @Route("/api/geonames")
  * @Route("/public-api/geonames")
  * @Cache(maxage="+1 week", public=true)
  * @throws BadRequestException
  * @Method({"GET"})
  * @return View
  */
 public function getAllAction()
 {
     $request = $this->requestStack->getCurrentRequest();
     $orderBy = $request->query->get('orderBy');
     $featured = $request->query->get('featured');
     $userId = $request->query->get('user');
     $user = $userId ? $this->userRepository->get($userId) : null;
     if ($featured === 'true') {
         return $this->getFeaturedGeonames();
     }
     // @TODO if order by distance use the real name with reverse geocode to find the right city
     if ($orderBy === 'distance') {
         $pager = $this->reverseGeonamer->reverseWithFallback($request);
     } else {
         $pager = $this->geonameRepository->getAll($request, $user);
     }
     $this->cacheManager->tagController($request, CacheTag::GEONAME);
     return $this->view($this->getPagedViewData($pager, 'geonames'));
 }