Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions class/question.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')));
}

Expand Down
2 changes: 2 additions & 0 deletions class/questiongroup.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down
12 changes: 11 additions & 1 deletion class/survey.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down Expand Up @@ -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()
{

}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion core/tpl/digiquali_question_single.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<div class="question__header-content">
<div class="question-title"><?php echo $question->getNomUrl(1, '', 0, '', -1, 1); ?></div>
<div class="question-description"><?php echo $question->description; ?></div>
<div class="question-points"><?php echo ($showCorrection ? $question->formatSingleQuestionScore($questionWithCorrectAnswer) : '') ?></div>
<div class="question-points"><?php echo ($showCorrection ? $question->formatSingleQuestionScore($questionWithCorrectAnswer, $objectLine->answer) : '') ?></div>
</div>
<div class="question__header-answer">
<?php print show_answer_from_question($question, $object, $questionAnswer, $questionGroupId, $showCorrection); ?>
Expand Down
2 changes: 1 addition & 1 deletion lib/digiquali_answer.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down