From 54f87f99adc6d8636a6c817be50c695895bada8a Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Fri, 9 Jan 2015 10:29:40 -0500 Subject: [PATCH] Don't show invited users results - refs BT#9070 --- main/exercice/exercise.lib.php | 4 +-- main/exercice/exercise_show.php | 4 +++ main/inc/lib/main_api.lib.php | 57 +++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 2 deletions(-) diff --git a/main/exercice/exercise.lib.php b/main/exercice/exercise.lib.php index 79cd9ebf5c..3496105b0b 100755 --- a/main/exercice/exercise.lib.php +++ b/main/exercice/exercise.lib.php @@ -1291,7 +1291,7 @@ function get_exam_results_data( ( SELECT u.user_id, firstname, lastname, email, username, ' ' as group_name, '' as group_id, official_code FROM $TBL_USER u - WHERE u.status != " . ROLE_INVITED . " + WHERE u.status NOT IN(" . apiGetExcludedUserTypes('string') . ") )"; } @@ -1362,7 +1362,7 @@ function get_exam_results_data( AND tth.exe_cours_id = '" . api_get_course_id()."' $hotpotatoe_where $sqlWhereOption - AND user.status != " . ROLE_INVITED . " + AND user.status NOT IN(" . apiGetExcludedUserTypes('string') . ") ORDER BY tth.exe_cours_id ASC, tth.exe_date DESC"; diff --git a/main/exercice/exercise_show.php b/main/exercice/exercise_show.php index d5ff900ba4..564630da94 100755 --- a/main/exercice/exercise_show.php +++ b/main/exercice/exercise_show.php @@ -90,6 +90,10 @@ $learnpath_item_id = $track_exercise_info['orig_lp_item_id']; $lp_item_view_id = $track_exercise_info['orig_lp_item_view_id']; $current_user_id = api_get_user_id(); +if (apiIsExcludedUserType(true, $student_id)) { + api_not_allowed(true); +} + $locked = api_resource_is_locked_by_gradebook($exercise_id, LINK_EXERCISE); if (empty($objExercise)) { diff --git a/main/inc/lib/main_api.lib.php b/main/inc/lib/main_api.lib.php index cb52d88fca..10feecb3c2 100755 --- a/main/inc/lib/main_api.lib.php +++ b/main/inc/lib/main_api.lib.php @@ -7497,3 +7497,60 @@ function api_register_campus($listCampus = true) { } // Reload the settings. } + +/** + * Check whether the user type should be exclude. + * Such as invited or anonymous users + * @param boolean $checkDB Optional. Whether check the user status + * @param int $userId Options. The user id + * @return boolean + */ +function apiIsExcludedUserType($checkDB = false, $userId = 0) +{ + if ($checkDB) { + $userId = empty($userId) ? api_get_user_id() : intval($userId); + + if ($userId == 0) { + return true; + } + + $userInfo = api_get_user_info($userId); + + switch ($userInfo['status']) { + case ROLE_INVITED: + //no break; + case ANONYMOUS: + return true; + default: + return false; + } + } + + $isInvited = api_is_invited_user(); + $isAnonymous = api_is_anonymous(); + + if ($isInvited || $isAnonymous) { + return true; + } + + return false; +} + +/** + * Get the exclude user types + * @param string $format Optional. The result type. Array or string + * @return array + */ +function apiGetExcludedUserTypes($format = 'array') +{ + $excludedTypes = array( + ROLE_INVITED, + ANONYMOUS + ); + + if ($format == 'string') { + return implode(', ', $excludedTypes); + } + + return $excludedTypes; +}