Fix code observations to PR, including parse errors, wrong variables naming, French text (still remains some), spacing and a potential security vulnerability

pull/2591/head
Yannick Warnier 8 years ago
parent c3a04bb8c6
commit 1e7e164dab
  1. 42
      main/exercise/exercise.class.php
  2. 8
      main/exercise/exercise_show.php
  3. 15
      main/exercise/exercise_submit.php
  4. 117
      main/exercise/multipleAnswerTrueFalseDegreeCertainty.php
  5. 82
      main/inc/lib/exercise.lib.php
  6. 81
      main/inc/lib/exercise_show_functions.lib.php

@ -2851,12 +2851,12 @@ class Exercise
}
$sql = "SELECT exe_id
FROM $table_track_e_exercises
WHERE
c_id = ".api_get_course_int_id()." AND
exe_exo_id = ".$this->id." AND
session_id = ".api_get_session_id()." ".
$sql_where;
FROM $table_track_e_exercises
WHERE
c_id = ".api_get_course_int_id()." AND
exe_exo_id = ".$this->id." AND
session_id = ".api_get_session_id()." ".
$sql_where;
$result = Database::query($sql);
$exe_list = Database::store_result($result);
@ -3384,9 +3384,11 @@ class Exercise
$totalScore = 0;
// Extra information of the question
if ($answerType == MULTIPLE_ANSWER_TRUE_FALSE ||
$answerType == MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY &&
!empty($extra)
if ((
$answerType == MULTIPLE_ANSWER_TRUE_FALSE ||
$answerType == MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY
)
&& !empty($extra)
) {
$extra = explode(':', $extra);
if ($debug) {
@ -3566,7 +3568,7 @@ class Exercise
$sql = "SELECT answer
FROM $TBL_TRACK_ATTEMPT
WHERE
exe_id = $exeId AND question_id = ".$questionId;
exe_id = $exeId AND question_id = $questionId";
$result = Database::query($sql);
while ($row = Database::fetch_array($result)) {
@ -3820,12 +3822,12 @@ class Exercise
$choice[$j] = null;
}
} else {
// This value is the user input, not escaped while correct answer is escaped by fckeditor
// This value is the user input, not escaped while correct answer is escaped by ckeditor
$choice[$j] = api_htmlentities(trim($choice[$j]));
}
$user_tags[] = $choice[$j];
//put the contents of the [] answer tag into correct_tags[]
// Put the contents of the [] answer tag into correct_tags[]
$correct_tags[] = api_substr($temp, 0, $pos);
$j++;
$temp = api_substr($temp, $pos + 1);
@ -5631,14 +5633,14 @@ class Exercise
if ($choice != 0) {
$reply = array_keys($choice);
for ($i = 0; $i < sizeof($reply); $i++) {
$answerChoosen = $reply[$i];
$chosenAnswer = $reply[$i];
if ($answerType == MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY) {
if ($choiceDegreeCertainty != 0) {
$replyDegreeCertainty = array_keys($choiceDegreeCertainty);
$answerDegreeCertainty = $replyDegreeCertainty[$i];
Event::saveQuestionAttempt(
$questionScore,
$answerChoosen.':'.$choice[$answerChoosen].':'.$choiceDegreeCertainty[$answerDegreeCertainty],
$chosenAnswer.':'.$choice[$chosenAnswer].':'.$choiceDegreeCertainty[$answerDegreeCertainty],
$quesId,
$exeId,
$i,
@ -5648,7 +5650,7 @@ class Exercise
} else {
Event::saveQuestionAttempt(
$questionScore,
$answerChoosen.':'.$choice[$answerChoosen],
$chosenAnswer.':'.$choice[$chosenAnswer],
$quesId,
$exeId,
$i,
@ -5656,7 +5658,7 @@ class Exercise
);
}
if ($debug) {
error_log('result =>'.$questionScore.' '.$answerChoosen.':'.$choice[$answerChoosen]);
error_log('result =>'.$questionScore.' '.$chosenAnswer.':'.$choice[$chosenAnswer]);
}
}
} else {
@ -5792,10 +5794,10 @@ class Exercise
}
if ($saved_results) {
$stat_table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
$sql = 'UPDATE '.$stat_table.' SET
exe_result = exe_result + '.floatval($questionScore).'
WHERE exe_id = '.$exeId;
$statsTable = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
$sql = "UPDATE $statsTable SET
exe_result = exe_result + ".floatval($questionScore)."
WHERE exe_id = $exeId";
Database::query($sql);
if ($debug) {
error_log($sql);

@ -955,14 +955,14 @@ $totalScoreText = '';
// Total score
$my_total_score_temp = $totalScore;
if ($origin != 'learnpath' || ($origin == 'learnpath' && isset($_GET['fb_type']))) {
if ($show_results || $show_only_total_score || $showTotalScoreAndUserChoicesInLastAttempt) {
$totalScoreText .= '<div class="question_row">';
if ($show_results || $show_only_total_score || $showTotalScoreAndUserChoicesInLastAttempt) {
$totalScoreText .= '<div class="question_row">';
if ($objExercise->selectPropagateNeg() == 0 && $myTotalScoreTemp < 0) {
$myTotalScoreTemp = 0;
$myTotalScoreTemp = 0;
}
if ($answerType == MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY) {
$totalScoreText .= ExerciseLib::getQuestionRibbonDiag(
$totalScoreText .= ExerciseLib::getQuestionDiagnosisRibbon(
$objExercise,
$myTotalScoreTemp,
$totalWeighting,

@ -791,7 +791,7 @@ if ($question_count != 0) {
header('Location: exercise_reminder.php?'.$params);
exit;
} else {
// Question degree certainty
// Certainty grade question
// We send un email to the student before redirection to the result page
$userInfo = api_get_user_info($user_id);
$recipient_name = api_get_person_name($userInfo['firstname'],
@ -805,21 +805,18 @@ if ($question_count != 0) {
null,
PERSON_NAME_EMAIL_ADDRESS
);
$emailGenerique = api_get_setting('emailAdministrator');
$senderEmail = api_get_setting('emailAdministrator');
$subject = "[".get_lang('DoNotReply')."] "
.html_entity_decode(get_lang('ResultAccomplishedTest')." \"".$objExercise->title."\"");
// message sended to the student
// message sent to the student
$message = get_lang('Dear').' '.$recipient_name.",<br><br>";
$message .= get_lang('MessageQuestionCertainty');
$exerciseLink = "<a href='".api_get_path(WEB_CODE_PATH)."/exercise/result.php?show_headers=1&"
.api_get_cidreq()
."&id=$exe_id'>";
$titleExercice = $objExercise->title;
$message = str_replace('%exerTitle', $titleExercice, $message);
$message = str_replace('%webPath', api_get_path(WEB_PATH), $message);
$message = str_replace('%s', $exerciseLink, $message);
$titleExercise = $objExercise->title;
$message .= sprintf(get_lang('QuestionDegreeCertaintyHTMLMail'), $titleExercise, api_get_path(WEB_PATH), $exerciseLink);
// show histogram
require_once api_get_path(SYS_CODE_PATH)
@ -833,7 +830,7 @@ if ($question_count != 0) {
$subject,
$message,
$senderName,
$emailGenerique,
$senderEmail,
['content-type' => 'html']
);

@ -21,8 +21,6 @@ class MultipleAnswerTrueFalseDegreeCertainty extends Question
public $optionsTitle;
public $options;
// const TEST = get_lang('new');
/**
* Constructor.
*/
@ -31,7 +29,7 @@ class MultipleAnswerTrueFalseDegreeCertainty extends Question
parent::__construct();
$this->type = MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY;
$this->isContent = $this->getIsContent();
$this->optionsTitle = [1 => 'langAnswers', 2 => 'DegreeOfCertainty'];
$this->optionsTitle = [1 => 'Answers', 2 => 'DegreeOfCertaintyThatMyAnswerIsCorrect'];
$this->options = [
1 => 'True',
2 => 'False',
@ -45,13 +43,15 @@ class MultipleAnswerTrueFalseDegreeCertainty extends Question
}
/**
* function which redefines Question::createAnswersForm.
*
* Redefines Question::createAnswersForm: creates the HTML form to answer the question
* @param FormValidator $form
* @throws \Exception
* @uses globals $text and $class, defined in the calling script
*/
public function createAnswersForm($form)
{
$nbAnswers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 4;
global $text, $class;
$nbAnswers = isset($_POST['nb_answers']) ? (int) $_POST['nb_answers'] : 4;
// The previous default value was 2. See task #1759.
$nbAnswers += (isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0));
@ -92,7 +92,7 @@ class MultipleAnswerTrueFalseDegreeCertainty extends Question
if ($nbAnswers < 1) {
$nbAnswers = 1;
Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
echo Display::return_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
}
// Can be more options
@ -192,10 +192,10 @@ class MultipleAnswerTrueFalseDegreeCertainty extends Question
}
}
global $text, $class;
if ($objEx->edit_exercise_in_lp == true) {
$form->addElement('submit', 'lessAnswers', get_lang('LessAnswer'), 'class="btn minus"');
$form->addElement('submit', 'moreAnswers', get_lang('PlusAnswer'), 'class="btn plus"');
//$text and $class defined in calling script
$form->addElement('submit', 'submitQuestion', $text, 'class="'.$class.'"');
}
$renderer->setElementTemplate('{element}&nbsp;', 'lessAnswers');
@ -286,6 +286,7 @@ class MultipleAnswerTrueFalseDegreeCertainty extends Question
}
/**
* Show result table headers
* @param int $feedbackType
* @param int $counter
* @param float $score
@ -388,36 +389,36 @@ class MultipleAnswerTrueFalseDegreeCertainty extends Question
}
/**
* Method to recovery lable for codes colors.
* Method to recover labels for color codes.
*
* @param $studentAnwser
* @param $studentAnswer
* @param $expectedAnswer
* @param $studentDegreeChoicePosition
*
* @return string
*/
public function getCodeResponse($studentAnwser, $expectedAnswer, $studentDegreeChoicePosition)
public function getCodeResponse($studentAnswer, $expectedAnswer, $studentDegreeChoicePosition)
{
$checkResult = ($studentAnwser == $expectedAnswer) ? true : false;
$checkResult = ($studentAnswer == $expectedAnswer) ? true : false;
if ($checkResult) {
if ($studentDegreeChoicePosition >= 6) {
return get_lang('langVerySure');
return get_lang('DegreeOfCertaintyVerySure');
}
if ($studentDegreeChoicePosition >= 4 && $studentDegreeChoicePosition <= 5) {
return get_lang('langPrettySur');
return get_lang('DegreeOfCertaintyPrettySure');
}
if ($studentDegreeChoicePosition == 3) {
return get_lang('langIgnorance');
return get_lang('DegreeOfCertaintyDeclaredIgnorance');
}
} else {
if ($studentDegreeChoicePosition >= 6) {
return get_lang('langVeryUnsure');
return get_lang('DegreeOfCertaintyVeryUnsure');
}
if ($studentDegreeChoicePosition >= 4 && $studentDegreeChoicePosition <= 5) {
return get_lang('langUnsure');
return get_lang('DegreeOfCertaintyUnsure');
}
if ($studentDegreeChoicePosition == 3) {
return get_lang('langIgnorance');
return get_lang('DegreeOfCertaintyIgnorance');
}
}
}
@ -436,8 +437,8 @@ class MultipleAnswerTrueFalseDegreeCertainty extends Question
&nbsp;
</td>
<td style="padding-left:10px;">
<b><?php echo get_lang('langVerySure'); ?> :</b>
<?php echo get_lang('langExplainVerySure'); ?>
<b><?php echo get_lang('DegreeOfCertaintyVerySure'); ?> :</b>
<?php echo get_lang('DegreeOfCertaintyVerySureDescription'); ?>
</td>
</tr>
<tr style="border-bottom: 1px solid #A39E9E;">
@ -445,8 +446,8 @@ class MultipleAnswerTrueFalseDegreeCertainty extends Question
&nbsp;
</td>
<td style="padding-left:10px;">
<b><?php echo get_lang('langPrettySur'); ?> :</b>
<?php echo get_lang('langExplainPrettySur'); ?>
<b><?php echo get_lang('DegreeOfCertaintyPrettySure'); ?> :</b>
<?php echo get_lang('DegreeOfCertaintyPrettySureDescription'); ?>
</td>
</tr>
<tr style="border: 1px solid #A39E9E;">
@ -454,8 +455,8 @@ class MultipleAnswerTrueFalseDegreeCertainty extends Question
&nbsp;
</td>
<td style="padding-left:10px;">
<b><?php echo get_lang('langIgnorance'); ?> :</b>
<?php echo get_lang('langExplainIgnorance'); ?>
<b><?php echo get_lang('DegreeOfCertaintyDeclaredIgnorance'); ?> :</b>
<?php echo get_lang('DegreeOfCertaintyDeclaredIgnoranceDescription'); ?>
</td>
</tr>
<tr style="border: 1px solid #A39E9E;">
@ -463,8 +464,8 @@ class MultipleAnswerTrueFalseDegreeCertainty extends Question
&nbsp;
</td>
<td style="padding-left:10px;">
<b><?php echo get_lang('langUnsure'); ?> :</b>
<?php echo get_lang('langExplainUnsure'); ?>
<b><?php echo get_lang('DegreeOfCertaintyUnsure'); ?> :</b>
<?php echo get_lang('DegreeOfCertaintyUnsureDescription'); ?>
</td>
</tr>
<tr style="border-bottom: 1px solid #A39E9E;">
@ -472,8 +473,8 @@ class MultipleAnswerTrueFalseDegreeCertainty extends Question
&nbsp;
</td>
<td style="padding-left:10px;">
<b><?php echo get_lang('langVeryUnsure'); ?> :</b>
<?php echo get_lang('langExplainVeryUnsure'); ?>
<b><?php echo get_lang('DegreeOfCertaintyVeryUnsure'); ?> :</b>
<?php echo get_lang('DegreeOfCertaintyVeryUnsureDescription'); ?>
</td>
</tr>
</table><br/>
@ -481,11 +482,19 @@ class MultipleAnswerTrueFalseDegreeCertainty extends Question
<?php
}
public static function displayDegreeChartByCategory($scoreListAll, $title, $sizeRatio = 1, $objExercice)
/**
* Display basic bar charts of results by category of questions
* @param array $scoreListAll
* @param string $title The block title
* @param int $sizeRatio
* @param Exercise $objExercise
* @return string The HTML/CSS code for the charts block
*/
public static function displayDegreeChartByCategory($scoreListAll, $title, $sizeRatio = 1, $objExercise)
{
$maxHeight = 0;
if ($objExercice->gather_questions_categories == 1) { // original
if ($objExercise->gather_questions_categories == 1) { // original
$groupCategoriesByBracket = true;
} else {
$groupCategoriesByBracket = false;
@ -494,7 +503,7 @@ class MultipleAnswerTrueFalseDegreeCertainty extends Question
if ($groupCategoriesByBracket) {
$scoreList = [];
$categoryPrefixList = []; // categoryPrefix['Math'] = firstCategoryId for this prefix
// rebuild $scoreList factirizing datas with caregory prefix
// rebuild $scoreList factorizing data with category prefix
foreach ($scoreListAll as $categoryId => $scoreListForCategory) {
$objCategory = new Testcategory();
$objCategoryNum = $objCategory->getCategory($categoryId);
@ -519,7 +528,7 @@ class MultipleAnswerTrueFalseDegreeCertainty extends Question
$scoreList[$categoryId] = $scoreListAll[$categoryId];
}
} else {
// dont matche the prefix '[math] Math category'
// doesn't match the prefix '[math] Math category'
$scoreList[$categoryId] = $scoreListAll[$categoryId];
}
}
@ -529,8 +538,8 @@ class MultipleAnswerTrueFalseDegreeCertainty extends Question
// get the max height of item to have each table the same height if displayed side by side
foreach ($scoreList as $categoryId => $scoreListForCategory) {
$testCategorie = new TestCategory();
$categorieQuestionName = $testCategorie->getCategory($categoryId)->name;
$testCategory = new TestCategory();
$categoryQuestionName = $testCategory->getCategory($categoryId)->name;
list($null, $height) = self::displayDegreeChart(
$scoreListForCategory,
300,
@ -559,10 +568,10 @@ class MultipleAnswerTrueFalseDegreeCertainty extends Question
$i = 0;
foreach ($scoreList as $categoryId => $scoreListForCategory) {
$oCategory = new Testcategory();
$categorieQuestionName = $oCategory->getCategory($categoryId)->name;
$categoryQuestionName = $oCategory->getCategory($categoryId)->name;
if ($categorieQuestionName == '') {
$categoryName = get_lang('NonCategory');
if ($categoryQuestionName == '') {
$categoryName = get_lang('WithoutCategory');
} else {
$categoryName = $oCategory->name;
}
@ -735,7 +744,7 @@ class MultipleAnswerTrueFalseDegreeCertainty extends Question
$title = ucfirst(api_preg_replace("/[\[\]]/", "", $title));
}
$affiche = (strpos($title, "ensemble") > 0) ?
$display = (strpos($title, "ensemble") > 0) ?
$title."<br/>($totalAttemptNumber questions)" :
$title;
$textSize = (
@ -758,7 +767,7 @@ class MultipleAnswerTrueFalseDegreeCertainty extends Question
$html .= '<tr><th colspan="5" class="'
.$classGlobalChart
.'">'
.$affiche
.$display
.'</th><tr>'
;
@ -824,13 +833,13 @@ class MultipleAnswerTrueFalseDegreeCertainty extends Question
$html .= '</tr>';
if ($displayExplanationText) {
// affichage texte histogramme
// Display of histogram text
$explainHistoList = [
'langVeryUnsure',
'langUnsure',
'langIgnorance',
'langPrettySur',
'langVerySure', ];
'DegreeOfCertaintyVeryUnsure',
'DegreeOfCertaintyUnsure',
'DegreeOfCertaintyIgnorance',
'DegreeOfCertaintyPrettySure',
'DegreeOfCertaintyVerySure', ];
$html .= '<tr>';
$i = 0;
foreach ($explainHistoList as $explain) {
@ -886,7 +895,7 @@ class MultipleAnswerTrueFalseDegreeCertainty extends Question
}
$data = Database::fetch_assoc($res);
$courseCode = $data['exe_cours_id'];
$courseCode = $data['c_id'];
$exerciseId = $data['exe_exo_id'];
$userId = $data['exe_user_id'];
$attemptDate = $data['exe_date'];
@ -897,14 +906,16 @@ class MultipleAnswerTrueFalseDegreeCertainty extends Question
}
// look for previous attempt
$exerciseId = (int) $exerciseId;
$userId = (int) $userId;
$sql = "SELECT *
FROM $tblTrackEExercise
WHERE c_id = '".$courseCode."'
AND exe_exo_id = ".intval($exerciseId)."
AND exe_user_id = ".intval($userId)."
WHERE c_id = '$courseCode'
AND exe_exo_id = $exerciseId
AND exe_user_id = $userId
AND status = ''
AND exe_date > '0000-00-00 00:00:00'
AND exe_date < '".$attemptDate."'
AND exe_date < '$attemptDate'
ORDER BY exe_date DESC";
$res = Database::query($sql);
@ -1179,7 +1190,7 @@ class MultipleAnswerTrueFalseDegreeCertainty extends Question
$html = MultipleAnswerTrueFalseDegreeCertainty::displayDegreeChart(
$globalScoreList,
600,
get_lang('ResultTest'),
get_lang('YourOverallResultForTheTest'),
2,
0,
true,
@ -1198,7 +1209,7 @@ class MultipleAnswerTrueFalseDegreeCertainty extends Question
$html .= MultipleAnswerTrueFalseDegreeCertainty::displayDegreeChart(
$previousAttemptScoreList,
600,
get_lang('CompareLastResult'),
get_lang('ForComparisonYourLastResultToThisTest'),
2
)
."<br/>"
@ -1208,7 +1219,7 @@ class MultipleAnswerTrueFalseDegreeCertainty extends Question
$categoryScoreList = MultipleAnswerTrueFalseDegreeCertainty::getColorNumberListForAttemptByCategory($exeId);
$html .= MultipleAnswerTrueFalseDegreeCertainty::displayDegreeChartByCategory(
$categoryScoreList,
get_lang('ResultsbyDiscipline'),
get_lang('YourResultsByDiscipline'),
1, $objExercice
)
."<br/>"

@ -7,7 +7,7 @@ use ChamiloSession as Session;
* Class ExerciseLib
* shows a question and its answers.
*
* @author Olivier Brouckaert <oli.brouckaert@skynet.be>
* @author Olivier Brouckaert <oli.brouckaert@skynet.be> 2003-2004
* @author Hubert Borderiou 2011-10-21
* @author ivantcholakov2009-07-20
*/
@ -28,6 +28,7 @@ class ExerciseLib
* @param bool $show_answers
*
* @return bool|int
* @throws \Exception
*/
public static function showQuestion(
$exercise,
@ -348,10 +349,10 @@ class ExerciseLib
foreach ($objQuestionTmp->optionsTitle as $item) {
if (in_array($item, $objQuestionTmp->optionsTitle)) {
$properties = [];
if ($item == "langAnswers") {
if ($item == 'Answers') {
$properties["colspan"] = 2;
$properties["style"] = "background-color: #F56B2A; color: #ffffff;";
} elseif ($item == "DegreeOfCertainty") {
} elseif ($item == 'DegreeOfCertaintyThatMyAnswerIsCorrect') {
$properties["colspan"] = 6;
$properties["style"] = "background-color: #330066; color: #ffffff;";
}
@ -393,12 +394,12 @@ class ExerciseLib
// add explanation
$header2 = Display::tag('th', '&nbsp;');
$descriptionList = [
get_lang('Ignorance'),
get_lang('VeryUnsure'),
get_lang('Unsure'),
get_lang('PrettySur'),
get_lang('Sur'),
get_lang('VerySur'),
get_lang('DegreeOfCertaintyIDeclareMyIgnorance'),
get_lang('DegreeOfCertaintyIAmVeryUnsure'),
get_lang('DegreeOfCertaintyIAmUnsure'),
get_lang('DegreeOfCertaintyIAmPrettySure'),
get_lang('DegreeOfCertaintyIAmSure'),
get_lang('DegreeOfCertaintyIAmVerySure'),
];
$counter2 = 0;
@ -558,10 +559,10 @@ class ExerciseLib
$s .= $answer_input;
}
break;
case MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY:
case MULTIPLE_ANSWER:
case MULTIPLE_ANSWER_TRUE_FALSE:
case GLOBAL_MULTIPLE_ANSWER:
case MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY:
$input_id = 'choice-'.$questionId.'-'.$answerId;
$answer = Security::remove_XSS($answer, STUDENT);
@ -949,13 +950,11 @@ class ExerciseLib
$answer,
$studentAnswerList
);
$studentAnswerListTobecleaned = $studentAnswerList[0];
$studentAnswerListToClean = $studentAnswerList[0];
$studentAnswerList = [];
for ($i = 0; $i < count(
$studentAnswerListTobecleaned
); $i++) {
$answerCorrected = $studentAnswerListTobecleaned[$i];
for ($i = 0; $i < count($studentAnswerListToClean); $i++) {
$answerCorrected = $studentAnswerListToClean[$i];
$answerCorrected = api_preg_replace(
'| / <font color="green"><b>.*$|',
'',
@ -1000,7 +999,7 @@ class ExerciseLib
' '.$answer.' '
);
if (!empty($correctAnswerList) && !empty($studentAnswerList)) {
$answer = "";
$answer = '';
$i = 0;
foreach ($studentAnswerList as $studentItem) {
// remove surronding brackets
@ -1093,8 +1092,8 @@ class ExerciseLib
if (isset($select_items[$lines_count])) {
$s .= '<div class="text-right">
<p class="indent">'.
$select_items[$lines_count]['letter'].'.&nbsp; '.
$select_items[$lines_count]['answer'].'
$select_items[$lines_count]['letter'].'.&nbsp; '.
$select_items[$lines_count]['answer'].'
</p>
</div>';
} else {
@ -1112,7 +1111,7 @@ class ExerciseLib
<td colspan="2"></td>
<td valign="top">';
$s .= '<b>'.$select_items[$lines_count]['letter'].'.</b> '.
$select_items[$lines_count]['answer'];
$select_items[$lines_count]['answer'];
$s .= "</td>
</tr>";
$lines_count++;
@ -1960,7 +1959,6 @@ HOTSPOT;
$courseCode = null,
$showSessionField = false,
$showExerciseCategories = false,
$userExtraFieldsToAdd = []
$userExtraFieldsToAdd = [],
$useCommaAsDecimalPoint = false,
$roundValues = false
@ -1976,7 +1974,12 @@ HOTSPOT;
}
$course_id = $courseInfo['real_id'];
$is_allowedToEdit = api_is_allowed_to_edit(null, true) || api_is_allowed_to_edit(true) || api_is_drh() || api_is_student_boss();
$is_allowedToEdit =
api_is_allowed_to_edit(null, true) ||
api_is_allowed_to_edit(true) ||
api_is_drh() ||
api_is_student_boss() ||
api_is_session_admin();
$TBL_USER = Database::get_main_table(TABLE_MAIN_USER);
$TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
$TBL_GROUP_REL_USER = Database::get_course_table(TABLE_GROUP_USER);
@ -2213,6 +2216,15 @@ HOTSPOT;
}
}
$scoreDisplay = new ScoreDisplay();
$decimalSeparator = '.';
$thousandSeparator = ',';
if ($useCommaAsDecimalPoint) {
$decimalSeparator = ',';
$thousandSeparator = '';
}
$listInfo = [];
// Simple exercises
if (empty($hotpotatoe_where)) {
@ -2627,7 +2639,6 @@ HOTSPOT;
true,
true,
true, // $show_only_percentage = false
true // hide % sign
true, // hide % sign
$decimalSeparator,
$thousandSeparator,
@ -2646,10 +2657,6 @@ HOTSPOT;
true,
true,
true,
true
);
$results[$i]['only_score'] = $my_res;
$results[$i]['total'] = $my_total;
true,
$decimalSeparator,
$thousandSeparator,
@ -2765,12 +2772,6 @@ HOTSPOT;
* Converts the score with the exercise_max_note and exercise_min_score
* the platform settings + formats the results using the float_format function.
*
* @param float $score
* @param float $weight
* @param bool $show_percentage show percentage or not
* @param bool $use_platform_settings use or not the platform settings
* @param bool $show_only_percentage
* @param bool $hidePercetangeSign hide "%" sign
* @param float $score
* @param float $weight
* @param bool $show_percentage show percentage or not
@ -2789,7 +2790,6 @@ HOTSPOT;
$show_percentage = true,
$use_platform_settings = true,
$show_only_percentage = false,
$hidePercetangeSign = false
$hidePercentageSign = false,
$decimalSeparator = '.',
$thousandSeparator = ',',
@ -2853,7 +2853,7 @@ HOTSPOT;
$html = '';
if ($show_percentage) {
$percentageSign = '%';
if ($hidePercetangeSign) {
if ($hidePercentageSign) {
$percentageSign = '';
}
$html = $percentage."$percentageSign ($score / $weight)";
@ -3842,7 +3842,7 @@ EOT;
* @param int $question_id
* @param int $exercise_id
*
* @return int
* @return array
*/
public static function getNumberStudentsFillBlanksAnswerCount(
$question_id,
@ -3885,6 +3885,7 @@ EOT;
}
/**
* Get the number of questions with answers
* @param int $question_id
* @param int $exercise_id
* @param string $course_code
@ -3976,6 +3977,7 @@ EOT;
}
/**
* Get number of answers to hotspot questions
* @param int $answer_id
* @param int $question_id
* @param int $exercise_id
@ -4330,6 +4332,7 @@ EOT;
}
/**
* Return an HTML select menu with the student groups
* @param string $in_name is the name and the id of the <select>
* @param string $in_default default value for option
* @param string $in_onchange
@ -4528,6 +4531,7 @@ EOT;
}
$countPendingQuestions = 0;
$result = [];
// Loop over all question to show results for each of them, one by one
if (!empty($question_list)) {
foreach ($question_list as $questionId) {
@ -4697,11 +4701,12 @@ EOT;
$totalScoreText = null;
if ($show_results || $show_only_score) {
if ($result['answer_type'] == MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY) {
echo "<h1 style='text-align : center; margin : 20px 0;'>Vos Résultats</h1><br>";
echo '<h1 style="text-align : center; margin : 20px 0;">'.get_lang('YourResults').'</h1><br />';
}
$totalScoreText .= '<div class="question_row_score">';
if ($result['answer_type'] == MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY) {
$totalScoreText .= self::getQuestionRibbonDiag($objExercise,
$totalScoreText .= self::getQuestionDiagnosisRibbon(
$objExercise,
$total_score,
$total_weight,
true
@ -4807,6 +4812,7 @@ EOT;
}
/**
* Get a special ribbon on top of "degree of certainty" questions (variation from getTotalScoreRibbon() for other question types)
* @param Exercise $objExercise
* @param float $score
* @param float $weight
@ -4814,7 +4820,7 @@ EOT;
*
* @return string
*/
public static function getQuestionRibbonDiag($objExercise, $score, $weight, $checkPassPercentage = false)
public static function getQuestionDiagnosisRibbon($objExercise, $score, $weight, $checkPassPercentage = false)
{
$displayChartDegree = true;
$ribbon = $displayChartDegree ? '<div class="ribbon">' : '';

@ -506,9 +506,7 @@ class ExerciseShowFunctions
* @param string $answer
* @param string $answerComment
* @param int $answerCorrect
* @param int $id
* @param int $questionId
* @param int $answerNumber
* @param bool $inResultsDisabled
*/
public static function displayMultipleAnswerTrueFalseDegreeCertainty(
@ -532,12 +530,12 @@ class ExerciseShowFunctions
$courseId = api_get_course_int_id();
$newOptions = Question::readQuestionOption($questionId, $courseId);
//Your choice
if (isset($newOptions[$studentChoice])) {
echo get_lang($newOptions[$studentChoice]['name']);
} else {
echo '-';
} ?>
//Your choice
if (isset($newOptions[$studentChoice])) {
echo get_lang($newOptions[$studentChoice]['name']);
} else {
echo '-';
} ?>
</td>
<td width="5%">
<?php
@ -553,48 +551,57 @@ class ExerciseShowFunctions
} ?>
</td>
<td width="25%">
<?php echo $answer; ?>
<?php
echo $answer;
?>
</td>
<td width="5%" style="text-align:center;">
<?php
echo $newOptions[$studentChoiceDegree]['name']; ?>
<?php
echo $newOptions[$studentChoiceDegree]['name'];
?>
</td>
<!-- color by certainty -->
<?php
$degreCertitudeColor = $question->getColorResponse($studentChoice,
$answerCorrect,
$newOptions[$studentChoiceDegree]['position']
);
if ($degreCertitudeColor == "#088A08" || $degreCertitudeColor == "#FE2E2E") {
$color = "#FFFFFF";
} else {
$color = "#000000";
}
$codeResponse = $question->getCodeResponse($studentChoice,
$answerCorrect,
$newOptions[$studentChoiceDegree]['position']
); ?>
$degreeCertaintyColor = $question->getColorResponse(
$studentChoice,
$answerCorrect,
$newOptions[$studentChoiceDegree]['position']
);
if ($degreeCertaintyColor == "#088A08" || $degreeCertaintyColor == "#FE2E2E") {
$color = "#FFFFFF";
} else {
$color = "#000000";
}
$responseCode = $question->getCodeResponse(
$studentChoice,
$answerCorrect,
$newOptions[$studentChoiceDegree]['position']
);
?>
<td width="10%">
<div style="text-align:center;color: <?php echo $color; ?>;
border:1px #D6D4D4 solid;background-color: <?php echo $degreCertitudeColor; ?>;
line-height:30px;height:30px;width: 100%;margin:auto;"><?php echo nl2br($codeResponse); ?>
border:1px #D6D4D4 solid;background-color: <?php echo $degreeCertaintyColor; ?>;
line-height:30px;height:30px;width: 100%;margin:auto;"><?php echo nl2br($responseCode); ?>
</div>
</td>
<?php if ($feedbackType != EXERCISE_FEEDBACK_TYPE_EXAM) {
?>
<?php
if ($feedbackType != EXERCISE_FEEDBACK_TYPE_EXAM) {
?>
<td width="20%">
<?php
$color = "black";
if (isset($newOptions[$studentChoice])) {
echo '<span style="font-weight: bold; color: '.$color.';">'.nl2br($answerComment).'</span>';
} ?>
<?php
$color = "black";
if (isset($newOptions[$studentChoice])) {
echo '<span style="font-weight: bold; color: '.$color.';">'.nl2br($answerComment).'</span>';
}
?>
</td>
<?php
} else {
?>
<td>&nbsp;</td>
<?php
} ?>
?>
<td>&nbsp;</td>
<?php
}
?>
</tr>
<?php
}

Loading…
Cancel
Save