コード例 #1
0
 /**
  * Return the count of activities by user
  *
  * Not Implemented Yet
  *
  * @param User $user
  * @param \DateTime $start
  * @return array
  */
 public function findActivitiesByUserCount(User $user, \DateTime $start)
 {
     /** @var $em EntityManager */
     $em = $this->getEntityManager();
     /** @var $qb QueryBuilder */
     $qb = $em->createQueryBuilder();
     $expr = $qb->expr();
     $districtsIds = $user->getDistrictsIds();
     $sectionsIds = $user->getGroupSectionsIds();
     $activeGroups = $this->getEntityManager()->getRepository('CivixCoreBundle:UserGroup')->getActiveGroupIds($user);
     $userFollowingIds = $user->getFollowingIds();
     return $qb->select('COUNT(act.id)')->from('CivixCoreBundle:Activity', 'act')->leftJoin('act.activityConditions', 'act_c')->where($expr->gt('act.sentAt', ':start'))->andWhere($expr->orX($expr->in('act_c.districtId', ':userDistrictsIds'), 'act_c.isSuperuser = 1', $expr->in('act_c.groupId', ':userGroupsIds'), $expr->in('act_c.userId', ':userFollowingIds'), $expr->in('act_c.groupSectionId', ':userGroupSectionIds'), ':user MEMBER OF act_c.users'))->setParameter('userDistrictsIds', empty($districtsIds) ? false : $districtsIds)->setParameter('userGroupsIds', empty($activeGroups) ? false : $activeGroups)->setParameter('userFollowingIds', empty($userFollowingIds) ? false : $userFollowingIds)->setParameter('userGroupSectionIds', empty($sectionsIds) ? false : $sectionsIds)->setParameter('user', $user)->setParameter('start', $start->format('Y-m-d H:i:s'))->getQuery()->getSingleScalarResult();
 }
コード例 #2
0
 public function findByUser(User $user, \DateTime $start)
 {
     $districtsIds = $user->getDistrictsIds();
     $groupsIds = $user->getGroupsIds();
     $representativeIds = array();
     if (!empty($districtsIds)) {
         $qb = $this->getEntityManager()->createQueryBuilder();
         $representativeIds = $qb->select('r.id')->from('CivixCoreBundle:Representative', 'r')->where($qb->expr()->in('r.district', $districtsIds))->getQuery()->getArrayResult();
         $representativeIds = array_reduce($representativeIds, function ($ids, $item) {
             $ids[] = $item['id'];
             return $ids;
         }, array());
     }
     $representativeIds = empty($representativeIds) ? array(0) : $representativeIds;
     $groupsIds = empty($groupsIds) ? array(0) : $groupsIds;
     $qb = $this->getEntityManager()->createQueryBuilder();
     return $qb->select('a, r, gr, rs')->from('CivixCoreBundle:Announcement', 'a')->leftJoin('a.group', 'gr')->leftJoin('a.representative', 'r')->leftJoin('r.representativeStorage', 'rs')->where($qb->expr()->orX($qb->expr()->in('a.representative', $representativeIds), $qb->expr()->in('a.group', $groupsIds)))->andWhere('a.publishedAt > :start')->setParameter('start', $start->format('Y-m-d H:i:s'))->orderBy('a.publishedAt', 'DESC')->getQuery()->getResult();
 }
コード例 #3
0
 public function findActivitiesByUser(User $user, \DateTime $start)
 {
     /** @var $em EntityManager */
     $em = $this->getEntityManager();
     /** @var $qb QueryBuilder */
     $qb = $em->createQueryBuilder();
     $expr = $qb->expr();
     $districtsIds = $user->getDistrictsIds();
     $sectionsIds = $user->getGroupSectionsIds();
     $activeGroups = $this->getEntityManager()->getRepository('CivixCoreBundle:UserGroup')->getActiveGroupIds($user);
     $userFollowingIds = $user->getFollowingIds();
     $activities = $qb->select('act')->from('CivixCoreBundle:Activity', 'act')->leftJoin('act.activityConditions', 'act_c')->where($expr->gt('act.sentAt', ':start'))->andWhere($expr->orX($expr->in('act_c.districtId', ':userDistrictsIds'), 'act_c.isSuperuser = 1', $expr->in('act_c.groupId', ':userGroupsIds'), $expr->in('act_c.userId', ':userFollowingIds'), $expr->in('act_c.groupSectionId', ':userGroupSectionIds'), ':user MEMBER OF act_c.users'))->setParameter('userDistrictsIds', empty($districtsIds) ? false : $districtsIds)->setParameter('userGroupsIds', empty($activeGroups) ? false : $activeGroups)->setParameter('userFollowingIds', empty($userFollowingIds) ? false : $userFollowingIds)->setParameter('userGroupSectionIds', empty($sectionsIds) ? false : $sectionsIds)->setParameter('user', $user)->setParameter('start', $start->format('Y-m-d H:i:s'))->orderBy('act.sentAt', 'DESC')->setMaxResults(500)->getQuery()->getResult();
     $readItems = $this->getEntityManager()->getRepository(ActivityRead::class)->findLastIdsByUser($user, $start);
     /* @var $activity Activity */
     foreach ($activities as $activity) {
         if (in_array($activity->getId(), $readItems)) {
             $activity->setRead(true);
         }
     }
     return $activities;
 }
 public function getDistrictsIds()
 {
     $this->__load();
     return parent::getDistrictsIds();
 }
コード例 #5
0
 public function findByQuery($query, User $user)
 {
     $userDistrictIds = $user->getDistrictsIds();
     $qb = $this->getEntityManager()->createQueryBuilder();
     $representativesFromStorage = $qb->select('rs, r')->from('CivixCoreBundle:RepresentativeStorage', 'rs')->leftJoin('rs.representative', 'r')->leftJoin('rs.district', 'd')->where($qb->expr()->in('rs.district', $userDistrictIds ? $userDistrictIds : array(0)))->andWhere($qb->expr()->orX($qb->expr()->like('rs.officialTitle', $qb->expr()->literal('%' . $query . '%')), $qb->expr()->like('rs.firstName', $qb->expr()->literal('%' . $query . '%')), $qb->expr()->like('rs.lastName', $qb->expr()->literal('%' . $query . '%'))))->orderBy('d.districtType')->getQuery()->getResult();
     $qb = $this->getEntityManager()->createQueryBuilder();
     $representatives = $qb->select('r')->from('CivixCoreBundle:Representative', 'r')->leftJoin('r.district', 'd')->where($qb->expr()->in('r.district', $userDistrictIds ? $userDistrictIds : array(0)))->andWhere('r.isNonLegislative = 1')->andWhere($qb->expr()->orX($qb->expr()->like('r.officialTitle', $qb->expr()->literal('%' . $query . '%')), $qb->expr()->like('r.firstName', $qb->expr()->literal('%' . $query . '%')), $qb->expr()->like('r.lastName', $qb->expr()->literal('%' . $query . '%'))))->orderBy('d.districtType')->getQuery()->getResult();
     return array_merge($representativesFromStorage, $representatives);
 }