Internal: Refactor exercise update from 1.11.x

pull/3466/head
Julio Montoya 4 years ago
parent 76a038e0b8
commit 0670f8d288
  1. 1
      public/main/exercise/MultipleAnswerTrueFalseDegreeCertainty.php
  2. 84
      public/main/exercise/UniqueAnswerImage.php
  3. 19
      public/main/exercise/exercise.class.php
  4. 152
      public/main/exercise/exercise_result.php
  5. 3
      public/main/exercise/exercise_show.php
  6. 67
      public/main/exercise/export/qti2/Ims2Question.php
  7. 55
      public/main/exercise/export/qti2/ImsAnswerFillInBlanks.php
  8. 39
      public/main/exercise/export/qti2/ImsAnswerFree.php
  9. 97
      public/main/exercise/export/qti2/ImsAnswerHotspot.php
  10. 29
      public/main/exercise/export/qti2/ImsAnswerInterface.php
  11. 94
      public/main/exercise/export/qti2/ImsAnswerMatching.php
  12. 84
      public/main/exercise/export/qti2/ImsAnswerMultipleChoice.php
  13. 422
      public/main/exercise/export/qti2/qti2_classes.php
  14. 2
      public/main/exercise/hotspot_save.inc.php
  15. 1
      public/main/exercise/overview.php
  16. 24
      public/main/exercise/result.php
  17. 7
      public/main/exercise/stats.php
  18. 7
      public/main/template/default/exercise/result.html.twig
  19. 1
      src/CoreBundle/Composer/ScriptHandler.php

@ -213,7 +213,6 @@ class MultipleAnswerTrueFalseDegreeCertainty extends Question
) {
$form->addElement('submit', 'lessAnswers', get_lang('Remove answer option'), 'class="btn btn-danger minus"');
$form->addElement('submit', 'moreAnswers', get_lang('Add answer option'), 'class="btn btn-primary plus"');
//$text and $class defined in calling script
$form->addElement('submit', 'submitQuestion', $text, 'class = "btn btn-primary"');
}
$renderer->setElementTemplate('{element} ', 'lessAnswers');

@ -60,7 +60,74 @@ class UniqueAnswerImage extends UniqueAnswer
}
$html = '<div class="alert alert-success" role="alert">'.
get_lang('Images will be resized (up or down) to 200x150 pixels. For a better rendering of the question, we recommend you upload only images of this size.').'</div>';
get_lang('UniqueAnswerImagePreferredSize200x150').'</div>';
$zoomOptions = api_get_configuration_value('quiz_image_zoom');
if (isset($zoomOptions['options'])) {
$finderFolder = api_get_path(WEB_PATH).'vendor/studio-42/elfinder/';
$html .= '<!-- elFinder CSS (REQUIRED) -->';
$html .= '<link rel="stylesheet" type="text/css" media="screen"
href="'.$finderFolder.'css/elfinder.full.css">';
$html .= '<link rel="stylesheet" type="text/css" media="screen" href="'.$finderFolder.'css/theme.css">';
$html .= '<!-- elFinder JS (REQUIRED) -->';
$html .= '<script type="text/javascript" src="'.$finderFolder.'js/elfinder.full.js"></script>';
$html .= '<!-- elFinder translation (OPTIONAL) -->';
$language = 'en';
$platformLanguage = api_get_interface_language();
$iso = api_get_language_isocode($platformLanguage);
$filePart = "vendor/studio-42/elfinder/js/i18n/elfinder.$iso.js";
$file = api_get_path(SYS_PATH).$filePart;
$includeFile = '';
if (file_exists($file)) {
$includeFile = '<script type="text/javascript" src="'.api_get_path(WEB_PATH).$filePart.'"></script>';
$language = $iso;
}
$html .= $includeFile;
$html .= '<script type="text/javascript" charset="utf-8">
$(document).ready(function () {
$(".add_img_link").on("click", function(e){
e.preventDefault();
e.stopPropagation();
var name = $(this).prop("name");
var id = parseInt(name.match(/[0-9]+/));
$([document.documentElement, document.body]).animate({
scrollTop: $("#elfinder").offset().top
}, 1000);
var elf = $("#elfinder").elfinder({
url : "'.api_get_path(WEB_LIBRARY_PATH).'elfinder/connectorAction.php?'.api_get_cidreq().'",
getFileCallback: function(file) {
var filePath = file; //file contains the relative url.
var imageZoom = filePath.url;
var iname = "answer["+id+"]";
CKEDITOR.instances[iname].insertHtml(\'
<img
id="zoom_picture"
class="zoom_picture"
src="\'+imageZoom+\'"
data-zoom-image="\'+imageZoom+\'"
width="200px"
height="150px"
/>\');
$("#elfinder").elfinder("destroy"); //close the window after image is selected
},
startPathHash: "l2_Lw", // Sets the course driver as default
resizable: false,
lang: "'.$language.'"
}).elfinder("instance"+id);
});
});
</script>';
$html .= '<div id="elfinder"></div>';
}
$html .= '<table class="table table-striped table-hover">
<thead>
<tr style="text-align: center;">
@ -182,7 +249,20 @@ class UniqueAnswerImage extends UniqueAnswer
'counter['.$i.']'
);
$renderer->setElementTemplate(
'<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>',
'<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}'.
(isset($zoomOptions['options']) ?
'<br><div class="form-group ">
<label for="question_admin_form_btn_add_img['.$i.']" class="col-sm-2 control-label"></label>
<div class="col-sm-8">
<button class="add_img_link btn btn-info btn-sm"
name="btn_add_img['.$i.']"
type="submit"
id="question_admin_form_btn_add_img['.$i.']">
<em class="fa fa-plus"></em> '.get_lang('AddImageWithZoom').'
</button>
</div>
<div class="col-sm-2"></div>
</div>' : '').'</td>',
'answer['.$i.']'
);
$renderer->setElementTemplate(

@ -8334,10 +8334,15 @@ class Exercise
}
/**
* @param int $start
* @param int $length
* Get the question IDs from quiz_rel_question for the current quiz,
* using the parameters as the arguments to the SQL's LIMIT clause.
* Because the exercise_id is known, it also comes with a filter on
* the session, so sessions are not specified here.
*
* @return array
* @param int $start At which question do we want to start the list
* @param int $length Up to how many results we want
*
* @return array A list of question IDs
*/
public function getQuestionForTeacher($start = 0, $length = 10)
{
@ -8518,8 +8523,16 @@ class Exercise
}
/**
* Return an HTML table of exercises for on-screen printing, including
* action icons. If no exercise is present and the user can edit the
* course, show a "create test" button.
*
* @param int $categoryId
* @param string $keyword
* @param int $userId Optional.
* @param int $courseId Optional.
* @param int $sessionId Optional.
* @param bool $returnData Optional.
*
* @return string
*/

@ -80,49 +80,63 @@ if (!empty($objExercise->getResultAccess())) {
$htmlHeadXtra[] = api_get_js('epiclock/renderers/minute/epiclock.minute.js');*/
}
$htmlHeadXtra[] = api_get_build_js('exercise.js');
if (!in_array($origin, ['learnpath', 'embeddable'])) {
$showHeader = false;
$showFooter = false;
$pageActions = '';
$pageTop = '';
$pageBottom = '';
$pageContent = '';
if (!in_array($origin, ['learnpath', 'embeddable', 'mobileapp'])) {
// So we are not in learnpath tool
Display::display_header($nameTools, get_lang('Test'));
} else {
$htmlHeadXtra[] = '
<style>
body { background: none;}
</style>
';
Display::display_reduced_header();
$showHeader = true;
}
// I'm in a preview mode as course admin. Display the action menu.
if (api_is_course_admin() && !in_array($origin, ['learnpath', 'embeddable'])) {
echo '<div class="actions">';
echo '<a href="admin.php?'.api_get_cidreq().'&exerciseId='.$objExercise->id.'">'.
Display::return_icon('back.png', get_lang('Go back to the questions list'), [], 32).'</a>';
echo '<a href="exercise_admin.php?'.api_get_cidreq().'&modifyTest=yes&exerciseId='.$objExercise->id.'">'.
Display::return_icon('edit.png', get_lang('ModifyTest'), [], 32).'</a>';
echo '</div>';
$pageActions = Display::toolbarAction(
'exercise_result_actions',
[
Display::url(
Display::return_icon('back.png', get_lang('GoBackToQuestionList'), [], 32),
'admin.php?'.api_get_cidreq().'&exerciseId='.$objExercise->id
)
.Display::url(
Display::return_icon('edit.png', get_lang('ModifyExercise'), [], 32),
'exercise_admin.php?'.api_get_cidreq().'&modifyExercise=yes&exerciseId='.$objExercise->id
),
]
);
}
$exercise_stat_info = $objExercise->get_stat_track_exercise_info_by_exe_id($exe_id);
$learnpath_id = isset($exercise_stat_info['orig_lp_id']) ? $exercise_stat_info['orig_lp_id'] : 0;
$learnpath_item_id = isset($exercise_stat_info['orig_lp_item_id']) ? $exercise_stat_info['orig_lp_item_id'] : 0;
$learnpath_item_view_id = isset($exercise_stat_info['orig_lp_item_view_id']) ? $exercise_stat_info['orig_lp_item_view_id'] : 0;
if ('learnpath' === $origin) {
?>
<form method="GET" action="exercise.php?<?php echo api_get_cidreq(); ?>">
<input type="hidden" name="origin" value="<?php echo $origin; ?>" />
<input type="hidden" name="learnpath_id" value="<?php echo $learnpath_id; ?>" />
<input type="hidden" name="learnpath_item_id" value="<?php echo $learnpath_item_id; ?>"/>
<input type="hidden" name="learnpath_item_view_id" value="<?php echo $learnpath_item_view_id; ?>" />
<?php
$learnpath_item_view_id = isset($exercise_stat_info['orig_lp_item_view_id'])
? $exercise_stat_info['orig_lp_item_view_id'] : 0;
$logInfo = [
'tool' => TOOL_QUIZ,
'tool_id' => $objExercise->id,
'action' => $learnpath_id,
'action_details' => $learnpath_id,
];
Event::registerLog($logInfo);
if ($origin === 'learnpath') {
$pageTop .= '
<form method="GET" action="exercise.php?'.api_get_cidreq().'">
<input type="hidden" name="origin" value='.$origin.'/>
<input type="hidden" name="learnpath_id" value="'.$learnpath_id.'"/>
<input type="hidden" name="learnpath_item_id" value="'.$learnpath_item_id.'"/>
<input type="hidden" name="learnpath_item_view_id" value="'.$learnpath_item_view_id.'"/>
';
}
$i = $total_score = $max_score = 0;
$remainingMessage = '';
$attemptButton = '';
if ('embeddable' !== $origin) {
if ($origin !== 'embeddable') {
$attemptButton = Display::toolbarButton(
get_lang('Another attempt'),
api_get_path(WEB_CODE_PATH).'exercise/overview.php?'.api_get_cidreq().'&'.http_build_query([
@ -146,15 +160,21 @@ if ($objExercise->selectAttempts() > 0) {
$learnpath_item_view_id
);
if ($attempt_count >= $objExercise->selectAttempts()) {
echo Display::return_message(
sprintf(get_lang('You cannot take test <b>%s</b> because you have already reached the maximum of %s attempts.'), $objExercise->selectTitle(), $objExercise->selectAttempts()),
Display::addFlash(
Display::return_message(
sprintf(get_lang('ReachedMaxAttempts'), $objExercise->selectTitle(), $objExercise->selectAttempts()),
'warning',
false
)
);
if (!in_array($origin, ['learnpath', 'embeddable'])) {
//we are not in learnpath tool
Display::display_footer();
$showFooter = true;
}
$template = new Template($nameTools, $showHeader, $showFooter);
$template->assign('actions', $pageActions);
$template->display_one_col_template();
exit;
} else {
$attempt_count++;
@ -175,18 +195,18 @@ if (!empty($exercise_stat_info)) {
$max_score = $objExercise->get_max_score();
if ('embeddable' === $origin) {
showEmbeddableFinishButton();
if ($origin === 'embeddable') {
$pageTop .= showEmbeddableFinishButton();
} else {
echo Display::return_message(get_lang('Saved.').'<br />', 'normal', false);
Display::addFlash(
Display::return_message(get_lang('Saved'), 'normal', false)
);
}
$saveResults = true;
$feedbackType = $objExercise->getFeedbackType();
if (!in_array($feedbackType, [EXERCISE_FEEDBACK_TYPE_DIRECT, EXERCISE_FEEDBACK_TYPE_POPUP])) {
//$saveResults = false;
}
ob_start();
// Display and save questions
ExerciseLib::displayQuestionListByAttempt(
$objExercise,
@ -194,6 +214,8 @@ ExerciseLib::displayQuestionListByAttempt(
$saveResults,
$remainingMessage
);
$pageContent .= ob_get_contents();
ob_end_clean();
//Unset session for clock time
if (!empty($learnpath_id) && $saveResults) {
@ -210,31 +232,33 @@ ExerciseLib::exercise_time_control_delete(
ExerciseLib::delete_chat_exercise_session($exe_id);
if (!in_array($origin, ['learnpath', 'embeddable'])) {
echo '<div class="question-return">';
echo Display::url(
get_lang('Return to Course Homepage'),
if (!in_array($origin, ['learnpath', 'embeddable', 'mobileapp'])) {
$pageBottom .= '<div class="question-return">';
$pageBottom .= Display::url(
get_lang('ReturnToCourseHomepage'),
api_get_course_url(),
['class' => 'btn btn-primary']
);
echo '</div>';
$pageBottom .= '</div>';
if (api_is_allowed_to_session_edit()) {
Exercise::cleanSessionVariables();
}
Display::display_footer();
} elseif ('embeddable' === $origin) {
$showFooter = true;
} elseif (in_array($origin, ['embeddable', 'mobileapp'])) {
if (api_is_allowed_to_session_edit()) {
Exercise::cleanSessionVariables();
}
Session::write('attempt_remaining', $remainingMessage);
showEmbeddableFinishButton();
Display::display_reduced_footer();
$showFooter = false;
} else {
$lp_mode = Session::read('lp_mode');
$url = '../lp/lp_controller.php?'.api_get_cidreq().'&action=view&lp_id='.$learnpath_id.'&lp_item_id='.$learnpath_item_id.'&exeId='.$exercise_stat_info['exe_id'].'&fb_type='.$objExercise->getFeedbackType().'#atoc_'.$learnpath_item_id;
$href = 'fullscreen' === $lp_mode ? ' window.opener.location.href="'.$url.'" ' : ' top.location.href="'.$url.'"';
$url = '../lp/lp_controller.php?'.api_get_cidreq().'&action=view&lp_id='.$learnpath_id
.'&lp_item_id='.$learnpath_item_id.'&exeId='.$exercise_stat_info['exe_id']
.'&fb_type='.$objExercise->getFeedbackType().'#atoc_'.$learnpath_item_id;
$href = $lp_mode === 'fullscreen' ? ' window.opener.location.href="'.$url.'" ' : ' top.location.href="'.$url.'"';
if (api_is_allowed_to_session_edit()) {
Exercise::cleanSessionVariables();
@ -242,14 +266,26 @@ if (!in_array($origin, ['learnpath', 'embeddable'])) {
Session::write('attempt_remaining', $remainingMessage);
// Record the results in the learning path, using the SCORM interface (API)
echo "<script>window.parent.API.void_save_asset('$total_score', '$max_score', 0, 'completed');</script>";
echo '<script type="text/javascript">'.$href.'</script>';
Display::display_reduced_footer();
$pageBottom .= "<script>window.parent.API.void_save_asset('$total_score', '$max_score', 0, 'completed');</script>";
$pageBottom .= '<script type="text/javascript">'.$href.'</script>';
$showFooter = false;
}
$template = new Template($nameTools, $showHeader, $showFooter);
$template->assign('page_top', $pageTop);
$template->assign('page_content', $pageContent);
$template->assign('page_bottom', $pageBottom);
$layout = $template->fetch(
$template->get_template('exercise/result.tpl')
);
$template->assign('actions', $pageActions);
$template->assign('content', $layout);
$template->display_one_col_template();
function showEmbeddableFinishButton()
{
echo '<script>
$js = '<script>
$(function () {
$(\'.btn-close-quiz\').on(\'click\', function () {
window.parent.$(\'video:not(.skip), audio:not(.skip)\').get(0).play();
@ -257,15 +293,17 @@ function showEmbeddableFinishButton()
});
</script>';
echo Display::tag(
$html = Display::tag(
'p',
Display::toolbarButton(
get_lang('End test'),
get_lang('GoBackToVideo'),
'#',
'times',
'undo',
'warning',
['role' => 'button', 'class' => 'btn-close-quiz']
),
['class' => 'text-right']
['class' => 'text-center']
);
return $js.PHP_EOL.$html;
}

@ -313,7 +313,8 @@ if ($show_results || $show_only_total_score || $showTotalScoreAndUserChoicesInLa
// Shows exercise header
echo $objExercise->showExerciseResultHeader(
$user_info,
$track_exercise_info
$track_exercise_info,
false
);
}

@ -0,0 +1,67 @@
<?php
/* For licensing terms, see /license.txt */
/**
* @author Claro Team <cvs@claroline.net>
* @author Yannick Warnier <yannick.warnier@beeznest.com> -
* updated ImsAnswerHotspot to match QTI norms
*/
class Ims2Question extends Question
{
/**
* Include the correct answer class and create answer.
*
* @return Answer
*/
public function setAnswer()
{
switch ($this->type) {
case MCUA:
$answer = new ImsAnswerMultipleChoice($this->id);
return $answer;
case MCMA:
$answer = new ImsAnswerMultipleChoice($this->id);
return $answer;
case TF:
$answer = new ImsAnswerMultipleChoice($this->id);
return $answer;
case FIB:
$answer = new ImsAnswerFillInBlanks($this->id);
return $answer;
case MATCHING:
case MATCHING_DRAGGABLE:
$answer = new ImsAnswerMatching($this->id);
return $answer;
case FREE_ANSWER:
$answer = new ImsAnswerFree($this->id);
return $answer;
case HOT_SPOT:
$answer = new ImsAnswerHotspot($this->id);
return $answer;
default:
$answer = null;
break;
}
return $answer;
}
public function createAnswersForm($form)
{
return true;
}
public function processAnswersCreation($form, $exercise)
{
return true;
}
}

@ -0,0 +1,55 @@
<?php
/**
* Class.
*/
class ImsAnswerFillInBlanks extends Answer implements ImsAnswerInterface
{
private $answerList = [];
private $gradeList = [];
/**
* Export the text with missing words.
*/
public function imsExportResponses($questionIdent, $questionStatment)
{
$this->answerList = $this->getAnswersList(true);
$text = isset($this->answerText) ? $this->answerText : '';
if (is_array($this->answerList)) {
foreach ($this->answerList as $key => $answer) {
$key = $answer['id'];
$answer = $answer['answer'];
$len = api_strlen($answer);
$text = str_replace('['.$answer.']', '<textEntryInteraction responseIdentifier="fill_'.$key.'" expectedLength="'.api_strlen($answer).'"/>', $text);
}
}
return $text;
}
public function imsExportResponsesDeclaration($questionIdent, Question $question = null)
{
$this->answerList = $this->getAnswersList(true);
$this->gradeList = $this->getGradesList();
$out = '';
if (is_array($this->answerList)) {
foreach ($this->answerList as $answer) {
$answerKey = $answer['id'];
$answer = $answer['answer'];
$out .= ' <responseDeclaration identifier="fill_'.$answerKey.'" cardinality="single" baseType="identifier">'."\n";
$out .= ' <correctResponse>'."\n";
$out .= ' <value><![CDATA['.formatExerciseQtiText($answer).']]></value>'."\n";
$out .= ' </correctResponse>'."\n";
if (isset($this->gradeList[$answerKey])) {
$out .= ' <mapping>'."\n";
$out .= ' <mapEntry mapKey="'.$answer.'" mappedValue="'.$this->gradeList[$answerKey].'"/>'."\n";
$out .= ' </mapping>'."\n";
}
$out .= ' </responseDeclaration>'."\n";
}
}
return $out;
}
}

@ -0,0 +1,39 @@
<?php
/**
* Class.
*/
class ImsAnswerFree extends Answer implements ImsAnswerInterface
{
/**
* @todo implement
* Export the question part as a matrix-choice, with only one possible answer per line.
*
* @param string $questionIdent
* @param string $questionStatment
* @param string $questionDesc
* @param string $questionMedia
*
* @return string
*/
public function imsExportResponses($questionIdent, $questionStatment, $questionDesc = '', $questionMedia = '')
{
$questionDesc = formatExerciseQtiText($questionDesc);
return '<extendedTextInteraction responseIdentifier="'.$questionIdent.'" >
<prompt>
'.$questionDesc.'
</prompt>
</extendedTextInteraction>';
}
public function imsExportResponsesDeclaration($questionIdent, Question $question = null)
{
$out = ' <responseDeclaration identifier="'.$questionIdent.'" cardinality="single" baseType="string">';
$out .= '<outcomeDeclaration identifier="SCORE" cardinality="single" baseType="float">
<defaultValue><value>'.$question->weighting.'</value></defaultValue></outcomeDeclaration>';
$out .= ' </responseDeclaration>'."\n";
return $out;
}
}

@ -0,0 +1,97 @@
<?php
/**
* Class.
*/
class ImsAnswerHotspot extends Answer implements ImsAnswerInterface
{
private $answerList = [];
private $gradeList = [];
/**
* @todo update this to match hot spots instead of copying matching
* Export the question part as a matrix-choice, with only one possible answer per line.
*
* @param string $questionIdent
* @param string $questionStatment
* @param string $questionDesc
* @param string $questionMedia
*
* @return string
*/
public function imsExportResponses($questionIdent, $questionStatment, $questionDesc = '', $questionMedia = '')
{
$this->answerList = $this->getAnswersList(true);
$mediaFilePath = api_get_course_path().'/document/images/'.$questionMedia;
$sysQuestionMediaPath = api_get_path(SYS_COURSE_PATH).$mediaFilePath;
$questionMedia = api_get_path(WEB_COURSE_PATH).$mediaFilePath;
$mimetype = mime_content_type($sysQuestionMediaPath);
if (empty($mimetype)) {
$mimetype = 'image/jpeg';
}
$text = ' <p>'.$questionStatment.'</p>'."\n";
$text .= ' <graphicOrderInteraction responseIdentifier="hotspot_'.$questionIdent.'">'."\n";
$text .= ' <prompt>'.$questionDesc.'</prompt>'."\n";
$text .= ' <object type="'.$mimetype.'" width="250" height="230" data="'.$questionMedia.'">-</object>'."\n";
if (is_array($this->answerList)) {
foreach ($this->answerList as $key => $answer) {
$key = $answer['id'];
$answerTxt = $answer['answer'];
$len = api_strlen($answerTxt);
//coords are transformed according to QTIv2 rules here: http://www.imsproject.org/question/qtiv2p1pd/imsqti_infov2p1pd.html#element10663
$coords = '';
$type = 'default';
switch ($answer['hotspot_type']) {
case 'square':
$type = 'rect';
$res = [];
$coords = preg_match('/^\s*(\d+);(\d+)\|(\d+)\|(\d+)\s*$/', $answer['hotspot_coord'], $res);
$coords = $res[1].','.$res[2].','.((int) $res[1] + (int) $res[3]).','.((int) $res[2] + (int) $res[4]);
break;
case 'circle':
$type = 'circle';
$res = [];
$coords = preg_match('/^\s*(\d+);(\d+)\|(\d+)\|(\d+)\s*$/', $answer['hotspot_coord'], $res);
$coords = $res[1].','.$res[2].','.sqrt(pow($res[1] - $res[3], 2) + pow($res[2] - $res[4]));
break;
case 'poly':
$type = 'poly';
$coords = str_replace([';', '|'], [',', ','], $answer['hotspot_coord']);
break;
case 'delineation':
$type = 'delineation';
$coords = str_replace([';', '|'], [',', ','], $answer['hotspot_coord']);
break;
}
$text .= ' <hotspotChoice shape="'.$type.'" coords="'.$coords.'" identifier="'.$key.'"/>'."\n";
}
}
$text .= ' </graphicOrderInteraction>'."\n";
return $text;
}
public function imsExportResponsesDeclaration($questionIdent, Question $question = null)
{
$this->answerList = $this->getAnswersList(true);
$this->gradeList = $this->getGradesList();
$out = ' <responseDeclaration identifier="hotspot_'.$questionIdent.'" cardinality="ordered" baseType="identifier">'."\n";
if (is_array($this->answerList)) {
$out .= ' <correctResponse>'."\n";
foreach ($this->answerList as $answerKey => $answer) {
$answerKey = $answer['id'];
$answer = $answer['answer'];
$out .= '<value><![CDATA['.formatExerciseQtiText($answerKey).']]></value>';
}
$out .= ' </correctResponse>'."\n";
}
$out .= ' </responseDeclaration>'."\n";
return $out;
}
}

@ -0,0 +1,29 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Interface ImsAnswerInterface.
*/
interface ImsAnswerInterface
{
/**
* @param string $questionIdent
* @param string $questionStatment
* @param string $questionDesc
* @param string $questionMedia
*
* @return string
*/
public function imsExportResponses($questionIdent, $questionStatment, $questionDesc = '', $questionMedia = '');
/**
* @param $questionIdent
*
* @return mixed
*/
public function imsExportResponsesDeclaration($questionIdent, Question $question = null);
}

@ -0,0 +1,94 @@
<?php
/**
* Class.
*/
class ImsAnswerMatching extends Answer implements ImsAnswerInterface
{
public $leftList = [];
public $rightList = [];
private $answerList = [];
/**
* Export the question part as a matrix-choice, with only one possible answer per line.
*
* @param string $questionIdent
* @param string $questionStatment
* @param string $questionDesc
* @param string $questionMedia
*
* @return string
*/
public function imsExportResponses($questionIdent, $questionStatment, $questionDesc = '', $questionMedia = '')
{
$this->answerList = $this->getAnswersList(true);
$maxAssociation = max(count($this->leftList), count($this->rightList));
$out = '<matchInteraction responseIdentifier="'.$questionIdent.'" maxAssociations="'.$maxAssociation.'">'."\n";
$out .= $questionStatment;
//add left column
$out .= ' <simpleMatchSet>'."\n";
if (is_array($this->leftList)) {
foreach ($this->leftList as $leftKey => $leftElement) {
$out .= '
<simpleAssociableChoice identifier="left_'.$leftKey.'" >
<![CDATA['.formatExerciseQtiText($leftElement['answer']).']]>
</simpleAssociableChoice>'."\n";
}
}
$out .= ' </simpleMatchSet>'."\n";
//add right column
$out .= ' <simpleMatchSet>'."\n";
$i = 0;
if (is_array($this->rightList)) {
foreach ($this->rightList as $rightKey => $rightElement) {
$out .= '<simpleAssociableChoice identifier="right_'.$i.'" >
<![CDATA['.formatExerciseQtiText($rightElement['answer']).']]>
</simpleAssociableChoice>'."\n";
$i++;
}
}
$out .= ' </simpleMatchSet>'."\n";
$out .= '</matchInteraction>'."\n";
return $out;
}
public function imsExportResponsesDeclaration($questionIdent, Question $question = null)
{
$this->answerList = $this->getAnswersList(true);
$out = ' <responseDeclaration identifier="'.$questionIdent.'" cardinality="single" baseType="identifier">'."\n";
$out .= ' <correctResponse>'."\n";
$gradeArray = [];
if (isset($this->leftList) && is_array($this->leftList)) {
foreach ($this->leftList as $leftKey => $leftElement) {
$i = 0;
foreach ($this->rightList as $rightKey => $rightElement) {
if (($leftElement['match'] == $rightElement['code'])) {
$out .= ' <value>left_'.$leftKey.' right_'.$i.'</value>'."\n";
$gradeArray['left_'.$leftKey.' right_'.$i] = $leftElement['grade'];
}
$i++;
}
}
}
$out .= ' </correctResponse>'."\n";
if (is_array($gradeArray)) {
$out .= ' <mapping>'."\n";
foreach ($gradeArray as $gradeKey => $grade) {
$out .= ' <mapEntry mapKey="'.$gradeKey.'" mappedValue="'.$grade.'"/>'."\n";
}
$out .= ' </mapping>'."\n";
}
$out .= ' </responseDeclaration>'."\n";
return $out;
}
}

@ -0,0 +1,84 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Class.
*/
class ImsAnswerMultipleChoice extends Answer implements ImsAnswerInterface
{
/**
* Return the XML flow for the possible answers.
*
* @param string $questionIdent
* @param string $questionStatment
* @param string $questionDesc
* @param string $questionMedia
*
* @return string
*/
public function imsExportResponses($questionIdent, $questionStatment, $questionDesc = '', $questionMedia = '')
{
// @todo getAnswersList() converts the answers using api_html_entity_decode()
$this->answerList = $this->getAnswersList(true);
$out = ' <choiceInteraction responseIdentifier="'.$questionIdent.'" >'."\n";
$out .= ' <prompt><![CDATA['.formatExerciseQtiText($questionStatment).']]></prompt>'."\n";
if (is_array($this->answerList)) {
foreach ($this->answerList as $current_answer) {
$out .= '<simpleChoice identifier="answer_'.$current_answer['id'].'" fixed="false">
<![CDATA['.formatExerciseQtiText($current_answer['answer']).']]>';
if (isset($current_answer['comment']) && '' != $current_answer['comment']) {
$out .= '<feedbackInline identifier="answer_'.$current_answer['id'].'">
<![CDATA['.formatExerciseQtiText($current_answer['comment']).']]>
</feedbackInline>';
}
$out .= '</simpleChoice>'."\n";
}
}
$out .= ' </choiceInteraction>'."\n";
return $out;
}
/**
* Return the XML flow of answer ResponsesDeclaration.
*/
public function imsExportResponsesDeclaration($questionIdent, Question $question = null)
{
$this->answerList = $this->getAnswersList(true);
$type = $this->getQuestionType();
if (MCMA == $type) {
$cardinality = 'multiple';
} else {
$cardinality = 'single';
}
$out = ' <responseDeclaration identifier="'.$questionIdent.'" cardinality="'.$cardinality.'" baseType="identifier">'."\n";
// Match the correct answers.
if (is_array($this->answerList)) {
$out .= ' <correctResponse>'."\n";
foreach ($this->answerList as $current_answer) {
if ($current_answer['correct']) {
$out .= ' <value>answer_'.$current_answer['id'].'</value>'."\n";
}
}
$out .= ' </correctResponse>'."\n";
}
// Add the grading
if (is_array($this->answerList)) {
$out .= ' <mapping>'."\n";
foreach ($this->answerList as $current_answer) {
if (isset($current_answer['grade'])) {
$out .= ' <mapEntry mapKey="answer_'.$current_answer['id'].'" mappedValue="'.$current_answer['grade'].'" />'."\n";
}
}
$out .= ' </mapping>'."\n";
}
$out .= ' </responseDeclaration>'."\n";
return $out;
}
}

@ -1,422 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Interface ImsAnswerInterface.
*/
interface ImsAnswerInterface
{
/**
* @param $questionIdent
* @param $questionStatment
*/
public function imsExportResponses($questionIdent, $questionStatment);
/**
* @param $questionIdent
*/
public function imsExportResponsesDeclaration($questionIdent, Question $question = null);
}
/**
* @author Claro Team <cvs@claroline.net>
* @author Yannick Warnier <yannick.warnier@beeznest.com> -
* updated ImsAnswerHotspot to match QTI norms
*/
class Ims2Question extends Question
{
/**
* Include the correct answer class and create answer.
*
* @return Answer
*/
public function setAnswer()
{
switch ($this->type) {
case MCUA:
$answer = new ImsAnswerMultipleChoice($this->id);
return $answer;
case MCMA:
$answer = new ImsAnswerMultipleChoice($this->id);
return $answer;
case TF:
$answer = new ImsAnswerMultipleChoice($this->id);
return $answer;
case FIB:
$answer = new ImsAnswerFillInBlanks($this->id);
return $answer;
case MATCHING:
case MATCHING_DRAGGABLE:
$answer = new ImsAnswerMatching($this->id);
return $answer;
case FREE_ANSWER:
$answer = new ImsAnswerFree($this->id);
return $answer;
case HOT_SPOT:
$answer = new ImsAnswerHotspot($this->id);
return $answer;
default:
$answer = null;
break;
}
return $answer;
}
public function createAnswersForm($form)
{
return true;
}
public function processAnswersCreation($form, $exercise)
{
return true;
}
}
/**
* Class.
*/
class ImsAnswerMultipleChoice extends Answer implements ImsAnswerInterface
{
/**
* Return the XML flow for the possible answers.
*/
public function imsExportResponses($questionIdent, $questionStatment)
{
// @todo getAnswersList() converts the answers using api_html_entity_decode()
$this->answerList = $this->getAnswersList(true);
$out = ' <choiceInteraction responseIdentifier="'.$questionIdent.'" >'."\n";
$out .= ' <prompt><![CDATA['.formatExerciseQtiText($questionStatment).']]></prompt>'."\n";
if (is_array($this->answerList)) {
foreach ($this->answerList as $current_answer) {
$out .= '<simpleChoice identifier="answer_'.$current_answer['id'].'" fixed="false">
<![CDATA['.formatExerciseQtiText($current_answer['answer']).']]>';
if (isset($current_answer['comment']) && '' != $current_answer['comment']) {
$out .= '<feedbackInline identifier="answer_'.$current_answer['id'].'">
<![CDATA['.formatExerciseQtiText($current_answer['comment']).']]>
</feedbackInline>';
}
$out .= '</simpleChoice>'."\n";
}
}
$out .= ' </choiceInteraction>'."\n";
return $out;
}
/**
* Return the XML flow of answer ResponsesDeclaration.
*/
public function imsExportResponsesDeclaration($questionIdent, Question $question = null)
{
$this->answerList = $this->getAnswersList(true);
$type = $this->getQuestionType();
if (MCMA == $type) {
$cardinality = 'multiple';
} else {
$cardinality = 'single';
}
$out = ' <responseDeclaration identifier="'.$questionIdent.'" cardinality="'.$cardinality.'" baseType="identifier">'."\n";
// Match the correct answers.
if (is_array($this->answerList)) {
$out .= ' <correctResponse>'."\n";
foreach ($this->answerList as $current_answer) {
if ($current_answer['correct']) {
$out .= ' <value>answer_'.$current_answer['id'].'</value>'."\n";
}
}
$out .= ' </correctResponse>'."\n";
}
// Add the grading
if (is_array($this->answerList)) {
$out .= ' <mapping>'."\n";
foreach ($this->answerList as $current_answer) {
if (isset($current_answer['grade'])) {
$out .= ' <mapEntry mapKey="answer_'.$current_answer['id'].'" mappedValue="'.$current_answer['grade'].'" />'."\n";
}
}
$out .= ' </mapping>'."\n";
}
$out .= ' </responseDeclaration>'."\n";
return $out;
}
}
/**
* Class.
*/
class ImsAnswerFillInBlanks extends Answer implements ImsAnswerInterface
{
private $answerList = [];
private $gradeList = [];
/**
* Export the text with missing words.
*/
public function imsExportResponses($questionIdent, $questionStatment)
{
$this->answerList = $this->getAnswersList(true);
$text = isset($this->answerText) ? $this->answerText : '';
if (is_array($this->answerList)) {
foreach ($this->answerList as $key => $answer) {
$key = $answer['id'];
$answer = $answer['answer'];
$len = api_strlen($answer);
$text = str_replace('['.$answer.']', '<textEntryInteraction responseIdentifier="fill_'.$key.'" expectedLength="'.api_strlen($answer).'"/>', $text);
}
}
return $text;
}
public function imsExportResponsesDeclaration($questionIdent, Question $question = null)
{
$this->answerList = $this->getAnswersList(true);
$this->gradeList = $this->getGradesList();
$out = '';
if (is_array($this->answerList)) {
foreach ($this->answerList as $answer) {
$answerKey = $answer['id'];
$answer = $answer['answer'];
$out .= ' <responseDeclaration identifier="fill_'.$answerKey.'" cardinality="single" baseType="identifier">'."\n";
$out .= ' <correctResponse>'."\n";
$out .= ' <value><![CDATA['.formatExerciseQtiText($answer).']]></value>'."\n";
$out .= ' </correctResponse>'."\n";
if (isset($this->gradeList[$answerKey])) {
$out .= ' <mapping>'."\n";
$out .= ' <mapEntry mapKey="'.$answer.'" mappedValue="'.$this->gradeList[$answerKey].'"/>'."\n";
$out .= ' </mapping>'."\n";
}
$out .= ' </responseDeclaration>'."\n";
}
}
return $out;
}
}
/**
* Class.
*/
class ImsAnswerMatching extends Answer implements ImsAnswerInterface
{
public $leftList = [];
public $rightList = [];
private $answerList = [];
/**
* Export the question part as a matrix-choice, with only one possible answer per line.
*/
public function imsExportResponses($questionIdent, $questionStatment)
{
$this->answerList = $this->getAnswersList(true);
$maxAssociation = max(count($this->leftList), count($this->rightList));
$out = '<matchInteraction responseIdentifier="'.$questionIdent.'" maxAssociations="'.$maxAssociation.'">'."\n";
$out .= $questionStatment;
//add left column
$out .= ' <simpleMatchSet>'."\n";
if (is_array($this->leftList)) {
foreach ($this->leftList as $leftKey => $leftElement) {
$out .= '
<simpleAssociableChoice identifier="left_'.$leftKey.'" >
<![CDATA['.formatExerciseQtiText($leftElement['answer']).']]>
</simpleAssociableChoice>'."\n";
}
}
$out .= ' </simpleMatchSet>'."\n";
//add right column
$out .= ' <simpleMatchSet>'."\n";
$i = 0;
if (is_array($this->rightList)) {
foreach ($this->rightList as $rightKey => $rightElement) {
$out .= '<simpleAssociableChoice identifier="right_'.$i.'" >
<![CDATA['.formatExerciseQtiText($rightElement['answer']).']]>
</simpleAssociableChoice>'."\n";
$i++;
}
}
$out .= ' </simpleMatchSet>'."\n";
$out .= '</matchInteraction>'."\n";
return $out;
}
public function imsExportResponsesDeclaration($questionIdent, Question $question = null)
{
$this->answerList = $this->getAnswersList(true);
$out = ' <responseDeclaration identifier="'.$questionIdent.'" cardinality="single" baseType="identifier">'."\n";
$out .= ' <correctResponse>'."\n";
$gradeArray = [];
if (isset($this->leftList) && is_array($this->leftList)) {
foreach ($this->leftList as $leftKey => $leftElement) {
$i = 0;
foreach ($this->rightList as $rightKey => $rightElement) {
if (($leftElement['match'] == $rightElement['code'])) {
$out .= ' <value>left_'.$leftKey.' right_'.$i.'</value>'."\n";
$gradeArray['left_'.$leftKey.' right_'.$i] = $leftElement['grade'];
}
$i++;
}
}
}
$out .= ' </correctResponse>'."\n";
if (is_array($gradeArray)) {
$out .= ' <mapping>'."\n";
foreach ($gradeArray as $gradeKey => $grade) {
$out .= ' <mapEntry mapKey="'.$gradeKey.'" mappedValue="'.$grade.'"/>'."\n";
}
$out .= ' </mapping>'."\n";
}
$out .= ' </responseDeclaration>'."\n";
return $out;
}
}
/**
* Class.
*/
class ImsAnswerHotspot extends Answer implements ImsAnswerInterface
{
private $answerList = [];
private $gradeList = [];
/**
* TODO update this to match hot spots instead of copying matching
* Export the question part as a matrix-choice, with only one possible answer per line.
*/
public function imsExportResponses($questionIdent, $questionStatment, $questionDesc = '', $questionMedia = '')
{
$this->answerList = $this->getAnswersList(true);
$mediaFilePath = api_get_course_path().'/document/images/'.$questionMedia;
$sysQuestionMediaPath = api_get_path(SYS_COURSE_PATH).$mediaFilePath;
$questionMedia = api_get_path(WEB_COURSE_PATH).$mediaFilePath;
$mimetype = mime_content_type($sysQuestionMediaPath);
if (empty($mimetype)) {
$mimetype = 'image/jpeg';
}
$text = ' <p>'.$questionStatment.'</p>'."\n";
$text .= ' <graphicOrderInteraction responseIdentifier="hotspot_'.$questionIdent.'">'."\n";
$text .= ' <prompt>'.$questionDesc.'</prompt>'."\n";
$text .= ' <object type="'.$mimetype.'" width="250" height="230" data="'.$questionMedia.'">-</object>'."\n";
if (is_array($this->answerList)) {
foreach ($this->answerList as $key => $answer) {
$key = $answer['id'];
$answerTxt = $answer['answer'];
$len = api_strlen($answerTxt);
//coords are transformed according to QTIv2 rules here: http://www.imsproject.org/question/qtiv2p1pd/imsqti_infov2p1pd.html#element10663
$coords = '';
$type = 'default';
switch ($answer['hotspot_type']) {
case 'square':
$type = 'rect';
$res = [];
$coords = preg_match('/^\s*(\d+);(\d+)\|(\d+)\|(\d+)\s*$/', $answer['hotspot_coord'], $res);
$coords = $res[1].','.$res[2].','.((int) $res[1] + (int) $res[3]).','.((int) $res[2] + (int) $res[4]);
break;
case 'circle':
$type = 'circle';
$res = [];
$coords = preg_match('/^\s*(\d+);(\d+)\|(\d+)\|(\d+)\s*$/', $answer['hotspot_coord'], $res);
$coords = $res[1].','.$res[2].','.sqrt(pow($res[1] - $res[3], 2) + pow($res[2] - $res[4]));
break;
case 'poly':
$type = 'poly';
$coords = str_replace([';', '|'], [',', ','], $answer['hotspot_coord']);
break;
case 'delineation':
$type = 'delineation';
$coords = str_replace([';', '|'], [',', ','], $answer['hotspot_coord']);
break;
}
$text .= ' <hotspotChoice shape="'.$type.'" coords="'.$coords.'" identifier="'.$key.'"/>'."\n";
}
}
$text .= ' </graphicOrderInteraction>'."\n";
return $text;
}
public function imsExportResponsesDeclaration($questionIdent, Question $question = null)
{
$this->answerList = $this->getAnswersList(true);
$this->gradeList = $this->getGradesList();
$out = ' <responseDeclaration identifier="hotspot_'.$questionIdent.'" cardinality="ordered" baseType="identifier">'."\n";
if (is_array($this->answerList)) {
$out .= ' <correctResponse>'."\n";
foreach ($this->answerList as $answerKey => $answer) {
$answerKey = $answer['id'];
$answer = $answer['answer'];
$out .= '<value><![CDATA['.formatExerciseQtiText($answerKey).']]></value>';
}
$out .= ' </correctResponse>'."\n";
}
$out .= ' </responseDeclaration>'."\n";
return $out;
}
}
/**
* Class.
*/
class ImsAnswerFree extends Answer implements ImsAnswerInterface
{
/**
* TODO implement
* Export the question part as a matrix-choice, with only one possible answer per line.
*/
public function imsExportResponses(
$questionIdent,
$questionStatment,
$questionDesc = '',
$questionMedia = ''
) {
$questionDesc = formatExerciseQtiText($questionDesc);
return '<extendedTextInteraction responseIdentifier="'.$questionIdent.'" >
<prompt>
'.$questionDesc.'
</prompt>
</extendedTextInteraction>';
}
public function imsExportResponsesDeclaration($questionIdent, Question $question = null)
{
$out = ' <responseDeclaration identifier="'.$questionIdent.'" cardinality="single" baseType="string">';
$out .= '<outcomeDeclaration identifier="SCORE" cardinality="single" baseType="float">
<defaultValue><value>'.$question->weighting.'</value></defaultValue></outcomeDeclaration>';
$out .= ' </responseDeclaration>'."\n";
return $out;
}
}

@ -4,8 +4,6 @@
/**
* @author Toon Keppens
*
* @version $Id: admin.php 10680 2007-01-11 21:26:23Z pcool $
*/
require_once __DIR__.'/../inc/global.inc.php';

@ -365,6 +365,7 @@ if (!empty($attempts)) {
case RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS_AND_RANKING:
case RESULT_DISABLE_SHOW_FINAL_SCORE_ONLY_WITH_CATEGORIES:
case RESULT_DISABLE_RANKING:
case RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER:
$header_names = [
get_lang('Attempt'),
get_lang('Start Date'),

@ -75,26 +75,36 @@ if ($show_headers) {
];
$interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Result')];
$this_section = SECTION_COURSES;
Display::display_header();
} else {
$htmlHeadXtra[] = '<style>
body { background: none;}
</style>';
Display::display_reduced_header();
if ($origin == 'mobileapp') {
echo '<div class="actions">';
echo '<a href="javascript:window.history.go(-1);">'.
Display::return_icon('back.png', get_lang('GoBackToQuestionList'), [], 32).'</a>';
echo '</div>';
}
}
$message = Session::read('attempt_remaining');
Session::erase('attempt_remaining');
ob_start();
ExerciseLib::displayQuestionListByAttempt(
$objExercise,
$id,
false,
$message
);
$pageContent = ob_get_contents();
ob_end_clean();
if ($show_headers) {
Display::display_footer();
} else {
Display::display_reduced_footer();
}
$template = new Template('', $show_headers, $show_headers);
$template->assign('page_content', $pageContent);
$layout = $template->fetch(
$template->get_template('exercise/result.tpl')
);
$template->assign('content', $layout);
$template->display_one_col_template();

@ -42,7 +42,9 @@ if (empty($sessionId)) {
);
}
$count_students = count($students);
$question_list = $objExercise->get_validated_question_list();
//$question_list = $objExercise->get_validated_question_list();
$totalQuestions = $objExercise->getQuestionCount(); //Get total of questions
$question_list = $objExercise->getQuestionForTeacher(0, $totalQuestions); // get questions from 0 to total
$data = [];
// Question title # of students who tool it Lowest score Average Highest score Maximum score
@ -64,7 +66,8 @@ if (!empty($question_list)) {
$question_id,
$exerciseId,
$courseCode,
$sessionId
$sessionId,
true
);
$count_users = ExerciseLib::get_number_students_question_with_answer_count(

@ -0,0 +1,7 @@
{# Displayed from exercise_result.php #}
{{ page_top }}
{{ page_content }}
{{ page_bottom }}

@ -150,6 +150,7 @@ class ScriptHandler
__DIR__.'/../../../../main/exercice/export/scorm/scorm_export.php',
__DIR__.'/../../../../main/exercice/testheaderpage.php',
__DIR__.'/../../../../main/exercise/hotspot_lang_conversion.php',
__DIR__.'/../../../../main/exercise/export/qti2/qti2_classes.php',
__DIR__.'/../../../../main/inc/lib/main_api.lib.php',
//__DIR__.'/../../../../main/inc/lib/nusoap/class.soapclient.php',
__DIR__.'/../../../../main/inc/lib/nusoap/nusoap.php',

Loading…
Cancel
Save