Exemplo n.º 1
0
 /**
  * Checks whether the current user follows a specific user.
  *
  * @param User $user
  *
  * @return bool
  */
 public function follows(User $user) : bool
 {
     return $this->following->exists(function ($index, User $following) use($user) {
         return $following->getId() === $user->getId();
     });
 }
 /**
  * Creates a list that contains the ids of all users following a specific user.
  *
  * @param User $user
  *
  * @return int[]
  */
 public function getFollowingIdsByUser(User $user)
 {
     $qb = $this->_em->createQueryBuilder();
     $result = $qb->select('partial user.{id}')->distinct()->from('Account:User', 'user')->join('Account:User', 'current_user', Join::WITH, $qb->expr()->eq('current_user.id', ':user_id'))->where($qb->expr()->isMemberOf('user', 'current_user.following'))->setParameter(':user_id', $user->getId())->getQuery()->getResult(Query::HYDRATE_ARRAY);
     return array_column($result, 'id');
 }
 /**
  * {@inheritdoc}
  */
 public function getFollowingIdsByUser(User $user, PaginatableDTO $dto) : array
 {
     $qb = $this->_em->createQueryBuilder();
     $qb->select('partial user.{id}')->distinct()->from('Account:User', 'user')->join('Account:User', 'current_user', Join::WITH, $qb->expr()->eq('current_user.id', ':user_id'))->where($qb->expr()->isMemberOf('user', 'current_user.following'))->setParameter(':user_id', $user->getId());
     // copy pagination parameters
     // into the query builder.
     if (null !== ($limit = $dto->limit)) {
         $qb->setMaxResults($limit);
     }
     if (null !== ($offset = $dto->offset)) {
         $qb->setFirstResult($offset);
     }
     $result = $qb->getQuery()->setCacheable(true)->setLifetime(1200)->setCacheRegion('non_strict')->useResultCache(true, 1200)->getResult(Query::HYDRATE_ARRAY);
     return array_column($result, 'id');
 }
 /**
  * @Then I should see the user with id :arg1
  */
 public function iShouldSeeTheUserWithId($arg1)
 {
     Assertion::eq((int) $arg1, $this->user->getId());
 }
 /**
  * Dispatches the mailer event.
  *
  * @param User   $user
  * @param string $templateName
  *
  * @throws \LogicException
  */
 private function dispatchNotificationEvent(User $user, string $templateName)
 {
     $this->accountBlockerProvider->addTemporaryBlockedAccountID($user->getId());
     $this->notify(['notification_target' => $user, 'tracing_data' => $this->ipTracer->getIpLocationData($this->requestStack->getMasterRequest()->getClientIp(), $user->getLocale())], [$user], ['mail'], null, sprintf('AppBundle:Email/AuthAttempt:%s', $templateName));
 }