diff --git a/class/question.class.php b/class/question.class.php index 85707fb6..5f2c072f 100644 --- a/class/question.class.php +++ b/class/question.class.php @@ -879,15 +879,20 @@ public static function getQuestionTypesWithBounds(): array /** * Return a formatted string to print question score (in points) * like : 0 / 3 points - * - * @param int $questionWithCorrectAnswer (values are those returned by Question::checkAnswerIsCorrect()) + *+ + * @param int $questionWithCorrectAnswer (values are those returned by Question::checkAnswerIsCorrect()) + * @param string $answer (answer of the line) * * @return string */ - public function formatSingleQuestionScore(int $questionWithCorrectAnswer): string + public function formatSingleQuestionScore(int $questionWithCorrectAnswer, string $answer): string { global $langs; + if ($this->type == $this::TYPE_PERCENTAGE) { + return ($answer != '' ? round(($answer / 100) * $this->points, 2) : 0) . ' / ' . $this->points . ' ' . strtolower(($this->points > 1 ? $langs->trans('Points') : $langs->trans('Point'))); + } + return (($questionWithCorrectAnswer >= 0) ? $this->points : 0) . ' / ' . $this->points . ' ' . strtolower(($this->points > 1 ? $langs->trans('Points') : $langs->trans('Point'))); } diff --git a/class/questiongroup.class.php b/class/questiongroup.class.php index 581df469..60a469c3 100644 --- a/class/questiongroup.class.php +++ b/class/questiongroup.class.php @@ -754,6 +754,8 @@ public function calculatePoints(SaturneObject $survey): array if ($questionId == $questionAnswer->fk_question) { if ($question->checkAnswerIsCorrect($questionAnswer->answer) >= 0) { $questionGroupCorrectAnswersTotalPoints += $question->points; + } elseif ($question->type == $question::TYPE_PERCENTAGE) { + $questionGroupCorrectAnswersTotalPoints += round($questionAnswer->answer / 100, 2); } if ($questionAnswer->answer !== '') { $numberOfAnsweredQuestions++; diff --git a/class/survey.class.php b/class/survey.class.php index 192588d3..aeed0cb9 100644 --- a/class/survey.class.php +++ b/class/survey.class.php @@ -699,8 +699,10 @@ public function calculatePoints(): array foreach ($this->lines as $questionAnswer) { if ($questionId == $questionAnswer->fk_question) { - if ($question->checkAnswerIsCorrect($questionAnswer->answer)) { + if ($question->checkAnswerIsCorrect($questionAnswer->answer) >= 0) { $surveyCorrectAnswersTotalPoints += $question->points; + } elseif ($question->type == $question::TYPE_PERCENTAGE) { + $surveyCorrectAnswersTotalPoints += round($questionAnswer->answer / 100, 2); } if ($questionAnswer->answer !== '') { $numberOfAnsweredQuestions++; @@ -804,6 +806,14 @@ public function displayAnswers(SurveyLine $objectLine, array $questionsAndGroups include DOL_DOCUMENT_ROOT . '/custom/digiquali/core/tpl/digiquali_answers.tpl.php'; } + + /** + * Get status of the survey + */ + public function getStatus() + { + + } } /** diff --git a/core/tpl/digiquali_question_single.tpl.php b/core/tpl/digiquali_question_single.tpl.php index cc99dbef..0f96c07f 100644 --- a/core/tpl/digiquali_question_single.tpl.php +++ b/core/tpl/digiquali_question_single.tpl.php @@ -52,7 +52,7 @@
getNomUrl(1, '', 0, '', -1, 1); ?>
description; ?>
-
formatSingleQuestionScore($questionWithCorrectAnswer) : '') ?>
+
formatSingleQuestionScore($questionWithCorrectAnswer, $objectLine->answer) : '') ?>
diff --git a/lib/digiquali_answer.lib.php b/lib/digiquali_answer.lib.php index 7adc434d..9b0f795a 100644 --- a/lib/digiquali_answer.lib.php +++ b/lib/digiquali_answer.lib.php @@ -135,7 +135,7 @@ function show_answer_from_question(Question $question, CommonObject $object, str $step = $questionConfig[$question->type]['step']; } - if ($showCorrection) { + if ($showCorrection && $question->type == $question::TYPE_RANGE) { $isAnswerCorrect = $question->isAnswerInQuestionRange($questionAnswer); $answerCssClass = ($isAnswerCorrect && $questionAnswer !== '' ? ' correct' : ' incorrect'); }