diff --git a/public/main/inc/ajax/model.ajax.php b/public/main/inc/ajax/model.ajax.php index fd3c50a46e..6a4e4f5e82 100644 --- a/public/main/inc/ajax/model.ajax.php +++ b/public/main/inc/ajax/model.ajax.php @@ -816,8 +816,15 @@ switch ($action) { } } - if ('custom' === $listType && 'true' === api_get_setting('session.allow_session_status')) { - $whereCondition .= ' AND (s.status IN ("'.SessionManager::STATUS_PLANNED.'", "'.SessionManager::STATUS_PROGRESS.'") ) '; + if ('true' === api_get_setting('session.allow_session_status')) { + if (isset($filters->filter_status)) { + $sStatus = (int) $filters->filter_status; + $whereCondition .= ' AND s.status = '.$sStatus; + } else { + if ($listType === 'custom') { + $whereCondition .= ' AND (s.status IN ("'.SessionManager::STATUS_PLANNED.'", "'.SessionManager::STATUS_PROGRESS.'") ) '; + } + } } switch ($listType) { @@ -835,7 +842,8 @@ switch ($action) { [], $listType, $extraFieldsToLoad, - $search + $search, + $language ); break; case 'active': @@ -1939,7 +1947,15 @@ switch ($action) { } } - $sidx = in_array($sidx, $columns) ? $sidx : 'name'; + if ($_REQUEST['origin'] == 'load_search') { + if (!in_array($sidx, $columns)) { + $sidx = 'display_start_date'; + $sord = 'DESC'; + } + } else { + $sidx = in_array($sidx, $columns) ? $sidx : 'name'; + } + $orderBy = "$sidx $sord, s.name"; $limit = 20; $total_pages = 0; if ($count > 0) { @@ -1960,7 +1976,7 @@ switch ($action) { $result = SessionManager::get_sessions_admin_complete( [ 'where' => $whereCondition, - 'order' => "$sidx $sord, s.name", + 'order' => $orderBy, 'extra' => $extra_fields, 'limit' => "$start , $limit", ] @@ -1972,7 +1988,7 @@ switch ($action) { api_get_user_id(), [ 'where' => $whereCondition, - 'order' => "$sidx $sord, s.name", + 'order' => $orderBy, 'extra' => $extra_fields, 'limit' => "$start , $limit", ], @@ -1980,7 +1996,8 @@ switch ($action) { $sessionColumns, $listType, $extraFieldsToLoad, - $search + $search, + $language ); break; case 'active': @@ -1989,7 +2006,7 @@ switch ($action) { $result = SessionManager::formatSessionsAdminForGrid( [ 'where' => $whereCondition, - 'order' => "$sidx $sord, s.name", + 'order' => $orderBy, 'extra' => $extra_fields, 'limit' => "$start , $limit", ], diff --git a/public/main/inc/lib/sessionmanager.lib.php b/public/main/inc/lib/sessionmanager.lib.php index e055460ecd..15ca2f71b6 100644 --- a/public/main/inc/lib/sessionmanager.lib.php +++ b/public/main/inc/lib/sessionmanager.lib.php @@ -470,7 +470,8 @@ class SessionManager $columns = [], $listType = 'all', $extraFieldsToLoad = [], - $formatted = false + $formatted = false, + $language = '' ) { $tblSession = Database::get_main_table(TABLE_MAIN_SESSION); $sessionCategoryTable = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY); @@ -547,6 +548,31 @@ class SessionManager } } + if (!empty($language)) { + $table = Database::get_main_table(TABLE_MAIN_SESSION_COURSE); + $tableCourse = Database::get_main_table(TABLE_MAIN_COURSE); + $sqlInjectJoins .= " INNER JOIN $table sc ON (sc.session_id = s.id) + INNER JOIN $tableCourse c ON (sc.c_id = c.id)"; + $language = Database::escape_string($language); + + if ('true' === api_get_setting('language.allow_course_multiple_languages')) { + $tblExtraField = Database::get_main_table(TABLE_EXTRA_FIELD); + $tblExtraFieldValue = Database::get_main_table(TABLE_EXTRA_FIELD_VALUES); + $extraFieldType = ExtraField::COURSE_FIELD_TYPE; + $sql = "SELECT id FROM $tblExtraField WHERE item_type = $extraFieldType AND variable = 'multiple_language'"; + $rs = Database::query($sql); + if (Database::num_rows($rs) > 0) { + $fieldId = Database::result($rs, 0, 0); + $sqlInjectJoins .= " INNER JOIN $tblExtraFieldValue cfv ON (c.id = cfv.item_id AND cfv.field_id = $fieldId)"; + $where .= " AND (c.course_language = '$language' OR cfv.field_value LIKE '%$language%')"; + } else { + $where .= " AND c.course_language = '$language' "; + } + } else { + $where .= " AND c.course_language = '$language' "; + } + } + $allowSessionAdminsToManageAllSessions = !api_is_platform_admin() && api_is_session_admin() && 'false' === api_get_setting('allow_session_admins_to_manage_all_sessions'); @@ -681,6 +707,12 @@ class SessionManager null, true ); + $usersLang = self::getCountUsersLangBySession($session['id']); + $tooltipUserLangs = ''; + if (!empty($usersLang)) { + $tooltipUserLangs = implode(' | ', $usersLang); + } + $session['users'] = ''.$session['users'].''; $courses = self::getCoursesInSession($session_id); $teachers = ''; foreach ($courses as $courseId) { @@ -688,9 +720,6 @@ class SessionManager // Ofaj $teachers = CourseManager::get_coachs_from_course_to_string($session_id, $courseInfo['real_id']); - /*$teachers .= CourseManager::get_teacher_list_from_course_code_to_string( - $courseInfo['code'] - );*/ } // ofaj $session['teachers'] = ''; @@ -764,6 +793,55 @@ class SessionManager return $formattedSessions; } + /** + * Get the count of users by language and session + * + * @param $sid + * @param int $urlId + * @param null $status + * + * @return array A list of ISO lang of users registered in the session , ex: FR 6 + */ + public static function getCountUsersLangBySession( + $sid, + $urlId = 0, + $status = null + ): array + { + $sid = (int) $sid; + $urlId = empty($urlId) ? api_get_current_access_url_id() : (int) $urlId; + + $tblUser = Database::get_main_table(TABLE_MAIN_USER); + $tblSessionUser = Database::get_main_table(TABLE_MAIN_SESSION_USER); + $tableAccessUrlUser = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); + $tableLanguage = Database::get_main_table(TABLE_MAIN_LANGUAGE); + + $sql = "SELECT l.isocode, count(u.id) as cLang + FROM $tblSessionUser su + INNER JOIN $tblUser u ON (u.id = su.user_id) + INNER JOIN $tableLanguage l ON (l.english_name = u.language) + LEFT OUTER JOIN $tableAccessUrlUser au ON (au.user_id = u.id) + "; + + if (is_numeric($status)) { + $status = (int) $status; + $sql .= " WHERE su.relation_type = $status AND (au.access_url_id = $urlId OR au.access_url_id is null)"; + } else { + $sql .= " WHERE (au.access_url_id = $urlId OR au.access_url_id is null )"; + } + $sql .= " AND su.session_id = $sid GROUP BY l.isocode"; + + $rs = Database::query($sql); + $usersLang = []; + if (Database::num_rows($rs) > 0) { + while ($row = Database::fetch_assoc($rs)) { + $usersLang[] = strtoupper($row['isocode'])." ".$row['cLang']; + } + } + + return $usersLang; + } + /** * Gets the admin session list callback of the session/session_list.php page. * diff --git a/public/main/search/load_search.php b/public/main/search/load_search.php index d28b247e30..c3e77cd829 100644 --- a/public/main/search/load_search.php +++ b/public/main/search/load_search.php @@ -977,13 +977,13 @@ if (!empty($filterToSend)) { $filterToSend = json_encode($filterToSend); $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_sessions&_search=true&load_extra_field='. - $extraFieldListToString.'&filters2='.$filterToSend; + $extraFieldListToString.'&_force_search=true&rows=20&page=1&origin=load_search&sidx=&sord=desc&filters2='.$filterToSend; if (isset($params['search_using_2'])) { $url .= '&lang='.$lang; } } else { $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_sessions&_search=true&load_extra_field='. - $extraFieldListToString.'&_force_search=true&rows=20&page=1&sidx=&sord=asc'; + $extraFieldListToString.'&_force_search=true&rows=20&page=1&origin=load_search&sidx=&sord=desc'; } // Autowidth