|
|
|
|
@ -11,38 +11,60 @@ api_block_anonymous_users(); |
|
|
|
|
$plugin = StudentFollowUpPlugin::create(); |
|
|
|
|
|
|
|
|
|
$currentUserId = api_get_user_id(); |
|
|
|
|
$currentPage = isset($_GET['page']) ? (int) $_GET['page'] : 1; |
|
|
|
|
$keyword = isset($_GET['keyword']) ? $_GET['keyword'] : ''; |
|
|
|
|
$currentPage = isset($_REQUEST['page']) ? (int) $_REQUEST['page'] : 1; |
|
|
|
|
$keyword = isset($_REQUEST['keyword']) ? Security::remove_XSS($_REQUEST['keyword']) : ''; |
|
|
|
|
$sessionId = isset($_REQUEST['session_id']) ? (int) $_REQUEST['session_id'] : 0; |
|
|
|
|
$selectedTag = isset($_REQUEST['tag']) ? Security::remove_XSS($_REQUEST['tag']) : ''; |
|
|
|
|
|
|
|
|
|
$totalItems = 0; |
|
|
|
|
$items = []; |
|
|
|
|
$tags = []; |
|
|
|
|
$showPrivate = false; |
|
|
|
|
|
|
|
|
|
$pageSize = StudentFollowUpPlugin::getPageSize(); |
|
|
|
|
$firstResults = $pageSize * ($currentPage - 1); |
|
|
|
|
$pagesCount = 0; |
|
|
|
|
$isAdmin = api_is_platform_admin(); |
|
|
|
|
|
|
|
|
|
$userList = []; |
|
|
|
|
if (!api_is_platform_admin()) { |
|
|
|
|
if (!$isAdmin) { |
|
|
|
|
$status = COURSEMANAGER; |
|
|
|
|
if (api_is_drh()) { |
|
|
|
|
$status = DRH; |
|
|
|
|
} |
|
|
|
|
$userList = StudentFollowUpPlugin::getUsers( |
|
|
|
|
$data = StudentFollowUpPlugin::getUsers( |
|
|
|
|
$status, |
|
|
|
|
$currentUserId, |
|
|
|
|
$sessionId, |
|
|
|
|
$firstResults, |
|
|
|
|
$pageSize |
|
|
|
|
); |
|
|
|
|
$userList = $data['users']; |
|
|
|
|
$fullSessionList = $data['sessions']; |
|
|
|
|
} else { |
|
|
|
|
$fullSessionList = SessionManager::getSessionsCoachedByUser($currentUserId); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!empty($sessionId)) { |
|
|
|
|
$userList = SessionManager::get_users_by_session($sessionId); |
|
|
|
|
$userList = array_column($userList, 'user_id'); |
|
|
|
|
} |
|
|
|
|
$tagList = []; |
|
|
|
|
|
|
|
|
|
if (!empty($userList) || api_is_platform_admin()) { |
|
|
|
|
if (!empty($userList) || $isAdmin) { |
|
|
|
|
$em = Database::getManager(); |
|
|
|
|
$qb = $em->createQueryBuilder(); |
|
|
|
|
$criteria = Criteria::create(); |
|
|
|
|
if (!api_is_platform_admin()) { |
|
|
|
|
|
|
|
|
|
if (!$isAdmin) { |
|
|
|
|
$criteria->where(Criteria::expr()->in('user', $userList)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!empty($sessionId)) { |
|
|
|
|
$criteria->where(Criteria::expr()->in('user', $userList)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ($showPrivate == false) { |
|
|
|
|
if ($showPrivate === false) { |
|
|
|
|
$criteria->andWhere(Criteria::expr()->eq('private', false)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -59,9 +81,9 @@ if (!empty($userList) || api_is_platform_admin()) { |
|
|
|
|
; |
|
|
|
|
|
|
|
|
|
if (!empty($keyword)) { |
|
|
|
|
$keyword = explode(' ', $keyword); |
|
|
|
|
if (is_array($keyword)) { |
|
|
|
|
foreach ($keyword as $key) { |
|
|
|
|
$keywordToArray = explode(' ', $keyword); |
|
|
|
|
if (is_array($keywordToArray)) { |
|
|
|
|
foreach ($keywordToArray as $key) { |
|
|
|
|
$key = trim($key); |
|
|
|
|
if (empty($key)) { |
|
|
|
|
continue; |
|
|
|
|
@ -79,15 +101,45 @@ if (!empty($userList) || api_is_platform_admin()) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$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().'?'; |
|
|
|
|
if ($totalItems > 1) { |
|
|
|
|
$url = api_get_self().'?session_id='.$sessionId.'&tag='.$selectedTag.'&keyword='.$keyword.'&'; |
|
|
|
|
if ($totalItems > 1 && $pagesCount > 1) { |
|
|
|
|
$pagination .= '<ul class="pagination">'; |
|
|
|
|
for ($i = 0; $i < $pagesCount; $i++) { |
|
|
|
|
$newPage = $i + 1; |
|
|
|
|
@ -101,7 +153,7 @@ if ($totalItems > 1) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Create a search-box |
|
|
|
|
$form = new FormValidator('search_simple', 'get', null, null, null, 'inline'); |
|
|
|
|
$form = new FormValidator('search_simple', 'get', null, null, null, FormValidator::LAYOUT_HORIZONTAL); |
|
|
|
|
$form->addText( |
|
|
|
|
'keyword', |
|
|
|
|
get_lang('Search'), |
|
|
|
|
@ -110,8 +162,33 @@ $form->addText( |
|
|
|
|
'aria-label' => get_lang('SearchUsers'), |
|
|
|
|
] |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
if (!empty($fullSessionList)) { |
|
|
|
|
$options = array_column($fullSessionList, 'name', 'id'); |
|
|
|
|
$options[0] = get_lang('SelectAnOption'); |
|
|
|
|
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('SelectAnOption')]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$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()); |
|
|
|
|
|