コード例 #1
0
 /**
  * Builds a list that contains advices of users that can be followed by the current user
  *
  * @param User $user
  * @param integer $limit
  *
  * @return User[]
  */
 public function adviceFollowersByUser(User $user, $limit = 5)
 {
     $followerRepository = $this->followerRepository;
     $currentFollowing = $user->getFollowing();
     if (count($currentFollowing) === 0) {
         return $followerRepository->findUsersWithMostFollowers($limit, $user);
     }
     $advices = $followerRepository->findFollowingByFollowing($user, $limit);
     if (empty($advices)) {
         throw new FollowerException();
     }
     return $advices;
 }
コード例 #2
0
 public function testUnfollowUser()
 {
     $target = User::fromDTO(new CreateUserDTO('foo', 'bar', '*****@*****.**'));
     $user = new User(new Credentials('Ma27', 'test-pwd'), new UserDetails('*****@*****.**', new \DateTime(), new \DateTime()), [$target]);
     $this->assertCount(1, $user->getFollowing());
     $user->unfollow($target);
     $this->assertCount(0, $user->getFollowing());
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 public function findFollowingByFollowing(User $user, $maxQueryResultLength = 5)
 {
     $qb = $this->getEntityManager()->createQueryBuilder();
     $limit = (int) $maxQueryResultLength;
     $userIds = array_map(function (User $user) {
         return $user->getId();
     }, array_merge($user->getFollowing(), [$user]));
     $qb->select('user')->from('SEN_User:User', 'user')->join('SEN_User:User', 'following', Join::WITH, $qb->expr()->in('following.identifier', ':followingIds'))->where($qb->expr()->isMemberOf('user', 'following.following'))->andWhere($qb->expr()->notIn('user.identifier', $userIds))->setParameter(':followingIds', $userIds);
     $qb->setMaxResults($limit);
     return $qb->getQuery()->getResult();
 }