diff --git a/main/exercise/UploadAnswer.php b/main/exercise/UploadAnswer.php new file mode 100644 index 0000000000..9e266bca46 --- /dev/null +++ b/main/exercise/UploadAnswer.php @@ -0,0 +1,64 @@ +type = UPLOAD_ANSWER; + $this->isContent = $this->getIsContent(); + } + + /** + * {@inheritdoc} + */ + public function createAnswersForm($form) + { + $form->addElement('text', 'weighting', get_lang('Weighting')); + global $text; + // setting the save button here and not in the question class.php + $form->addButtonSave($text, 'submitQuestion'); + if (!empty($this->iid)) { + $form->setDefaults(['weighting' => float_format($this->weighting, 1)]); + } else { + if ($this->isContent == 1) { + $form->setDefaults(['weighting' => '10']); + } + } + } + + /** + * {@inheritdoc} + */ + public function processAnswersCreation($form, $exercise) + { + $this->weighting = $form->getSubmitValue('weighting'); + $this->save($exercise); + } + + /** + * {@inheritdoc} + */ + public function return_header(Exercise $exercise, $counter = null, $score = []) + { + $score['revised'] = $this->isQuestionWaitingReview($score); + $header = parent::return_header($exercise, $counter, $score); + $header .= '
'.get_lang('Answer').' | +
---|
'. @@ -6144,6 +6165,18 @@ class Exercise false, $questionDuration ); + } elseif ($answerType == UPLOAD_ANSWER) { + $answer = $choice; + Event::saveQuestionAttempt( + $questionScore, + $answer, + $quesId, + $exeId, + 0, + $this->iid, + false, + $questionDuration + ); } elseif ($answerType == ORAL_EXPRESSION) { $answer = $choice; Event::saveQuestionAttempt( diff --git a/main/exercise/exercise_report.php b/main/exercise/exercise_report.php index d0cb7c4bc7..49052cd678 100755 --- a/main/exercise/exercise_report.php +++ b/main/exercise/exercise_report.php @@ -199,7 +199,7 @@ if (isset($_REQUEST['comments']) && // From the database. $marksFromDatabase = $questionListData[$questionId]['marks']; - if (in_array($question->type, [FREE_ANSWER, ORAL_EXPRESSION, ANNOTATION])) { + if (in_array($question->type, [FREE_ANSWER, ORAL_EXPRESSION, ANNOTATION, UPLOAD_ANSWER])) { // From the form. $params['marks'] = $marks; if ($marksFromDatabase != $marks) { diff --git a/main/exercise/exercise_show.php b/main/exercise/exercise_show.php index 4c36279bd1..442a58738b 100755 --- a/main/exercise/exercise_show.php +++ b/main/exercise/exercise_show.php @@ -441,6 +441,7 @@ foreach ($questionList as $questionId) { case CALCULATED_ANSWER: case GLOBAL_MULTIPLE_ANSWER: case FREE_ANSWER: + case UPLOAD_ANSWER: case ORAL_EXPRESSION: case MATCHING: case DRAGGABLE: @@ -604,7 +605,7 @@ foreach ($questionList as $questionId) { if ($isFeedbackAllowed && $action !== 'export') { $name = 'fckdiv'.$questionId; $marksname = 'marksName'.$questionId; - if (in_array($answerType, [FREE_ANSWER, ORAL_EXPRESSION, ANNOTATION])) { + if (in_array($answerType, [FREE_ANSWER, ORAL_EXPRESSION, ANNOTATION, UPLOAD_ANSWER])) { $url_name = get_lang('EditCommentsAndMarks'); } else { $url_name = get_lang('AddComments'); @@ -679,7 +680,7 @@ foreach ($questionList as $questionId) { } if ($is_allowedToEdit && $isFeedbackAllowed && $action !== 'export') { - if (in_array($answerType, [FREE_ANSWER, ORAL_EXPRESSION, ANNOTATION])) { + if (in_array($answerType, [FREE_ANSWER, ORAL_EXPRESSION, ANNOTATION, UPLOAD_ANSWER])) { $marksname = 'marksName'.$questionId; $arrmarks[] = $questionId; @@ -836,7 +837,7 @@ foreach ($questionList as $questionId) { } } - if (in_array($objQuestionTmp->type, [FREE_ANSWER, ORAL_EXPRESSION, ANNOTATION])) { + if (in_array($objQuestionTmp->type, [FREE_ANSWER, ORAL_EXPRESSION, ANNOTATION, UPLOAD_ANSWER])) { $scoreToReview = [ 'score' => $my_total_score, 'comments' => isset($comnt) ? $comnt : null, diff --git a/main/exercise/exercise_submit.php b/main/exercise/exercise_submit.php index 6dc46d5376..26bf694d32 100755 --- a/main/exercise/exercise_submit.php +++ b/main/exercise/exercise_submit.php @@ -70,6 +70,7 @@ $htmlHeadXtra[] = api_get_js('epiclock/renderers/minute/epiclock.minute.js'); $htmlHeadXtra[] = ''; $htmlHeadXtra[] = ''; $htmlHeadXtra[] = ''; +$htmlHeadXtra[] = api_get_jquery_libraries_js(['jquery-ui', 'jquery-upload']); if (api_get_configuration_value('quiz_prevent_copy_paste')) { $htmlHeadXtra[] = ''; } @@ -741,6 +742,12 @@ if ($formSent && isset($_POST)) { $choice = [$hotspot_id => '']; } + // Only for upload answer + if (!isset($choice) && isset($_REQUEST['uploadChoice'])) { + $uploadAnswerFileNames = $_REQUEST['uploadChoice']; + $choice = implode('|', $uploadAnswerFileNames[$questionId]); + } + // if the user has answered at least one question if (is_array($choice)) { if ($debug) { @@ -1407,6 +1414,9 @@ echo ''; + $s .= $multipleForm->returnForm(); + break; case ORAL_EXPRESSION: // Add nanog if (api_get_setting('enable_record_audio') === 'true') { @@ -5009,7 +5038,7 @@ EOT; if ($show_results) { $score = $calculatedScore; } - if (in_array($objQuestionTmp->type, [FREE_ANSWER, ORAL_EXPRESSION, ANNOTATION])) { + if (in_array($objQuestionTmp->type, [FREE_ANSWER, ORAL_EXPRESSION, ANNOTATION, UPLOAD_ANSWER])) { $reviewScore = [ 'score' => $my_total_score, 'comments' => Event::get_comments($exeId, $questionId), diff --git a/main/inc/lib/exercise_show_functions.lib.php b/main/inc/lib/exercise_show_functions.lib.php index 29ca4ec2a8..c12e3db7ef 100755 --- a/main/inc/lib/exercise_show_functions.lib.php +++ b/main/inc/lib/exercise_show_functions.lib.php @@ -102,6 +102,49 @@ class ExerciseShowFunctions } } + /** + * Shows the answer to an upload question. + * + * @param float|null $questionScore Only used to check if > 0 + * @param int $resultsDisabled Unused + */ + public static function displayUploadAnswer( + string $feedbackType, + string $answer, + int $exeId, + int $questionId, + $questionScore = null, + $resultsDisabled = 0 + ) { + if (!empty($answer)) { + $exeInfo = Event::get_exercise_results_by_attempt($exeId); + if (empty($exeInfo)) { + global $exercise_stat_info; + $userId = $exercise_stat_info['exe_user_id']; + } else { + $userId = $exeInfo[$exeId]['exe_user_id']; + } + $userWebpath = UserManager::getUserPathById($userId, 'web').'my_files'.'/upload_answer/'.$exeId.'/'.$questionId.'/'; + $filesNames = explode('|', $answer); + echo ' |
'; + foreach ($filesNames as $filename) { + $filename = Security::remove_XSS($filename); + echo ''; + } + echo ' |