createQueryBuilder(); $criteria = Criteria::create(); if (!$isAdmin) { $criteria->where(Criteria::expr()->in('user', $userList)); } if (!empty($sessionId)) { $criteria->where(Criteria::expr()->in('user', $userList)); } if ($showPrivate === false) { $criteria->andWhere(Criteria::expr()->eq('private', false)); } $qb ->select('p') ->distinct() ->from('ChamiloPluginBundle:StudentFollowUp\CarePost', 'p') ->join('p.user', 'u') ->addCriteria($criteria) ->setFirstResult($firstResults) ->setMaxResults($pageSize) ->groupBy('p.user') ->orderBy('p.createdAt', 'desc') ; if (!empty($keyword)) { $keywordToArray = explode(' ', $keyword); if (is_array($keywordToArray)) { foreach ($keywordToArray as $key) { $key = trim($key); if (empty($key)) { continue; } $qb ->andWhere('u.firstname LIKE :keyword OR u.lastname LIKE :keyword OR u.username LIKE :keyword') ->setParameter('keyword', "%$key%") ; } } else { $qb ->andWhere('u.firstname LIKE :keyword OR u.lastname LIKE :keyword OR u.username LIKE :keyword') ->setParameter('keyword', "%$keyword%") ; } } $queryBuilderOriginal = clone $qb; if (!empty($selectedTag)) { $qb->andWhere('p.tags LIKE :tags '); $qb->setParameter('tags', "%$selectedTag%"); } $query = $qb->getQuery(); $items = new Paginator($query); $queryBuilderOriginal->select('p.tags') ->distinct(false) ->setFirstResult(null) ->setMaxResults(null) ->groupBy('p.id') ; $tags = $queryBuilderOriginal->getQuery()->getResult(); //var_dump($queryBuilderOriginal->getQuery()->getSQL()); $tagList = []; foreach ($tags as $tag) { $itemTags = $tag['tags']; foreach ($itemTags as $itemTag) { if (in_array($itemTag, array_keys($tagList))) { $tagList[$itemTag]++; } else { $tagList[$itemTag] = 1; } } } $totalItems = $items->count(); $pagesCount = ceil($totalItems / $pageSize); } $pagination = ''; $url = api_get_self().'?session_id='.$sessionId.'&tag='.$selectedTag.'&keyword='.$keyword.'&'; if ($totalItems > 1 && $pagesCount > 1) { $pagination .= '