/** * @param string $provider * @param string $id * * @throws NonUniqueUserException * @throws UserNotFoundException * * @return User */ public function findUserByExternalId($provider, $id) { try { return $this->repository->getUserByCredentialExternalId($provider, $id); } catch (NonUniqueResultException $e) { throw new NonUniqueUserException('Multiple users with this credential external user id'); } catch (NoResultException $e) { throw new UserNotFoundException('User Not found with this external user id'); } }
/** * @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)); }
/** * @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 */ public function create($data) { $notification = new Notification(); $notification->setName(Notification::LEADER_WISH); $notification->setContent(array('wish' => $data['wish'], 'userFullName' => $data['userFullName'], 'user' => $data['user'], 'restaurant' => $data['restaurant'], 'restaurantName' => $data['restaurantName'], 'image' => $data['image'])); $translatedMessage = $this->translator->trans($notification->getTranslationKey(), array('%name%' => $data['userFullName'], '%restaurant%' => $data['restaurantName'])); $notification->setMessage($translatedMessage); $followersIds = $this->userRepository->getFollowersIdsWithWish($data['user'], $data['wish']); foreach ($followersIds as $followersId) { $this->addPushMessage($notification, $followersId); } return $notification; }
/** * @param array $data * * @return Notification */ public function create($data) { $notification = new Notification(); $notification->setName(Notification::LEADER_FOLLOWS); $notification->setContent(array('follower' => $data['follower'], 'followerFullName' => $data['followerFullName'], 'leader' => $data['leader'], 'leaderFullName' => $data['leaderFullName'], 'image' => $data["followerImage"])); $followersIds = $this->userRepository->getFollowersIds($data['follower']); $translatedMessage = $this->translator->trans($notification->getTranslationKey(), array('%name%' => $data['followerFullName'], '%leader%' => $data['leaderFullName'])); $notification->setMessage($translatedMessage); foreach ($followersIds as $followerId) { $this->addPushMessage($notification, $followerId); } return $notification; }
/** * @param CacheMetaBag $cacheMetaBag * * @return array */ public function getTags(CacheMetaBag $cacheMetaBag) { $tags = array(); $geonameSuffix = $this->getGeonameSuffix($cacheMetaBag); $userId = $cacheMetaBag->getParameter('leadersOf'); $leadersIds = $this->userRepository->getLeadersIds($userId); foreach ($cacheMetaBag->getCacheTags() as $cacheTag) { foreach ($leadersIds as $leaderId) { $tags[] = $this->getEntityOfUserInGeonameTag($cacheTag, $leaderId, $geonameSuffix); } } return $tags; }
/** * @ApiDoc( * description="Leader array of id", * statusCodes={200="Leaders"}, * section="Leader", * filters={ * {"name"="leadersOf", "dataType"="integer", "required"=true} * }) * @Route("/api/leaders/ids") * @Cache(maxage="+1 week", public=true) * @Method({"GET"}) * @throws BadRequestException * @return View */ public function getLeadersIdsAction() { $request = $this->requestStack->getCurrentRequest(); $userId = $request->query->get('leadersOf'); // Handle deprecated parameter: client < 1.7.2 if (!$userId) { $userId = $request->query->get('user'); $request->query->set('leadersOf', $userId); } if (!$userId) { throw new BadRequestException(); } $leaders = $this->userRepository->getLeadersOf($userId); $this->cacheManager->tagController($request); return $this->view(array('leaders' => $leaders)); }
/** * @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; }
/** * All my reviews in common with my followers' reviews of the last week * @param $userId * * @return int */ public function getLastWeekCommonReviewsCount($userId) { $followerIds = $this->userRepository->getFollowersIds($userId); $sql = 'SELECT COUNT(*) as counter FROM ( SELECT reviews.id, reviews.restaurant_id FROM reviews WHERE reviews.user_id = ?) my_reviews INNER JOIN ( SELECT reviews.id, reviews.restaurant_id FROM reviews WHERE reviews.user_id IN (?) AND reviews.created > DATE_SUB(NOW(), INTERVAL 1 WEEK)) follower_reviews ON my_reviews.restaurant_id = follower_reviews.restaurant_id'; $result = $this->connection->fetchArray($sql, array($userId, $followerIds), array(\PDO::PARAM_INT, Connection::PARAM_INT_ARRAY)); return (int) $result[0]; }
/** * @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')); }