Merge of degre certainty question type

pull/2591/head
Ivan Zambrano 8 years ago
parent 27671f529f
commit a2284cccc3
  1. 70
      main/exercise/exercise_submit.php
  2. 85
      main/exercise/multipleAnswerTrueFalseDegreeCertainty.php
  3. 4
      main/inc/ajax/exercise.ajax.php
  4. 116
      main/inc/lib/exercise.lib.php
  5. 47
      main/inc/lib/exercise_show_functions.lib.php

@ -792,46 +792,9 @@ if ($question_count != 0) {
exit;
} else {
// 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'],
$userInfo['lastname'],
null,
PERSON_NAME_EMAIL_ADDRESS
);
$emailTo = $userInfo['email'];
$senderName = api_get_person_name(api_get_setting('administratorName'),
api_get_setting('administratorSurname'),
null,
PERSON_NAME_EMAIL_ADDRESS
);
$senderEmail = api_get_setting('emailAdministrator');
$subject = "[".get_lang('DoNotReply')."] "
.html_entity_decode(get_lang('ResultAccomplishedTest')." \"".$objExercise->title."\"");
// message sent to the student
$message = get_lang('Dear').' '.$recipient_name.",<br><br>";
$exerciseLink = "<a href='".api_get_path(WEB_CODE_PATH)."/exercise/result.php?show_headers=1&"
.api_get_cidreq()
."&id=$exe_id'>";
$titleExercise = '<span style="font-family: Arial; font-size: 18px; color: green;">'.$objExercise->title.'</span>';
$message .= sprintf(get_lang('QuestionDegreeCertaintyHTMLMail'), $titleExercise, api_get_path(WEB_PATH), $exerciseLink);
// show histogram
require_once api_get_path(SYS_CODE_PATH)
."exercise/multipleAnswerTrueFalseDegreeCertainty.php";
$message .= MultipleAnswerTrueFalseDegreeCertainty::displayStudentsChartResults($exe_id, $objExercise);
$message .= get_lang('KindRegards').'<br />';
$message = api_preg_replace("/\\\n/", "", $message);
api_mail_html($recipient_name,
$emailTo,
$subject,
$message,
$senderName,
$senderEmail,
['content-type' => 'html']
// We send an email to the student before redirection to the result page
MultipleAnswerTrueFalseDegreeCertainty::sendQuestionCertaintyNotification(
$user_id, $objExercise, $exe_id
);
header("Location: exercise_result.php?"
@ -1243,6 +1206,9 @@ if (!empty($error)) {
//3. Hotspots
var hotspot = $(\'*[name*="hotspot[\'+question_id+\']"]\').serialize();
//4. choice for degree of certainty
var my_choiceDc = $(\'*[name*="choiceDegreeCertainty[\'+question_id+\']"]\').serialize();
// Checking FCK
if (question_id) {
if (CKEDITOR.instances["choice["+question_id+"]"]) {
@ -1265,33 +1231,39 @@ if (!empty($error)) {
type:"post",
async: false,
url: "'.api_get_path(WEB_AJAX_PATH).'exercise.ajax.php?'.api_get_cidreq().'&a=save_exercise_by_now",
data: "'.$params.'&type=simple&question_id="+question_id+"&"+my_choice+"&"+hotspot+"&"+remind_list,
data: "'.$params.'&type=simple&question_id="+question_id+"&"+my_choice+"&"+hotspot+"&"+remind_list+"&"+my_choiceDc,
success: function(return_value) {
if (return_value == "ok") {
$("#save_for_now_"+question_id).html(\''.Display::return_icon('save.png', get_lang('Saved'), [], ICON_SIZE_SMALL).'\');
$("#save_for_now_"+question_id).html(\''.
Display::return_icon('save.png', get_lang('Saved'), [], ICON_SIZE_SMALL).'\');
} else if (return_value == "error") {
$("#save_for_now_"+question_id).html(\''.Display::return_icon('error.png', get_lang('Error'), [], ICON_SIZE_SMALL).'\');
$("#save_for_now_"+question_id).html(\''.
Display::return_icon('error.png', get_lang('Error'), [], ICON_SIZE_SMALL).'\');
} else if (return_value == "one_per_page") {
var url = "";
if ('.$reminder.' == 1 ) {
url = "exercise_reminder.php?'.$params.'&num='.$current_question.'";
} else if ('.$reminder.' == 2 ) {
url = "exercise_submit.php?'.$params.'&num='.$current_question.'&remind_question_id='.$remind_question_id.'&reminder=2";
url = "exercise_submit.php?'.$params.'&num='.$current_question.
'&remind_question_id='.$remind_question_id.'&reminder=2";
} else {
url = "exercise_submit.php?'.$params.'&num='.$current_question.'&remind_question_id='.$remind_question_id.'";
url = "exercise_submit.php?'.$params.'&num='.$current_question.
'&remind_question_id='.$remind_question_id.'";
}
if (url_extra) {
url = url_extra;
}
$("#save_for_now_"+question_id).html(\''.Display::return_icon('save.png', get_lang('Saved'), [], ICON_SIZE_SMALL).'\');
$("#save_for_now_"+question_id).html(\''.
Display::return_icon('save.png', get_lang('Saved'), [], ICON_SIZE_SMALL).'\');
window.location = url;
}
},
error: function() {
$("#save_for_now_"+question_id).html(\''.Display::return_icon('error.png', get_lang('Error'), [], ICON_SIZE_SMALL).'\');
$("#save_for_now_"+question_id).html(\''.
Display::return_icon('error.png', get_lang('Error'), [], ICON_SIZE_SMALL).'\');
}
});
}
@ -1348,7 +1320,9 @@ if (!empty($error)) {
}
</script>';
echo '<form id="exercise_form" method="post" action="'.api_get_self().'?'.api_get_cidreq().'&reminder='.$reminder.'&autocomplete=off&exerciseId='.$exerciseId.'" name="frm_exercise" '.$onsubmit.'>
echo '<form id="exercise_form" method="post" action="'.
api_get_self().'?'.api_get_cidreq().'&reminder='.$reminder.
'&autocomplete=off&exerciseId='.$exerciseId.'" name="frm_exercise" '.$onsubmit.'>
<input type="hidden" name="formSent" value="1" />
<input type="hidden" name="exerciseId" value="'.$exerciseId.'" />
<input type="hidden" name="num" value="'.$current_question.'" id="num_current_id" />

@ -44,9 +44,10 @@ class MultipleAnswerTrueFalseDegreeCertainty extends Question
/**
* 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
* @param FormValidator $form
* @throws Exception
* @throws HTML_QuickForm_Error
*/
public function createAnswersForm($form)
{
@ -100,20 +101,20 @@ class MultipleAnswerTrueFalseDegreeCertainty extends Question
for ($i = 1; $i <= $nbAnswers; ++$i) {
$renderer->setElementTemplate(
'<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>',
'correct['.$i.']'
'<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>',
'correct['.$i.']'
);
$renderer->setElementTemplate(
'<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>',
'counter['.$i.']'
'<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>',
'counter['.$i.']'
);
$renderer->setElementTemplate(
'<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>',
'answer['.$i.']'
'<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>',
'answer['.$i.']'
);
$renderer->setElementTemplate(
'<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>',
'comment['.$i.']'
'<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>',
'comment['.$i.']'
);
$answerNumber = $form->addElement('text', 'counter['.$i.']', null, 'value="'.$i.'"');
@ -270,7 +271,8 @@ class MultipleAnswerTrueFalseDegreeCertainty extends Question
$comment = trim($form->getSubmitValue('comment['.$i.']'));
$goodAnswer = trim($form->getSubmitValue('correct['.$i.']'));
if (empty($options)) {
//If this is the first time that the question is created when change the default values from the form 1 and 2 by the correct "option id" registered
// If this is the first time that the question is created then change
// the default values from the form 1 and 2 by the correct "option id" registered
$goodAnswer = $sortedByPosition[$goodAnswer]['id'];
}
$questionWeighting += $extraValues[0]; //By default 0 has the correct answers
@ -973,7 +975,11 @@ class MultipleAnswerTrueFalseDegreeCertainty extends Question
* [
* (categoryId=)5 => [LEVEL_DARKGREEN => 3, LEVEL_WHITE => 5, LEVEL_LIGHTRED => 12]
* (categoryId=)2 => [LEVEL_DARKGREEN => 8, LEVEL_LIGHTRED => 2, LEVEL_DARKTRED => 8]
* (categoryId=)0 => [LEVEL_DARKGREEN => 1, LEVEL_LIGHTGREEN => 2, LEVEL_WHITE => 6, LEVEL_LIGHTRED => 1, LEVEL_DARKTRED => 9]
* (categoryId=)0 => [LEVEL_DARKGREEN => 1,
* LEVEL_LIGHTGREEN => 2,
* LEVEL_WHITE => 6,
* LEVEL_LIGHTRED => 1,
* LEVEL_DARKTRED => 9]
* ]
*
* @param $exeId
@ -1227,4 +1233,59 @@ class MultipleAnswerTrueFalseDegreeCertainty extends Question
return $html;
}
/**
* send mail to student with degre certainty result test
* @param $userId
* @param $objExercise
* @param $exeId
*/
public static function sendQuestionCertaintyNotification($userId, $objExercise, $exeId)
{
$userInfo = api_get_user_info($userId);
$recipient_name = api_get_person_name($userInfo['firstname'],
$userInfo['lastname'],
null,
PERSON_NAME_EMAIL_ADDRESS
);
$emailTo = $userInfo['email'];
$senderName = api_get_person_name(api_get_setting('administratorName'),
api_get_setting('administratorSurname'),
null,
PERSON_NAME_EMAIL_ADDRESS
);
$genericEmail = api_get_setting('emailAdministrator');
$subject = "[".get_lang('DoNotReply')."] "
.html_entity_decode(get_lang('ResultAccomplishedTest')." \"".$objExercise->title."\"");
// message sended 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=$exeId'>";
$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);
// show histogram
require_once api_get_path(SYS_CODE_PATH)
."exercise/multipleAnswerTrueFalseDegreeCertainty.php";
$message .= MultipleAnswerTrueFalseDegreeCertainty::displayStudentsChartResults($exeId, $objExercise);
$message .= get_lang('KindRegards');
$message = api_preg_replace("/\\\n/", "", $message);
api_mail_html($recipient_name,
$emailTo,
$subject,
$message,
$senderName,
$genericEmail,
['content-type' => 'html']
);
}
}

@ -396,7 +396,7 @@ switch ($action) {
// Questions choices.
$choice = isset($_REQUEST['choice']) ? $_REQUEST['choice'] : null;
// cretainty degree choice
// certainty degree choice
$choiceDegreeCertainty = isset($_REQUEST['choiceDegreeCertainty']) ? $_REQUEST['choiceDegreeCertainty'] : null;
// Hot spot coordinates from all questions.
@ -522,7 +522,7 @@ switch ($action) {
$objQuestionTmp = Question::read($my_question_id, $course_id);
if ($objQuestionTmp->type == MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY) {
// LQ debug
$myChoiceDegreeCertainty = isset($choiceDegreeCertainty[$my_question_id]) ? $choiceDegreeCertainty[$my_question_id] : null;
}

@ -250,101 +250,89 @@ class ExerciseLib
['style' => 'text-align:left;']
);
} elseif ($answerType == MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY) {
echo "<script>
function RadioValidator(question_id, answer_id)
{
var ShowAlert = \"\";
var typeRadioB = \"\";
var AllFormElements = window.document.getElementById(\"exercise_form\").elements;
$header = Display::tag('th', get_lang('Options'), ['width' => '50%']);
echo "
<script>
function RadioValidator(question_id, answer_id)
{
var ShowAlert = '';
var typeRadioB = '';
var AllFormElements = window.document.getElementById('exercise_form').elements;
for (i = 0; i < AllFormElements.length; i++) {
if (AllFormElements[i].type == \"radio\") {
if (AllFormElements[i].type == 'radio') {
var ThisRadio = AllFormElements[i].name;
var ThisChecked = \"No\";
var ThisChecked = 'No';
var AllRadioOptions = document.getElementsByName(ThisRadio);
for (x = 0; x < AllRadioOptions.length; x++) {
if (AllRadioOptions[x].checked && ThisChecked == \"No\") {
ThisChecked = \"Yes\";
if (AllRadioOptions[x].checked && ThisChecked == 'No') {
ThisChecked = 'Yes';
break;
}
}
var AlreadySearched = ShowAlert.indexOf(ThisRadio);
if (ThisChecked == \"No\" && AlreadySearched == -1) {
if (ThisChecked == 'No' && AlreadySearched == -1) {
ShowAlert = ShowAlert + ThisRadio;
}
}
}
if (ShowAlert != \"\") {
if (ShowAlert != '') {
} else {
$(\".question-validate-btn\").attr(\"onclick\", \"save_now (\" + question_id +\", '', \" + answer_id+\")\");
$(\".question-validate-btn\").removeAttr('disabled');
$('.question-validate-btn').removeAttr('disabled');
}
}
function handleRadioRow(event, question_id, answer_id) {
var t = event.target;
if (t && t.tagName == \"INPUT\")
if (t && t.tagName == 'INPUT')
return;
while (t && t.tagName != \"TD\") {
while (t && t.tagName != 'TD') {
t = t.parentElement;
}
var r = t.getElementsByTagName(\"INPUT\")[0];
var r = t.getElementsByTagName('INPUT')[0];
r.click();
RadioValidator(question_id, answer_id);
}
$( document ).ready(function() {
var ShowAlert = \"\";
var typeRadioB = \"\";
var question_id = $('input[name=question_id]').val()
var AllFormElements = window.document.getElementById(\"exercise_form\").elements;
for (i = 0; i < AllFormElements.length; i++) {
if (AllFormElements[i].type == \"radio\") {
var ThisRadio = AllFormElements[i].name;
var ThisChecked = \"No\";
var AllRadioOptions = document.getElementsByName(ThisRadio);
for (x = 0; x < AllRadioOptions.length; x++) {
if (AllRadioOptions[x].checked && ThisChecked == \"No\") {
ThisChecked = \"Yes\";
break;
}
}
var AlreadySearched = ShowAlert.indexOf(ThisRadio);
if (ThisChecked == \"No\" && AlreadySearched == -1) {
ShowAlert = ShowAlert + ThisRadio;
var ShowAlert = '';
var typeRadioB = '';
var question_id = $('input[name=question_id]').val();
var AllFormElements = window.document.getElementById('exercise_form').elements;
for (i = 0; i < AllFormElements.length; i++) {
if (AllFormElements[i].type == 'radio') {
var ThisRadio = AllFormElements[i].name;
var ThisChecked = 'No';
var AllRadioOptions = document.getElementsByName(ThisRadio);
for (x = 0; x < AllRadioOptions.length; x++) {
if (AllRadioOptions[x].checked && ThisChecked == 'No') {
ThisChecked = \"Yes\";
break;
}
}
}
if (ShowAlert != \"\") {
$(\".question-validate-btn\").attr(\"onclick\", \"\");
$(\".question-validate-btn\").attr(\"disabled\", \"disabled\");
} else {
$(\".question-validate-btn\").attr(\"onclick\", \"save_now(\" + question_id +\", '', '')\");
$(\".question-validate-btn\").removeAttr('disabled');
}
});
var AlreadySearched = ShowAlert.indexOf(ThisRadio);
if (ThisChecked == 'No' && AlreadySearched == -1) {
ShowAlert = ShowAlert + ThisRadio;
}
}
}
if (ShowAlert != '') {
$('.question-validate-btn').attr('disabled', 'disabled');
} else {
$('.question-validate-btn').removeAttr('disabled');
}
});
</script>";
$header = Display::tag('th', get_lang('Options'), ['width' => '50%']);
foreach ($objQuestionTmp->optionsTitle as $item) {
if (in_array($item, $objQuestionTmp->optionsTitle)) {
@ -681,7 +669,8 @@ class ExerciseLib
$attributes = [];
}
$attributes['onChange'] = 'RadioValidator('.$questionId.', '.$numAnswer.')';
// gère la séletion des radio button du degré de certitude
// radio button selection
if (isset($myChoiceDegreeCertainty[$numAnswer]) &&
$id == $myChoiceDegreeCertainty[$numAnswer]
) {
@ -981,7 +970,8 @@ class ExerciseLib
}
}
// If display preview of answer in test view for exemple, set the student answer to the correct answers
// If display preview of answer in test view for exemple,
// set the student answer to the correct answers
if ($debug_mark_answer) {
// contain the rights answers surronded with brackets
$studentAnswerList = $correctAnswerList[0];

@ -265,7 +265,8 @@ class ExerciseShowFunctions
];
echo '<table class="data_table"><tr>';
echo '<td class="text-center" width="5%">';
echo '<span class="fa fa-square fa-fw fa-2x" aria-hidden="true" style="color:'.$hotspot_colors[$orderColor].'"></span>';
echo '<span class="fa fa-square fa-fw fa-2x" aria-hidden="true" style="color:'.
$hotspot_colors[$orderColor].'"></span>';
echo '</td>';
echo '<td class="text-left" width="25%">';
echo "$answerId - $answer";
@ -552,31 +553,31 @@ class ExerciseShowFunctions
</td>
<td width="25%">
<?php
echo $answer;
echo $answer;
?>
</td>
<td width="5%" style="text-align:center;">
<?php
echo $newOptions[$studentChoiceDegree]['name'];
echo $newOptions[$studentChoiceDegree]['name'];
?>
</td>
<!-- color by certainty -->
<?php
$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']
);
$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; ?>;
@ -585,14 +586,14 @@ class ExerciseShowFunctions
</div>
</td>
<?php
if ($feedbackType != EXERCISE_FEEDBACK_TYPE_EXAM) {
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>';
}
$color = "black";
if (isset($newOptions[$studentChoice])) {
echo '<span style="font-weight: bold; color: '.$color.';">'.nl2br($answerComment).'</span>';
}
?>
</td>
<?php

Loading…
Cancel
Save