public function findFollowingForUser(User $user) { $userFollowingIds = $user->getFollowingIds(); if (empty($userFollowingIds)) { return []; } $activeGroups = $this->getEntityManager()->getRepository('CivixCoreBundle:UserGroup')->getActiveGroupIds($user); $qb = $this->createQueryBuilder('sa'); $qb->addSelect('f')->addSelect('g')->leftJoin('sa.following', 'f')->leftJoin('sa.group', 'g')->where($qb->expr()->andX('sa.recipient is NULL', $qb->expr()->in('sa.following', ':followings'), empty($activeGroups) ? 'sa.group is NULL' : 'sa.group is NULL OR sa.group IN (:groups)'))->setParameter('followings', $userFollowingIds)->setParameter('groups', $activeGroups)->orderBy('sa.id', 'DESC')->setMaxResults(200); return $qb->getQuery()->getResult(); }
public function getFollowingIds() { $this->__load(); return parent::getFollowingIds(); }
private function addUnfollowingFilter(QueryBuilder $qb, User $user) { $excludedIds = array_merge(array($user->getId()), $user->getFollowingIds()); $qb->andWhere('u.id NOT IN (:excluded_ids)')->setParameter('excluded_ids', $excludedIds); return $qb; }