|
|
|
@ -174,8 +174,8 @@ class SessionManager |
|
|
|
|
global $_configuration; |
|
|
|
|
|
|
|
|
|
// Check portal limits |
|
|
|
|
$accessUrlId = empty($accessUrlId) && api_get_multiple_access_url() |
|
|
|
|
? api_get_current_access_url_id() |
|
|
|
|
$accessUrlId = api_is_multiple_url_enabled() |
|
|
|
|
? (empty($accessUrlId) ? api_get_current_access_url_id() : (int) $accessUrlId) |
|
|
|
|
: 1; |
|
|
|
|
|
|
|
|
|
if (is_array($_configuration[$accessUrlId]) && |
|
|
|
@ -466,33 +466,33 @@ class SessionManager |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Gets the admin session list callback of the session/session_list.php page. |
|
|
|
|
* Get session list for a session admin or platform admin. |
|
|
|
|
* |
|
|
|
|
* @param array $options order and limit keys |
|
|
|
|
* @param bool $get_count Whether to get all the results or only the count |
|
|
|
|
* @param array $columns |
|
|
|
|
* @param array $extraFieldsToLoad |
|
|
|
|
* @param int $userId User Id for the session admin. |
|
|
|
|
* @param array $options Optional. Order and limit keys. |
|
|
|
|
* @param bool $getCount Optional. Whether to get all the results or only the count. |
|
|
|
|
* @param array $columns Optional. Columns from jqGrid. |
|
|
|
|
* |
|
|
|
|
* @return mixed Integer for number of rows, or array of results |
|
|
|
|
* @assert ([],true) !== false |
|
|
|
|
* @return array |
|
|
|
|
*/ |
|
|
|
|
public static function get_sessions_admin( |
|
|
|
|
public static function getSessionsForAdmin( |
|
|
|
|
$userId, |
|
|
|
|
$options = [], |
|
|
|
|
$get_count = false, |
|
|
|
|
$columns = [], |
|
|
|
|
$extraFieldsToLoad = [] |
|
|
|
|
$getCount = false, |
|
|
|
|
$columns = [] |
|
|
|
|
) { |
|
|
|
|
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); |
|
|
|
|
$tblSession = Database::get_main_table(TABLE_MAIN_SESSION); |
|
|
|
|
$sessionCategoryTable = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY); |
|
|
|
|
|
|
|
|
|
$where = 'WHERE 1 = 1 '; |
|
|
|
|
$user_id = api_get_user_id(); |
|
|
|
|
|
|
|
|
|
$userId = (int) $userId; |
|
|
|
|
|
|
|
|
|
if (!api_is_platform_admin()) { |
|
|
|
|
if (api_is_session_admin() && |
|
|
|
|
api_get_setting('allow_session_admins_to_manage_all_sessions') == 'false' |
|
|
|
|
) { |
|
|
|
|
$where .= " AND s.session_admin_id = $user_id "; |
|
|
|
|
$where .= " AND s.session_admin_id = $userId "; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -500,13 +500,14 @@ class SessionManager |
|
|
|
|
api_is_teacher() && |
|
|
|
|
api_get_setting('allow_teachers_to_create_sessions') == 'true' |
|
|
|
|
) { |
|
|
|
|
$where .= " AND s.id_coach = $user_id "; |
|
|
|
|
$where .= " AND s.id_coach = $userId "; |
|
|
|
|
} |
|
|
|
|
$extra_field = new ExtraFieldModel('session'); |
|
|
|
|
$conditions = $extra_field->parseConditions($options); |
|
|
|
|
$inject_joins = $conditions['inject_joins']; |
|
|
|
|
|
|
|
|
|
$extraFieldModel = new ExtraFieldModel('session'); |
|
|
|
|
$conditions = $extraFieldModel->parseConditions($options); |
|
|
|
|
$sqlInjectJoins = $conditions['inject_joins']; |
|
|
|
|
$where .= $conditions['where']; |
|
|
|
|
$inject_where = $conditions['inject_where']; |
|
|
|
|
$sqlInjectWhere = $conditions['inject_where']; |
|
|
|
|
$inject_extra_fields = $conditions['inject_extra_fields']; |
|
|
|
|
$order = $conditions['order']; |
|
|
|
|
$limit = $conditions['limit']; |
|
|
|
@ -514,7 +515,7 @@ class SessionManager |
|
|
|
|
$isMakingOrder = false; |
|
|
|
|
$showCountUsers = false; |
|
|
|
|
|
|
|
|
|
if ($get_count == true) { |
|
|
|
|
if ($getCount == true) { |
|
|
|
|
$select = " SELECT count(DISTINCT s.id) as total_rows"; |
|
|
|
|
} else { |
|
|
|
|
if (!empty($columns['column_model'])) { |
|
|
|
@ -550,7 +551,7 @@ class SessionManager |
|
|
|
|
$isFilteringSessionCategoryWithName = strpos($where, 'sc.name') !== false; |
|
|
|
|
|
|
|
|
|
if ($isMakingOrder || $isFilteringSessionCategory || $isFilteringSessionCategoryWithName) { |
|
|
|
|
$inject_joins .= " LEFT JOIN $sessionCategoryTable sc ON s.session_category_id = sc.id "; |
|
|
|
|
$sqlInjectJoins .= " LEFT JOIN $sessionCategoryTable sc ON s.session_category_id = sc.id "; |
|
|
|
|
|
|
|
|
|
if ($isFilteringSessionCategory) { |
|
|
|
|
$where = str_replace('category_name', 'sc.name', $where); |
|
|
|
@ -562,28 +563,31 @@ class SessionManager |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ($showCountUsers) { |
|
|
|
|
$table = Database::get_main_table(TABLE_MAIN_SESSION_USER); |
|
|
|
|
$inject_joins .= " LEFT JOIN $table su ON (su.session_id = s.id)"; |
|
|
|
|
$tblSessionRelUser = Database::get_main_table(TABLE_MAIN_SESSION_USER); |
|
|
|
|
$sqlInjectJoins .= " LEFT JOIN $tblSessionRelUser su ON (su.session_id = s.id)"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$query = "$select FROM $tbl_session s $inject_joins $where $inject_where"; |
|
|
|
|
$query = "$select FROM $tblSession s $sqlInjectJoins $where $sqlInjectWhere"; |
|
|
|
|
|
|
|
|
|
if (api_is_multiple_url_enabled()) { |
|
|
|
|
$table_access_url_rel_session = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); |
|
|
|
|
$access_url_id = api_get_current_access_url_id(); |
|
|
|
|
if ($access_url_id != -1) { |
|
|
|
|
$where .= " AND ar.access_url_id = $access_url_id "; |
|
|
|
|
$tblAccessUrlRelSession = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); |
|
|
|
|
$accessUrlId = api_get_current_access_url_id(); |
|
|
|
|
|
|
|
|
|
if ($accessUrlId != -1) { |
|
|
|
|
$where .= " AND ar.access_url_id = $accessUrlId "; |
|
|
|
|
$query = "$select |
|
|
|
|
FROM $tbl_session s $inject_joins |
|
|
|
|
INNER JOIN $table_access_url_rel_session ar |
|
|
|
|
ON (ar.session_id = s.id) $where"; |
|
|
|
|
FROM $tblSession s $sqlInjectJoins |
|
|
|
|
INNER JOIN $tblAccessUrlRelSession ar |
|
|
|
|
ON (ar.session_id = s.id) $where"; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ($showCountUsers) { |
|
|
|
|
$query .= ' GROUP by s.id'; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$allowOrder = api_get_configuration_value('session_list_order'); |
|
|
|
|
|
|
|
|
|
if ($allowOrder) { |
|
|
|
|
$order = ' ORDER BY position ASC'; |
|
|
|
|
} |
|
|
|
@ -592,6 +596,52 @@ class SessionManager |
|
|
|
|
$query .= $limit; |
|
|
|
|
$result = Database::query($query); |
|
|
|
|
|
|
|
|
|
$sessions = Database::store_result($result, 'ASSOC'); |
|
|
|
|
|
|
|
|
|
if ($getCount) { |
|
|
|
|
return $sessions[0]['total_rows']; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $sessions; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Gets the admin session list callback of the session/session_list.php page. |
|
|
|
|
* |
|
|
|
|
* @param array $options order and limit keys |
|
|
|
|
* @param bool $getCount Whether to get all the results or only the count |
|
|
|
|
* @param array $columns |
|
|
|
|
* @param array $extraFieldsToLoad |
|
|
|
|
* |
|
|
|
|
* @return mixed Integer for number of rows, or array of results |
|
|
|
|
* @assert ([],true) !== false |
|
|
|
|
*/ |
|
|
|
|
public static function formatSessionsAdminForGrid( |
|
|
|
|
$options = [], |
|
|
|
|
$getCount = false, |
|
|
|
|
$columns = [], |
|
|
|
|
$extraFieldsToLoad = [] |
|
|
|
|
) { |
|
|
|
|
$showCountUsers = false; |
|
|
|
|
|
|
|
|
|
if (!$getCount && !empty($columns['column_model'])) { |
|
|
|
|
foreach ($columns['column_model'] as $column) { |
|
|
|
|
if ($column['name'] == 'users') { |
|
|
|
|
$showCountUsers = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$userId = api_get_user_id(); |
|
|
|
|
|
|
|
|
|
$sessions = self::getSessionsForAdmin($userId, $options, $getCount, $columns); |
|
|
|
|
|
|
|
|
|
if ($getCount) { |
|
|
|
|
return (int) $sessions; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$formattedSessions = []; |
|
|
|
|
|
|
|
|
|
$categories = self::get_all_session_category(); |
|
|
|
|
$orderedCategories = []; |
|
|
|
|
if (!empty($categories)) { |
|
|
|
@ -599,119 +649,91 @@ class SessionManager |
|
|
|
|
$orderedCategories[$category['id']] = $category['name']; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
$formatted_sessions = []; |
|
|
|
|
if (Database::num_rows($result)) { |
|
|
|
|
$sessions = Database::store_result($result, 'ASSOC'); |
|
|
|
|
if ($get_count) { |
|
|
|
|
return $sessions[0]['total_rows']; |
|
|
|
|
|
|
|
|
|
$activeIcon = Display::return_icon('accept.png', get_lang('Active')); |
|
|
|
|
$inactiveIcon = Display::return_icon('error.png', get_lang('Inactive')); |
|
|
|
|
|
|
|
|
|
foreach ($sessions as $session) { |
|
|
|
|
if ($showCountUsers) { |
|
|
|
|
$session['users'] = self::get_users_by_session($session['id'], 0, true); |
|
|
|
|
} |
|
|
|
|
$url = api_get_path(WEB_CODE_PATH).'session/resume_session.php?id_session='.$session['id']; |
|
|
|
|
if (api_is_drh() || $extraFieldsToLoad) { |
|
|
|
|
$url = api_get_path(WEB_PATH).'session/'.$session['id'].'/about/'; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$activeIcon = Display::return_icon( |
|
|
|
|
'accept.png', |
|
|
|
|
get_lang('Active'), |
|
|
|
|
[], |
|
|
|
|
ICON_SIZE_SMALL |
|
|
|
|
); |
|
|
|
|
$inactiveIcon = Display::return_icon( |
|
|
|
|
'error.png', |
|
|
|
|
get_lang('Inactive'), |
|
|
|
|
[], |
|
|
|
|
ICON_SIZE_SMALL |
|
|
|
|
); |
|
|
|
|
$session['name'] = Display::url($session['name'], $url); |
|
|
|
|
|
|
|
|
|
foreach ($sessions as $session) { |
|
|
|
|
$session_id = $session['id']; |
|
|
|
|
if ($showCountUsers) { |
|
|
|
|
$session['users'] = self::get_users_by_session( |
|
|
|
|
if (!empty($extraFieldsToLoad)) { |
|
|
|
|
foreach ($extraFieldsToLoad as $field) { |
|
|
|
|
$extraFieldValue = new ExtraFieldValue('session'); |
|
|
|
|
$fieldData = $extraFieldValue->getAllValuesByItemAndField( |
|
|
|
|
$session['id'], |
|
|
|
|
0, |
|
|
|
|
true |
|
|
|
|
$field['id'] |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
$url = api_get_path(WEB_CODE_PATH).'session/resume_session.php?id_session='.$session['id']; |
|
|
|
|
if (api_is_drh()) { |
|
|
|
|
$url = api_get_path(WEB_CODE_PATH).'session/about.php?session_id='.$session['id']; |
|
|
|
|
} |
|
|
|
|
if (api_is_platform_admin()) { |
|
|
|
|
$url = api_get_path(WEB_CODE_PATH).'session/resume_session.php?id_session='.$session['id']; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ($extraFieldsToLoad) { |
|
|
|
|
$url = api_get_path(WEB_CODE_PATH).'session/about.php?session_id='.$session['id']; |
|
|
|
|
} |
|
|
|
|
$session['name'] = Display::url($session['name'], $url); |
|
|
|
|
|
|
|
|
|
if (!empty($extraFieldsToLoad)) { |
|
|
|
|
foreach ($extraFieldsToLoad as $field) { |
|
|
|
|
$extraFieldValue = new ExtraFieldValue('session'); |
|
|
|
|
$fieldData = $extraFieldValue->getAllValuesByItemAndField( |
|
|
|
|
$session['id'], |
|
|
|
|
$field['id'] |
|
|
|
|
); |
|
|
|
|
$fieldDataArray = []; |
|
|
|
|
$fieldDataToString = ''; |
|
|
|
|
if (!empty($fieldData)) { |
|
|
|
|
foreach ($fieldData as $data) { |
|
|
|
|
$fieldDataArray[] = $data['value']; |
|
|
|
|
} |
|
|
|
|
$fieldDataToString = implode(', ', $fieldDataArray); |
|
|
|
|
$fieldDataArray = []; |
|
|
|
|
$fieldDataToString = ''; |
|
|
|
|
if (!empty($fieldData)) { |
|
|
|
|
foreach ($fieldData as $data) { |
|
|
|
|
$fieldDataArray[] = $data['value']; |
|
|
|
|
} |
|
|
|
|
$session[$field['variable']] = $fieldDataToString; |
|
|
|
|
$fieldDataToString = implode(', ', $fieldDataArray); |
|
|
|
|
} |
|
|
|
|
$session[$field['variable']] = $fieldDataToString; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (isset($session['session_active']) && $session['session_active'] == 1) { |
|
|
|
|
$session['session_active'] = $activeIcon; |
|
|
|
|
} else { |
|
|
|
|
$session['session_active'] = $inactiveIcon; |
|
|
|
|
} |
|
|
|
|
if (isset($session['session_active']) && $session['session_active'] == 1) { |
|
|
|
|
$session['session_active'] = $activeIcon; |
|
|
|
|
} else { |
|
|
|
|
$session['session_active'] = $inactiveIcon; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$session = self::convert_dates_to_local($session, true); |
|
|
|
|
$session = self::convert_dates_to_local($session, true); |
|
|
|
|
|
|
|
|
|
switch ($session['visibility']) { |
|
|
|
|
case SESSION_VISIBLE_READ_ONLY: //1 |
|
|
|
|
$session['visibility'] = get_lang('ReadOnly'); |
|
|
|
|
break; |
|
|
|
|
case SESSION_VISIBLE: //2 |
|
|
|
|
case SESSION_AVAILABLE: //4 |
|
|
|
|
$session['visibility'] = get_lang('Visible'); |
|
|
|
|
break; |
|
|
|
|
case SESSION_INVISIBLE: //3 |
|
|
|
|
$session['visibility'] = api_ucfirst(get_lang('Invisible')); |
|
|
|
|
break; |
|
|
|
|
switch ($session['visibility']) { |
|
|
|
|
case SESSION_VISIBLE_READ_ONLY: //1 |
|
|
|
|
$session['visibility'] = get_lang('ReadOnly'); |
|
|
|
|
break; |
|
|
|
|
case SESSION_VISIBLE: //2 |
|
|
|
|
case SESSION_AVAILABLE: //4 |
|
|
|
|
$session['visibility'] = get_lang('Visible'); |
|
|
|
|
break; |
|
|
|
|
case SESSION_INVISIBLE: //3 |
|
|
|
|
$session['visibility'] = api_ucfirst(get_lang('Invisible')); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Cleaning double selects. |
|
|
|
|
foreach ($session as $key => &$value) { |
|
|
|
|
if (isset($optionsByDouble[$key]) || isset($optionsByDouble[$key.'_second'])) { |
|
|
|
|
$options = explode('::', $value); |
|
|
|
|
} |
|
|
|
|
$original_key = $key; |
|
|
|
|
if (strpos($key, '_second') !== false) { |
|
|
|
|
$key = str_replace('_second', '', $key); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Cleaning double selects. |
|
|
|
|
foreach ($session as $key => &$value) { |
|
|
|
|
if (isset($options_by_double[$key]) || isset($options_by_double[$key.'_second'])) { |
|
|
|
|
$options = explode('::', $value); |
|
|
|
|
} |
|
|
|
|
$original_key = $key; |
|
|
|
|
if (strpos($key, '_second') === false) { |
|
|
|
|
if (isset($optionsByDouble[$key]) && |
|
|
|
|
isset($options[0]) && |
|
|
|
|
isset($optionsByDouble[$key][$options[0]]) |
|
|
|
|
) { |
|
|
|
|
if (strpos($original_key, '_second') === false) { |
|
|
|
|
$value = $optionsByDouble[$key][$options[0]]['option_display_text']; |
|
|
|
|
} else { |
|
|
|
|
$key = str_replace('_second', '', $key); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (isset($options_by_double[$key])) { |
|
|
|
|
if (isset($options[0])) { |
|
|
|
|
if (isset($options_by_double[$key][$options[0]])) { |
|
|
|
|
if (strpos($original_key, '_second') === false) { |
|
|
|
|
$value = $options_by_double[$key][$options[0]]['option_display_text']; |
|
|
|
|
} else { |
|
|
|
|
$value = $options_by_double[$key][$options[1]]['option_display_text']; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
$value = $optionsByDouble[$key][$options[1]]['option_display_text']; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$categoryName = isset($orderedCategories[$session['session_category_id']]) ? $orderedCategories[$session['session_category_id']] : ''; |
|
|
|
|
$session['category_name'] = $categoryName; |
|
|
|
|
$formatted_sessions[] = $session; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$categoryName = isset($orderedCategories[$session['session_category_id']]) |
|
|
|
|
? $orderedCategories[$session['session_category_id']] |
|
|
|
|
: ''; |
|
|
|
|
$session['category_name'] = $categoryName; |
|
|
|
|
$formattedSessions[] = $session; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $formatted_sessions; |
|
|
|
|
return $formattedSessions; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -1964,10 +1986,7 @@ class SessionManager |
|
|
|
|
false |
|
|
|
|
); |
|
|
|
|
// Variables for default template |
|
|
|
|
$tplContent->assign( |
|
|
|
|
'complete_name', |
|
|
|
|
stripslashes($user_info['complete_name']) |
|
|
|
|
); |
|
|
|
|
$tplContent->assign('complete_name', stripslashes($user_info['complete_name'])); |
|
|
|
|
$tplContent->assign('session_name', $session->getName()); |
|
|
|
|
$tplContent->assign( |
|
|
|
|
'session_coach', |
|
|
|
@ -2015,27 +2034,7 @@ class SessionManager |
|
|
|
|
if ($empty_users) { |
|
|
|
|
foreach ($existingUsers as $existing_user) { |
|
|
|
|
if (!in_array($existing_user, $userList)) { |
|
|
|
|
$sql = "DELETE FROM $tbl_session_rel_course_rel_user |
|
|
|
|
WHERE |
|
|
|
|
session_id = $sessionId AND |
|
|
|
|
c_id = $courseId AND |
|
|
|
|
user_id = $existing_user AND |
|
|
|
|
status = 0 "; |
|
|
|
|
$result = Database::query($sql); |
|
|
|
|
|
|
|
|
|
Event::addEvent( |
|
|
|
|
LOG_SESSION_DELETE_USER_COURSE, |
|
|
|
|
LOG_USER_ID, |
|
|
|
|
$existing_user, |
|
|
|
|
api_get_utc_datetime(), |
|
|
|
|
api_get_user_id(), |
|
|
|
|
$courseId, |
|
|
|
|
$sessionId |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
if (Database::affected_rows($result)) { |
|
|
|
|
$nbr_users--; |
|
|
|
|
} |
|
|
|
|
self::unSubscribeUserFromCourseSession($existing_user, $courseId, $sessionId); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -2265,12 +2264,12 @@ class SessionManager |
|
|
|
|
|
|
|
|
|
$statusCondition = null; |
|
|
|
|
if (isset($status) && !is_null($status)) { |
|
|
|
|
$status = intval($status); |
|
|
|
|
$status = (int) $status; |
|
|
|
|
$statusCondition = " AND status = $status"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
foreach ($userList as $userId) { |
|
|
|
|
$userId = intval($userId); |
|
|
|
|
$userId = (int) $userId; |
|
|
|
|
$sql = "DELETE FROM $table |
|
|
|
|
WHERE |
|
|
|
|
session_id = $sessionId AND |
|
|
|
@ -2279,6 +2278,16 @@ class SessionManager |
|
|
|
|
$statusCondition |
|
|
|
|
"; |
|
|
|
|
Database::query($sql); |
|
|
|
|
|
|
|
|
|
Event::addEvent( |
|
|
|
|
LOG_SESSION_DELETE_USER_COURSE, |
|
|
|
|
LOG_USER_ID, |
|
|
|
|
$userId, |
|
|
|
|
api_get_utc_datetime(), |
|
|
|
|
api_get_user_id(), |
|
|
|
|
$courseId, |
|
|
|
|
$sessionId |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ($updateTotal) { |
|
|
|
@ -2441,7 +2450,7 @@ class SessionManager |
|
|
|
|
WHERE |
|
|
|
|
session_id = $session_id AND |
|
|
|
|
user_id = $user_id AND |
|
|
|
|
relation_type <> ".SESSION_RELATION_TYPE_RRHH.""; |
|
|
|
|
relation_type <> ".SESSION_RELATION_TYPE_RRHH; |
|
|
|
|
$result = Database::query($sql); |
|
|
|
|
$return = Database::affected_rows($result); |
|
|
|
|
|
|
|
|
@ -2451,39 +2460,65 @@ class SessionManager |
|
|
|
|
WHERE id = $session_id "; |
|
|
|
|
Database::query($sql); |
|
|
|
|
|
|
|
|
|
Event::addEvent( |
|
|
|
|
LOG_SESSION_DELETE_USER, |
|
|
|
|
LOG_USER_ID, |
|
|
|
|
$user_id, |
|
|
|
|
api_get_utc_datetime(), |
|
|
|
|
api_get_user_id(), |
|
|
|
|
null, |
|
|
|
|
$session_id |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
// Get the list of courses related to this session |
|
|
|
|
$course_list = self::get_course_list_by_session_id($session_id); |
|
|
|
|
if (!empty($course_list)) { |
|
|
|
|
foreach ($course_list as $course) { |
|
|
|
|
$courseId = $course['id']; |
|
|
|
|
// Delete user from course |
|
|
|
|
$sql = "DELETE FROM $tbl_session_rel_course_rel_user |
|
|
|
|
WHERE session_id = $session_id AND c_id = $courseId AND user_id = $user_id"; |
|
|
|
|
$result = Database::query($sql); |
|
|
|
|
|
|
|
|
|
Event::addEvent( |
|
|
|
|
LOG_SESSION_DELETE_USER_COURSE, |
|
|
|
|
LOG_USER_ID, |
|
|
|
|
$user_id, |
|
|
|
|
api_get_utc_datetime(), |
|
|
|
|
api_get_user_id(), |
|
|
|
|
$courseId, |
|
|
|
|
$session_id |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
if (Database::affected_rows($result)) { |
|
|
|
|
// Update number of users in this relation |
|
|
|
|
$sql = "UPDATE $tbl_session_rel_course SET |
|
|
|
|
nbr_users = nbr_users - 1 |
|
|
|
|
WHERE session_id = $session_id AND c_id = $courseId"; |
|
|
|
|
Database::query($sql); |
|
|
|
|
} |
|
|
|
|
self::unSubscribeUserFromCourseSession($user_id, $course['id'], $session_id); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @param int $user_id |
|
|
|
|
* @param int $courseId |
|
|
|
|
* @param int $session_id |
|
|
|
|
*/ |
|
|
|
|
public static function unSubscribeUserFromCourseSession($user_id, $courseId, $session_id) |
|
|
|
|
{ |
|
|
|
|
$user_id = (int) $user_id; |
|
|
|
|
$courseId = (int) $courseId; |
|
|
|
|
$session_id = (int) $session_id; |
|
|
|
|
|
|
|
|
|
$tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); |
|
|
|
|
$tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE); |
|
|
|
|
|
|
|
|
|
// Delete user from course |
|
|
|
|
$sql = "DELETE FROM $tbl_session_rel_course_rel_user |
|
|
|
|
WHERE session_id = $session_id AND c_id = $courseId AND user_id = $user_id"; |
|
|
|
|
$result = Database::query($sql); |
|
|
|
|
|
|
|
|
|
if (Database::affected_rows($result)) { |
|
|
|
|
// Update number of users in this relation |
|
|
|
|
$sql = "UPDATE $tbl_session_rel_course SET |
|
|
|
|
nbr_users = nbr_users - 1 |
|
|
|
|
WHERE session_id = $session_id AND c_id = $courseId"; |
|
|
|
|
Database::query($sql); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Event::addEvent( |
|
|
|
|
LOG_SESSION_DELETE_USER_COURSE, |
|
|
|
|
LOG_USER_ID, |
|
|
|
|
$user_id, |
|
|
|
|
api_get_utc_datetime(), |
|
|
|
|
api_get_user_id(), |
|
|
|
|
$courseId, |
|
|
|
|
$session_id |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Subscribes courses to the given session and optionally (default) |
|
|
|
|
* unsubscribe previous users. |
|
|
|
@ -7882,7 +7917,7 @@ SQL; |
|
|
|
|
$form->addElement('html', '<div id="advanced_params_options" style="display:none">'); |
|
|
|
|
|
|
|
|
|
if (empty($sessionId)) { |
|
|
|
|
$sessions = SessionManager::get_sessions_admin(); |
|
|
|
|
$sessions = SessionManager::formatSessionsAdminForGrid(); |
|
|
|
|
$sessionList = []; |
|
|
|
|
$sessionList[] = ''; |
|
|
|
|
foreach ($sessions as $session) { |
|
|
|
@ -9136,6 +9171,103 @@ SQL; |
|
|
|
|
return $courseIds; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @param int $userId |
|
|
|
|
* @param int $sessionId |
|
|
|
|
* @param ExtraFieldValue $extraFieldValue |
|
|
|
|
* @param string $collapsableLink |
|
|
|
|
* |
|
|
|
|
* @return array |
|
|
|
|
*/ |
|
|
|
|
public static function getCollapsableData($userId, $sessionId, $extraFieldValue, $collapsableLink) |
|
|
|
|
{ |
|
|
|
|
$collapsed = 0; |
|
|
|
|
|
|
|
|
|
// Get default collapsed value in extra field |
|
|
|
|
$value = $extraFieldValue->get_values_by_handler_and_field_variable($sessionId, 'collapsed'); |
|
|
|
|
if (!empty($value) && isset($value['value'])) { |
|
|
|
|
$collapsed = $value['value']; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$userRelSession = Sessionmanager::getUserSession($userId, $sessionId); |
|
|
|
|
if ($userRelSession) { |
|
|
|
|
if (isset($userRelSession['collapsed']) && $userRelSession['collapsed'] != '') { |
|
|
|
|
$collapsed = $userRelSession['collapsed']; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
return ['collapsed' => $collapsed, 'collapsable_link' => ' ']; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$link = $collapsableLink.'&session_id='.$sessionId.'&value=1'; |
|
|
|
|
$image = '<i class="fa fa-folder-open"></i>'; |
|
|
|
|
if ($collapsed == 1) { |
|
|
|
|
$link = $collapsableLink.'&session_id='.$sessionId.'&value=0'; |
|
|
|
|
$image = '<i class="fa fa-folder"></i>'; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$link = Display::url( |
|
|
|
|
$image, |
|
|
|
|
$link |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
return ['collapsed' => $collapsed, 'collapsable_link' => $link]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Converts "start date" and "end date" to "From start date to end date" string. |
|
|
|
|
* |
|
|
|
|
* @param string $startDate |
|
|
|
|
* @param string $endDate |
|
|
|
|
* @param bool $showTime |
|
|
|
|
* @param bool $dateHuman |
|
|
|
|
* |
|
|
|
|
* @return string |
|
|
|
|
*/ |
|
|
|
|
public static function convertSessionDateToString($startDate, $endDate, $showTime, $dateHuman) |
|
|
|
|
{ |
|
|
|
|
// api_get_local_time returns empty if date is invalid like 0000-00-00 00:00:00 |
|
|
|
|
$startDateToLocal = api_get_local_time( |
|
|
|
|
$startDate, |
|
|
|
|
null, |
|
|
|
|
null, |
|
|
|
|
true, |
|
|
|
|
$showTime, |
|
|
|
|
$dateHuman |
|
|
|
|
); |
|
|
|
|
$endDateToLocal = api_get_local_time( |
|
|
|
|
$endDate, |
|
|
|
|
null, |
|
|
|
|
null, |
|
|
|
|
true, |
|
|
|
|
$showTime, |
|
|
|
|
$dateHuman |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
$format = $showTime ? DATE_TIME_FORMAT_LONG_24H : DATE_FORMAT_LONG_NO_DAY; |
|
|
|
|
|
|
|
|
|
$result = ''; |
|
|
|
|
if (!empty($startDateToLocal) && !empty($endDateToLocal)) { |
|
|
|
|
$result = sprintf( |
|
|
|
|
get_lang('FromDateXToDateY'), |
|
|
|
|
api_format_date($startDateToLocal, $format), |
|
|
|
|
api_format_date($endDateToLocal, $format) |
|
|
|
|
); |
|
|
|
|
} else { |
|
|
|
|
if (!empty($startDateToLocal)) { |
|
|
|
|
$result = get_lang('From').' '.api_format_date($startDateToLocal, $format); |
|
|
|
|
} |
|
|
|
|
if (!empty($endDateToLocal)) { |
|
|
|
|
$result = get_lang('Until').' '.api_format_date($endDateToLocal, $format); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (empty($result)) { |
|
|
|
|
$result = get_lang('NoTimeLimits'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @param int $id |
|
|
|
|
* |
|
|
|
@ -9227,58 +9359,6 @@ SQL; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Converts "start date" and "end date" to "From start date to end date" string. |
|
|
|
|
* |
|
|
|
|
* @param string $startDate |
|
|
|
|
* @param string $endDate |
|
|
|
|
* @param bool $showTime |
|
|
|
|
* @param bool $dateHuman |
|
|
|
|
* |
|
|
|
|
* @return string |
|
|
|
|
*/ |
|
|
|
|
private static function convertSessionDateToString($startDate, $endDate, $showTime, $dateHuman) |
|
|
|
|
{ |
|
|
|
|
// api_get_local_time returns empty if date is invalid like 0000-00-00 00:00:00 |
|
|
|
|
$startDateToLocal = api_get_local_time( |
|
|
|
|
$startDate, |
|
|
|
|
null, |
|
|
|
|
null, |
|
|
|
|
true, |
|
|
|
|
$showTime, |
|
|
|
|
$dateHuman |
|
|
|
|
); |
|
|
|
|
$endDateToLocal = api_get_local_time( |
|
|
|
|
$endDate, |
|
|
|
|
null, |
|
|
|
|
null, |
|
|
|
|
true, |
|
|
|
|
$showTime, |
|
|
|
|
$dateHuman |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
$result = ''; |
|
|
|
|
if (!empty($startDateToLocal) && !empty($endDateToLocal)) { |
|
|
|
|
$result = sprintf( |
|
|
|
|
get_lang('FromDateXToDateY'), |
|
|
|
|
api_format_date($startDateToLocal, DATE_TIME_FORMAT_LONG_24H), |
|
|
|
|
api_format_date($endDateToLocal, DATE_TIME_FORMAT_LONG_24H) |
|
|
|
|
); |
|
|
|
|
} else { |
|
|
|
|
if (!empty($startDateToLocal)) { |
|
|
|
|
$result = get_lang('From').' '.api_format_date($startDateToLocal, DATE_TIME_FORMAT_LONG_24H); |
|
|
|
|
} |
|
|
|
|
if (!empty($endDateToLocal)) { |
|
|
|
|
$result = get_lang('Until').' '.api_format_date($endDateToLocal, DATE_TIME_FORMAT_LONG_24H); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (empty($result)) { |
|
|
|
|
$result = get_lang('NoTimeLimits'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @param array $listA |
|
|
|
|
* @param array $listB |
|
|
|
|