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 .= ''; } // Create a search-box $form = new FormValidator('search_simple', 'get', null, null, null, FormValidator::LAYOUT_HORIZONTAL); $form->addText( 'keyword', get_lang('Search'), false, [ 'aria-label' => get_lang('Search users'), ] ); if (!empty($fullSessionList)) { $options = array_column($fullSessionList, 'name', 'id'); $options[0] = get_lang('Please select an option'); ksort($options); $form->addSelect('session_id', get_lang('Session'), $options); } if (!empty($tagList)) { $tagOptions = []; arsort($tagList); foreach ($tagList as $tag => $counter) { $tagOptions[$tag] = $tag.' ('.$counter.')'; } $form->addSelect('tag', get_lang('Tags'), $tagOptions, ['placeholder' => get_lang('Please select an option')]); } $form->addButtonSearch(get_lang('Search')); $defaults = [ 'session_id' => $sessionId, 'keyword' => $keyword, 'tag' => $selectedTag, ]; $form->setDefaults($defaults); $tpl = new Template($plugin->get_lang('plugin_title')); $tpl->assign('users', $items); $tpl->assign('form', $form->returnForm()); $url = api_get_path(WEB_PLUGIN_PATH).'studentfollowup/posts.php?'; $tpl->assign('post_url', $url); $url = api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?'; $tpl->assign('my_students_url', $url); $tpl->assign('pagination', $pagination); $tpl->assign('care_title', $plugin->get_lang('Student care detail view')); $content = $tpl->fetch('/'.$plugin->get_name().'/view/my_students.html.twig'); $tpl->assign('content', $content); $tpl->display_one_col_template();