Merging MDL-12063 from HEAD qtype_questions where left orphans when questions when deleted or

qtype change
This commit is contained in:
pichetp 2008-02-19 18:01:11 +00:00
parent cda98581a5
commit 9a5d3d9d3d

View file

@ -13,6 +13,10 @@
/// ///
/// QUESTION TYPE CLASS ////////////////// /// QUESTION TYPE CLASS //////////////////
/**
* @package questionbank
* @subpackage questiontypes
*/
class embedded_cloze_qtype extends default_questiontype { class embedded_cloze_qtype extends default_questiontype {
function name() { function name() {
@ -70,6 +74,22 @@ class embedded_cloze_qtype extends default_questiontype {
// if we still have some old wrapped question ids, reuse the next of them // if we still have some old wrapped question ids, reuse the next of them
if ($oldwrappedid = array_shift($oldwrappedids)) { if ($oldwrappedid = array_shift($oldwrappedids)) {
$wrapped->id = $oldwrappedid; $wrapped->id = $oldwrappedid;
$oldqtype = get_field('question', 'qtype', 'id',$oldwrappedid) ;
if($oldqtype != $wrapped->qtype ) {
switch ($oldqtype) {
case 'multichoice':
delete_records('question_multichoice', 'question', $oldwrappedid);
break;
case 'shortanswer':
delete_records('question_shortanswer', 'question', $oldwrappedid);
break;
case 'numerical':
delete_records('question_numerical', 'question', $oldwrappedid);
break;
default:
error("questiontype $wrapped->qtype not recognized");
}
}
} }
$wrapped->name = $question->name; $wrapped->name = $question->name;
$wrapped->parent = $question->id; $wrapped->parent = $question->id;
@ -81,8 +101,9 @@ class embedded_cloze_qtype extends default_questiontype {
// Delete redundant wrapped questions // Delete redundant wrapped questions
if(is_array($oldwrappedids) && count($oldwrappedids)){ if(is_array($oldwrappedids) && count($oldwrappedids)){
$oldwrappedids = implode(',', $oldwrappedids); foreach ($oldwrappedids as $id) {
delete_records_select('question', "id IN ($oldwrappedids)"); delete_question($id) ;
}
} }
if (!empty($sequence)) { if (!empty($sequence)) {
@ -204,6 +225,8 @@ class embedded_cloze_qtype extends default_questiontype {
echo "<img src=\"$CFG->wwwroot/question/type/$question->qtype/icon.gif\" ". echo "<img src=\"$CFG->wwwroot/question/type/$question->qtype/icon.gif\" ".
"class=\"icon\" alt=\"".get_string('clozeaid','qtype_multichoice')."\" /> "; "class=\"icon\" alt=\"".get_string('clozeaid','qtype_multichoice')."\" /> ";
} }
echo '<div class="ablock clearfix">';
// For this question type, we better print the image on top: // For this question type, we better print the image on top:
if ($image = get_question_image($question, $cmoptions->course)) { if ($image = get_question_image($question, $cmoptions->course)) {
echo('<img class="qimage" src="' . $image . '" alt="" /><br />'); echo('<img class="qimage" src="' . $image . '" alt="" /><br />');
@ -290,8 +313,39 @@ class embedded_cloze_qtype extends default_questiontype {
switch ($wrapped->qtype) { switch ($wrapped->qtype) {
case 'shortanswer': case 'shortanswer':
case 'numerical': case 'numerical':
echo " <input $style $readonly $popup name=\"$inputname\" $size = 1 ;
type=\"text\" value=\"".s($response, true)."\" size=\"12\" /> "; foreach ($answers as $answer) {
if (strlen(trim($answer->answer)) > $size ){
$size = strlen(trim($answer->answer));
}
}
if (strlen(trim($response))> $size ){
$size = strlen(trim($response))+1;
}
$size = $size + rand(0,$size*0.15);
$size > 60 ? $size = 60 : $size = $size;
$styleinfo = "size=\"$size\"";
/**
* Uncomment the following lines if you want to limit for small sizes.
* Results may vary with browsers see MDL-3274
*/
/*
if ($size < 2) {
$styleinfo = 'style="width: 1.1em;"';
}
if ($size == 2) {
$styleinfo = 'style="width: 1.9em;"';
}
if ($size == 3) {
$styleinfo = 'style="width: 2.3em;"';
}
if ($size == 4) {
$styleinfo = 'style="width: 2.8em;"';
}
*/
echo "<input $style $readonly $popup name=\"$inputname\"";
echo " type=\"text\" value=\"".s($response, true)."\" ".$styleinfo." /> ";
if (!empty($feedback) && !empty($USER->screenreader)) { if (!empty($feedback) && !empty($USER->screenreader)) {
echo "<img src=\"$CFG->pixpath/i/feedback.gif\" alt=\"$feedback\" />"; echo "<img src=\"$CFG->pixpath/i/feedback.gif\" alt=\"$feedback\" />";
} }
@ -334,6 +388,7 @@ class embedded_cloze_qtype extends default_questiontype {
// Print the final piece of question text: // Print the final piece of question text:
echo $qtextremaining; echo $qtextremaining;
$this->print_question_submit_buttons($question, $state, $cmoptions, $options); $this->print_question_submit_buttons($question, $state, $cmoptions, $options);
echo '</div>';
} }
function grade_responses(&$question, &$state, $cmoptions) { function grade_responses(&$question, &$state, $cmoptions) {