Remove duplicated Qti classes and methods - refs #7504

1.10.x
Angel Fernando Quiroz Campos 10 years ago
parent 5076ee5128
commit 56f7b0339d
  1. 440
      main/exercice/export/qti/qti_classes.php
  2. 351
      main/exercice/export/qti/qti_export.php
  3. 1
      vendor/composer/autoload_classmap.php

@ -25,213 +25,6 @@ require_once '../../hotspot.class.php';
require_once '../../matching.class.php';
require_once '../../hotspot.class.php';
/**
*
* @package chamilo.exercise
*/
class ImsQuestion extends Question
{
/**
* Include the correct answer class and create answer
*/
function setAnswer()
{
switch($this->type)
{
case MCUA :
$this->answer = new ImsAnswerMultipleChoice($this->id, false);
break;
case MCMA :
$this->answer = new ImsAnswerMultipleChoice($this->id, true);
break;
case TF :
$this->answer = new ImsAnswerTrueFalse($this->id);
break;
case FIB :
$this->answer = new ImsAnswerFillInBlanks($this->id);
break;
case MATCHING :
$this->answer = new ImsAnswerMatching($this->id);
break;
default :
$this->answer = null;
break;
}
return true;
}
/**
* allow to import the question
*
* @param questionArray is an array that must contain all the information needed to build the question
* @author Guillaume Lederer <guillaume@claroline.net>
*/
function import($questionArray, $exerciseTempPath)
{
//import answers
$this->answer->import($questionArray);
//import attached file, if any
if (isset($questionArray['attached_file_url']))
{
$file= array();
$file['name'] = $questionArray['attached_file_url'];
$file['tmp_name'] = $exerciseTempPath.$file['name'];
$this->setAttachment($file);
}
}
}
/**
*
* @package chamilo.exercise
*/
class ImsAnswerMultipleChoice extends answerMultipleChoice
{
/**
* Return the XML flow for the possible answers.
* That's one <response_lid>, containing several <flow_label>
*
* @author Amand Tihon <amand@alrj.org>
*/
function imsExportResponses($questionIdent)
{
// Opening of the response block.
if( $this->multipleAnswer )
{
$out = '<response_lid ident = "MCM_' . $questionIdent . '" rcardinality = "Multiple" rtiming = "No">' . "\n"
. '<render_choice shuffle = "No" minnumber = "1" maxnumber = "' . count($this->answerList) . '">' . "\n";
}
else
{
$out = '<response_lid ident="MCS_' . $questionIdent . '" rcardinality="Single" rtiming="No"><render_choice shuffle="No">' . "\n";
}
// Loop over answers
foreach( $this->answerList as $answer )
{
$responseIdent = $questionIdent . "_A_" . $answer['id'];
$out.= ' <flow_label><response_label ident="' . $responseIdent . '">'.(!$this->multipleAnswer ? '<flow_mat class="list">':'').'<material>' . "\n"
. ' <mattext><![CDATA[' . $answer['answer'] . ']]></mattext>' . "\n"
. ' </material>'.(!$this->multipleAnswer ? '</flow_mat>':'').'</response_label></flow_label>' . "\n";
}
$out.= "</render_choice></response_lid>\n";
return $out;
}
/**
* Return the XML flow of answer processing : a succession of <respcondition>.
*
* @author Amand Tihon <amand@alrj.org>
*/
function imsExportProcessing($questionIdent)
{
$out = '';
foreach( $this->answerList as $answer )
{
$responseIdent = $questionIdent . "_A_" . $answer['id'];
$feedbackIdent = $questionIdent . "_F_" . $answer['id'];
$conditionIdent = $questionIdent . "_C_" . $answer['id'];
if( $this->multipleAnswer )
{
$out .= '<respcondition title="' . $conditionIdent . '" continue="Yes"><conditionvar>' . "\n"
. ' <varequal respident="MCM_' . $questionIdent . '">' . $responseIdent . '</varequal>' . "\n";
}
else
{
$out .= '<respcondition title="' . $conditionIdent . '"><conditionvar>' . "\n"
. ' <varequal respident="MCS_' . $questionIdent . '">' . $responseIdent . '</varequal>' . "\n";
}
$out .= " </conditionvar>\n" . ' <setvar action="Add">' . $answer['grade'] . "</setvar>\n";
// Only add references for actually existing comments/feedbacks.
if( !empty($answer['comment']) )
{
$out .= ' <displayfeedback feedbacktype="Response" linkrefid="' . $feedbackIdent . '" />' . "\n";
}
$out .= "</respcondition>\n";
}
return $out;
}
/**
* Export the feedback (comments to selected answers) to IMS/QTI
*
* @author Amand Tihon <amand@alrj.org>
*/
function imsExportFeedback($questionIdent)
{
$out = "";
foreach( $this->answerList as $answer )
{
if( !empty($answer['comment']) )
{
$feedbackIdent = $questionIdent . "_F_" . $answer['id'];
$out.= '<itemfeedback ident="' . $feedbackIdent . '" view="Candidate"><flow_mat><material>' . "\n"
. ' <mattext><![CDATA[' . $answer['comment'] . "]]></mattext>\n"
. "</material></flow_mat></itemfeedback>\n";
}
}
return $out;
}
/**
* allow to import the answers, feedbacks, and grades of a question
* @param questionArray is an array that must contain all the information needed to build the question
* @author Guillaume Lederer <guillaume@claroline.net>
*/
function import($questionArray)
{
$answerArray = $questionArray['answer'];
$this->answerList = array(); //re-initialize answer object content
foreach ($answerArray as $key => $answer)
{
if (!isset($answer['feedback'])) $answer['feedback'] = "";
if (!isset($questionArray['weighting'][$key]))
{
if (isset($questionArray['default_weighting']))
{
$grade = $questionArray['default_weighting'];
}
else
{
$grade = 0;
}
}
else
{
$grade = $questionArray['weighting'][$key];
}
if (in_array($key,$questionArray['correct_answers'])) $is_correct = true; else $is_correct = false;
$addedAnswer = array(
'answer' => $answer['value'],
'correct' => $is_correct,
'grade' => $grade,
'comment' => $answer['feedback'],
);
$this->answerList[] = $addedAnswer;
}
}
}
/**
*
* @package chamilo.exercise
@ -343,236 +136,3 @@ class ImsAnswerTrueFalse extends answerTrueFalse
return $out;
}
}
/**
*
* @package chamilo.exercise
*/
class ImsAnswerFillInBlanks extends answerFillInBlanks
{
/**
* Export the text with missing words.
*
* As a side effect, it stores two lists in the class :
* the missing words and their respective weightings.
*
* @author Amand Tihon <amand@alrj.org>
*/
function imsExportResponses($questionIdent)
{
global $charset;
$out = "<flow>\n";
$responsePart = explode(']', $this->answer);
$i = 0; // Used for the reference generation.
foreach($responsePart as $part)
{
$response_ident = $questionIdent . "_A_" . $i;
if( strpos($part,'[') !== false )
{
list($rawText, $blank) = explode('[', $part);
}
else
{
$rawText = $part;
$blank = "";
}
if ($rawText!="")
{
$out.=" <material><mattext><![CDATA[" . $rawText . "]]></mattext></material>\n";
}
if ($blank!="")
{
$out.= ' <response_str ident="' . $response_ident . '" rcardinality="Single" rtiming="No">' . "\n"
. ' <render_fib fibtype="String" prompt="Box" encoding="' . $charset . '">' . "\n"
. ' <response_label ident="A"/>' . "\n"
. " </render_fib>\n"
. " </response_str>\n";
}
$i++;
}
$out.="</flow>\n";
return $out;
}
/**
* Exports the response processing.
*
* It uses the two lists build by export_responses(). This implies that export_responses MUST
* be called before.
*
* @author Amand Tihon <amand@alrj.org>
*/
function imsExportProcessing($questionIdent)
{
$out = "";
$answerCount = count($this->answerList);
for( $i = 0; $i < $answerCount ; $i++ )
{
$response_ident = $questionIdent . "_A_" . $i;
$out.= ' <respcondition continue="Yes"><conditionvar>' . "\n"
. ' <varequal respident="' . $response_ident . '" case="No"><![CDATA[' . $this->answerList[$i] . ']]></varequal>' . "\n"
. ' </conditionvar><setvar action="Add">' . $this->gradeList[$i] . "</setvar>\n"
. " </respcondition>\n";
}
return $out;
}
/**
* Export the feedback (comments to selected answers) to IMS/QTI
*
* @author Amand Tihon <amand@alrj.org>
*/
function imsExportFeedback($questionIdent)
{
// no feedback in this question type
return '';
}
/**
* allow to import the answers, feedbacks, and grades of a question
*
* @param questionArray is an array that must contain all the information needed to build the question
* @author Guillaume Lederer <guillaume@claroline.net>
*/
function import($questionArray)
{
$answerArray = $questionArray['answer'];
$this->answerText = str_replace ("\n","",$questionArray['response_text']);
if ($questionArray['subtype'] == "TEXTFIELD_FILL") $this->type = TEXTFIELD_FILL;
if ($questionArray['subtype'] == "LISTBOX_FILL")
{
$this->wrongAnswerList = $questionArray['wrong_answers'];
$this->type = LISTBOX_FILL;
}
//build correct_answsers array
if (isset($questionArray['weighting']))
{
$this->gradeList = $questionArray['weighting'];
}
}
}
/**
*
* @package chamilo.exercise
*/
class ImsAnswerMatching extends answerMatching
{
/**
* Export the question part as a matrix-choice, with only one possible answer per line.
* @author Amand Tihon <amand@alrj.org>
*/
function imsExportResponses($questionIdent)
{
$out = "";
// Now, loop again, finding questions (rows)
foreach( $this->leftList as $leftElt )
{
$responseIdent = $questionIdent . "_A_" . $leftElt['code'];
$out.= '<response_lid ident="' . $responseIdent . '" rcardinality="Single" rtiming="No">' . "\n"
. '<material><mattext><![CDATA[' . $leftElt['answer'] . "]]></mattext></material>\n"
. ' <render_choice shuffle="No"><flow_label>' . "\n";
foreach( $this->rightList as $rightElt )
{
$out.= ' <response_label ident="' . $rightElt['code'] . '"><material>' . "\n"
. " <mattext><![CDATA[" . $rightElt['answer'] . "]]></mattext>\n"
. " </material></response_label>\n";
}
$out.= "</flow_label></render_choice></response_lid>\n";
}
return $out;
}
/**
* Export the response processing part
* @author Amand Tihon <amand@alrj.org>
*/
function imsExportProcessing($questionIdent)
{
$out = "";
foreach( $this->leftList as $leftElt )
{
$responseIdent = $questionIdent . "_A_" . $leftElt['code'];
$out.= ' <respcondition continue="Yes"><conditionvar>' . "\n"
. ' <varequal respident="' . $responseIdent . '">' . $leftElt['match'] . "</varequal>\n"
. ' </conditionvar><setvar action="Add">' . $leftElt['grade'] . "</setvar>\n"
. " </respcondition>\n";
}
return $out;
}
/**
* Export the feedback (comments to selected answers) to IMS/QTI
*
* @author Amand Tihon <amand@alrj.org>
*/
function imsExportFeedback($questionIdent)
{
// no feedback in this question type
return '';
}
/**
* allow to import the answers, feedbacks, and grades of a question
*
* @param questionArray is an array that must contain all the information needed to build the question
* @author Guillaume Lederer <guillaume@claroline.net>
*/
function import($questionArray)
{
$answerArray = $questionArray['answer'];
//This tick to remove examples in the answers!!!!
$this->leftList = array();
$this->rightList = array();
//find right and left column
$right_column = array_pop($answerArray);
$left_column = array_pop($answerArray);
//1- build answers
foreach ($right_column as $right_key => $right_element)
{
$code = $this->addRight($right_element);
foreach ($left_column as $left_key => $left_element)
{
$matched_pattern = $left_key." ".$right_key;
$matched_pattern_inverted = $right_key." ".$left_key;
if (in_array($matched_pattern, $questionArray['correct_answers']) || in_array($matched_pattern_inverted, $questionArray['correct_answers']))
{
if (isset($questionArray['weighting'][$matched_pattern]))
{
$grade = $questionArray['weighting'][$matched_pattern];
}
else
{
$grade = 0;
}
$this->addLeft($left_element, $code, $grade);
}
}
}
}
}
?>

@ -1,351 +0,0 @@
<?php // $Id: $
/* For licensing terms, see /license.txt */
/**
* @author Claro Team <cvs@claroline.net>
* @author Amand Tihon <amand@alrj.org>
* @author Sebastien Piraux <pir@cerdecam.be>
* @author Yannick Warnier <yannick.warnier@beeznest.com>
* @package chamilo.exercise.qti
*/
/**
* Code
*/
if ( count( get_included_files() ) == 1 ) die( '---' );
include dirname(__FILE__) . '/qti_classes.php';
/*--------------------------------------------------------
Classes
--------------------------------------------------------*/
/**
* This class represents an entire exercise to be exported in IMS/QTI.
* It will be represented by a single <section> containing several <item>.
*
* Some properties cannot be exported, as IMS does not support them :
* - type (one page or multiple pages)
* - start_date and end_date
* - max_attempts
* - show_answer
* - anonymous_attempts
*
* @author Amand Tihon <amand@alrj.org>
* @package chamilo.exercise.qti
*/
class ImsSection
{
var $exercise;
/**
* Constructor.
* @param $exe The Exercise instance to export
* @author Amand Tihon <amand@alrj.org>
*/
function ImsSection($exe)
{
$this->exercise = $exe;
}
function start_section()
{
$out = '<section ident="EXO_' . $this->exercise->getId() . '" title="' . $this->exercise->getTitle() . '">' . "\n";
return $out;
}
function end_section()
{
return "</section>\n";
}
function export_duration()
{
if ($max_time = $this->exercise->getTimeLimit())
{
// return exercise duration in ISO8601 format.
$minutes = floor($max_time / 60);
$seconds = $max_time % 60;
return '<duration>PT' . $minutes . 'M' . $seconds . "S</duration>\n";
}
else
{
return '';
}
}
/**
* Export the presentation (Exercise's description)
* @author Amand Tihon <amand@alrj.org>
*/
function export_presentation()
{
$out = "<presentation_material><flow_mat><material>\n"
. " <mattext><![CDATA[" . $this->exercise->getDescription() . "]]></mattext>\n"
. "</material></flow_mat></presentation_material>\n";
return $out;
}
/**
* Export the ordering information.
* Either sequential, through all questions, or random, with a selected number of questions.
* @author Amand Tihon <amand@alrj.org>
*/
function export_ordering()
{
$out = '';
if ($n = $this->exercise->getShuffle()) {
$out.= "<selection_ordering>"
. " <selection>\n"
. " <selection_number>" . $n . "</selection_number>\n"
. " </selection>\n"
. ' <order order_type="Random" />'
. "\n</selection_ordering>\n";
}
else
{
$out.= '<selection_ordering sequence_type="Normal">' . "\n"
. " <selection />\n"
. "</selection_ordering>\n";
}
return $out;
}
/**
* Export the questions, as a succession of <items>
* @author Amand Tihon <amand@alrj.org>
*/
function export_questions()
{
$out = "";
foreach ($this->exercise->getQuestionList() as $q)
{
$out .= export_question($q['id'], False);
}
return $out;
}
/**
* Export the exercise in IMS/QTI.
*
* @param bool $standalone Wether it should include XML tag and DTD line.
* @return a string containing the XML flow
* @author Amand Tihon <amand@alrj.org>
*/
function export($standalone)
{
global $charset;
$head = $foot = "";
if ($standalone) {
$head = '<?xml version = "1.0" encoding = "' . $charset . '" standalone = "no"?>' . "\n"
. '<!DOCTYPE questestinterop SYSTEM "ims_qtiasiv1p2p1.dtd">' . "\n"
. "<questestinterop>\n";
$foot = "</questestinterop>\n";
}
$out = $head
. $this->start_section()
. $this->export_duration()
. $this->export_presentation()
. $this->export_ordering()
. $this->export_questions()
. $this->end_section()
. $foot;
return $out;
}
}
/*
Some quick notes on identifiers generation.
The IMS format requires some blocks, like items, responses, feedbacks, to be uniquely
identified.
The unicity is mandatory in a single XML, of course, but it's prefered that the identifier stays
coherent for an entire site.
Here's the method used to generate those identifiers.
Question identifier :: "QST_" + <Question Id from the DB> + "_" + <Question numeric type>
Response identifier :: <Question identifier> + "_A_" + <Response Id from the DB>
Condition identifier :: <Question identifier> + "_C_" + <Response Id from the DB>
Feedback identifier :: <Question identifier> + "_F_" + <Response Id from the DB>
*/
/**
* An IMS/QTI item. It corresponds to a single question.
* This class allows export from Claroline to IMS/QTI XML format.
* It is not usable as-is, but must be subclassed, to support different kinds of questions.
*
* Every start_*() and corresponding end_*(), as well as export_*() methods return a string.
*
* Warning: Attached files are NOT exported.
* @package chamilo.exercise.qti
* @author Amand Tihon <amand@alrj.org>
*/
class ImsItem
{
var $question;
var $question_ident;
var $answer;
/**
* Constructor.
*
* @param $question The Question object we want to export.
* @author Anamd Tihon
*/
function ImsItem($question)
{
$this->question = $question;
$this->answer = $question->answer;
$this->questionIdent = "QST_" . $question->getId() ;
}
/**
* Start the XML flow.
*
* This opens the <item> block, with correct attributes.
*
* @author Amand Tihon <amand@alrj.org>
*/
function start_item()
{
return '<item title="' . htmlspecialchars($this->question->getTitle()) . '" ident="' . $this->questionIdent . '">' . "\n";
}
/**
* End the XML flow, closing the </item> tag.
*
* @author Amand Tihon <amand@alrj.org>
*/
function end_item()
{
return "</item>\n";
}
/**
* Create the opening, with the question itself.
*
* This means it opens the <presentation> but doesn't close it, as this is the role of end_presentation().
* Inbetween, the export_responses from the subclass should have been called.
*
* @author Amand Tihon <amand@alrj.org>
*/
function start_presentation()
{
return '<presentation label="' . $this->questionIdent . '"><flow>' . "\n"
. '<material><mattext><![CDATA[' . $this->question->getDescription() . "]]></mattext></material>\n";
}
/**
* End the </presentation> part, opened by export_header.
*
* @author Amand Tihon <amand@alrj.org>
*/
function end_presentation()
{
return "</flow></presentation>\n";
}
/**
* Start the response processing, and declare the default variable, SCORE, at 0 in the outcomes.
*
* @author Amand Tihon <amand@alrj.org>
*/
function start_processing()
{
return '<resprocessing><outcomes><decvar vartype="Integer" defaultval="0" /></outcomes>' . "\n";
}
/**
* End the response processing part.
*
* @author Amand Tihon <amand@alrj.org>
*/
function end_processing()
{
return "</resprocessing>\n";
}
/**
* Export the question as an IMS/QTI Item.
*
* This is a default behaviour, some classes may want to override this.
*
* @param $standalone: Boolean stating if it should be exported as a stand-alone question
* @return A string, the XML flow for an Item.
* @author Amand Tihon <amand@alrj.org>
*/
function export($standalone = False)
{
global $charset;
$head = $foot = "";
if( $standalone )
{
$head = '<?xml version = "1.0" encoding = "'.$charset.'" standalone = "no"?>' . "\n"
. '<!DOCTYPE questestinterop SYSTEM "ims_qtiasiv1p2p1.dtd">' . "\n"
. "<questestinterop>\n";
$foot = "</questestinterop>\n";
}
return $head
. $this->start_item()
. $this->start_presentation()
. $this->answer->imsExportResponses($this->questionIdent)
. $this->end_presentation()
. $this->start_processing()
. $this->answer->imsExportProcessing($this->questionIdent)
. $this->end_processing()
. $this->answer->imsExportFeedback($this->questionIdent)
. $this->end_item()
. $foot;
}
}
/*--------------------------------------------------------
Functions
--------------------------------------------------------*/
/**
* Send a complete exercise in IMS/QTI format, from its ID
*
* @param int $exerciseId The exercise to exporte
* @param boolean $standalone Wether it should include XML tag and DTD line.
* @return The XML as a string, or an empty string if there's no exercise with given ID.
* @author Amand Tihon <amand@alrj.org>
*/
function export_exercise($exerciseId, $standalone=True)
{
$exercise = new Exercise();
if (! $exercise->load($exerciseId))
{
return '';
}
$ims = new ImsSection($exercise);
$xml = $ims->export($standalone);
return $xml;
}
/**
* Returns the XML flow corresponding to one question
*
* @param int The question ID
* @param bool standalone (ie including XML tag, DTD declaration, etc)
* @author Amand Tihon <amand@alrj.org>
*/
function export_question($questionId, $standalone=True)
{
$question = new ImsQuestion();
if( !$question->load($questionId) )
{
return '';
}
$ims = new ImsItem($question);
return $ims->export($standalone);
}
?>

@ -843,7 +843,6 @@ return array(
'ImsAnswerTrueFalse' => $baseDir . '/main/exercice/export/qti/qti_classes.php',
'ImsAssessmentItem' => $baseDir . '/main/exercice/export/qti2/qti2_export.php',
'ImsItem' => $baseDir . '/main/exercice/export/qti2/qti2_export.php',
'ImsQuestion' => $baseDir . '/main/exercice/export/qti/qti_classes.php',
'ImsSection' => $baseDir . '/main/exercice/export/qti2/qti2_export.php',
'IndexManager' => $baseDir . '/main/inc/lib/userportal.lib.php',
'IndexableChunk' => $baseDir . '/main/inc/lib/search/IndexableChunk.class.php',

Loading…
Cancel
Save