From b8a6caba5cbe6a2c6f521a47b6a2e8b23f6bff9e Mon Sep 17 00:00:00 2001 From: Carlos Alvarado Date: Thu, 7 Jan 2021 12:33:36 -0500 Subject: [PATCH] Excercise: Subscribe to remedial or advance course - refs BT#18165 --- main/exercise/exercise.class.php | 56 ++++++++++++++++++++------------ main/exercise/overview.php | 11 +++++++ 2 files changed, 47 insertions(+), 20 deletions(-) diff --git a/main/exercise/exercise.class.php b/main/exercise/exercise.class.php index 3c459774ad..978decec54 100755 --- a/main/exercise/exercise.class.php +++ b/main/exercise/exercise.class.php @@ -6795,7 +6795,6 @@ class Exercise } // 4. We check if the student have attempts - $extraMessage = ''; // extra mensaje if ($isVisible) { $exerciseAttempts = $this->selectAttempts(); @@ -6808,16 +6807,12 @@ class Exercise $lpItemViewId ); - // BT#18165 - $extraMessage .= $this->advanceCourseList(); if ($attemptCount >= $exerciseAttempts) { $message = sprintf( get_lang('ReachedMaxAttempts'), $this->name, $exerciseAttempts ); - // BT#18165 - $message .= $this->remedialCourseList(api_get_user_id()); $isVisible = false; } else { // Check blocking exercise. @@ -6852,7 +6847,34 @@ class Exercise } } // BT#18165 - $message .= $extraMessage; + $field = new ExtraField('exercise'); + $advancedCourseField = $field->get_handler_field_info_by_field_variable('advancedcourselist'); + + $field = new ExtraField('exercise'); + $remedialField = $field->get_handler_field_info_by_field_variable('remedialcourselist'); + + if ( + ($remedialField != false && isset($remedialField['default_value']) && $remedialField['default_value'] == 1 // if the plugin is activated + ) || ( + $advancedCourseField != false && isset($advancedCourseField['default_value']) && $advancedCourseField['default_value'] == 1 // if the plugin is activated + ) + ) { + $exerciseAttempts = $this->selectAttempts(); + if ($exerciseAttempts > 0) { + $attemptCount = Event::get_attempt_count_not_finished( + api_get_user_id(), + $this->id, + $lpId, + $lpItemId, + $lpItemViewId + ); + $message .= $this->advanceCourseList(api_get_user_id()); + if ($attemptCount >= $exerciseAttempts) { + $message .= $this->remedialCourseList(api_get_user_id()); + } + } + } + $rawMessage = ''; if (!empty($message)) { $rawMessage = $message; @@ -10853,21 +10875,17 @@ class Exercise || !isset($bestAttempt['exe_weighting']) ) { // Sin intentos, sin id de ejercicio y sin total definido - return ''; + return null; } - $resultado = $bestAttempt['exe_result']; - $total = $bestAttempt['exe_weighting']; - $objExercise = new Exercise(); - $objExercise->read($bestAttempt['exe_id']); - $percentSuccess = (float) $objExercise->selectPassPercentage(); + $percentSuccess = (float) $this->selectPassPercentage(); $pass = ExerciseLib::isPassPercentageAttemptPassed( - $objExercise, - $resultado, - $total + $this, + $bestAttempt['exe_result'], + $bestAttempt['exe_weighting'] ); if ($percentSuccess == 0 && $pass == false) { - return ''; + return null; } $canRemedial = ($pass == false) ? true : false; //Examen de siguiente nivel @@ -10962,11 +10980,9 @@ class Exercise } } } - $objExercise = new Exercise(); - $objExercise->read($bestAttempt['exe_id']); - $percentSuccess = (float) $objExercise->selectPassPercentage(); + $percentSuccess = (float) $this->selectPassPercentage(); $pass = ExerciseLib::isPassPercentageAttemptPassed( - $objExercise, + $this, $bestAttempt['exe_result'], $bestAttempt['exe_weighting'] ); diff --git a/main/exercise/overview.php b/main/exercise/overview.php index a910104bb5..3581bed011 100755 --- a/main/exercise/overview.php +++ b/main/exercise/overview.php @@ -195,8 +195,19 @@ if ($visible_return['value'] == false) { $message = $visible_return['message']; $exercise_url_button = null; } +}else{ + $text = $objExercise->advanceCourseList(api_get_user_id()); + if(!empty($text)){ + $message = Display::return_message( + $text, + 'info', + false + ); + } + } + if (!api_is_allowed_to_session_edit()) { $exercise_url_button = null; }