Skip to content

Commit

Permalink
Add filtering on course code and session ID in user information page …
Browse files Browse the repository at this point in the history
…when removing from a course - loosely refs CT#8248
  • Loading branch information
ywarnier committed May 19, 2016
1 parent f4311b2 commit 34fa348
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
19 changes: 13 additions & 6 deletions main/admin/user_information.php
Expand Up @@ -403,21 +403,28 @@
if (isset($_GET['action'])) {
switch ($_GET['action']) {
case 'unsubscribe':
if (CourseManager::get_user_in_course_status($_GET['user_id'], $_GET['course_code']) == STUDENT) {
CourseManager::unsubscribe_user($_GET['user_id'], $_GET['course_code'], $_GET['id_session']);
$userId = empty($_GET['user_id']) ? 0 : intval($_GET['user_id']);
$courseCode = empty($_GET['course_code']) ? '' : intval($_GET['course_code']);
$sessionId = empty($_GET['id_session']) ? 0 : intval($_GET['id_session']);
if (CourseManager::get_user_in_course_status($userId, $courseCode) == STUDENT) {
CourseManager::unsubscribe_user($userId, $courseCode, $sessionId);
$message = Display::return_message(get_lang('UserUnsubscribed'));
} else {
$message = Display::return_message(
get_lang('CannotUnsubscribeUserFromCourse'),
'error'
'error',
false
);
}
break;
case 'unsubscribeSessionCourse':
$userId = empty($_GET['user_id']) ? 0 : intval($_GET['user_id']);
$courseCode = empty($_GET['course_code']) ? '' : intval($_GET['course_code']);
$sessionId = empty($_GET['id_session']) ? 0 : intval($_GET['id_session']);
SessionManager::removeUsersFromCourseSession(
array($_GET['user_id']),
$_GET['id_session'],
api_get_course_info($_GET['course_code'])
array($userId),
$sessionId,
api_get_course_info($courseCode)
);
$message = Display::return_message(get_lang('UserUnsubscribed'));
break;
Expand Down
5 changes: 4 additions & 1 deletion main/inc/lib/course.lib.php
Expand Up @@ -304,12 +304,15 @@ public static function get_access_settings($course_code)
* @param int $user_id
* @param string $course_code
*
* @return int the status of the user in that course
* @return int|bool the status of the user in that course (or false if the user is not in that course)
*/
public static function get_user_in_course_status($user_id, $course_code)
{
$courseInfo = api_get_course_info($course_code);
$courseId = $courseInfo['real_id'];
if (empty($courseId)) {
return false;
}
$result = Database::fetch_array(
Database::query(
"SELECT status FROM " . Database::get_main_table(TABLE_MAIN_COURSE_USER) . "
Expand Down

0 comments on commit 34fa348

Please sign in to comment.