mirror of
https://github.com/moodle/moodle.git
synced 2025-08-07 18:06:51 +02:00
Merging MDL-12063 from HEAD qtype_questions where left orphans when questions when deleted or
qtype change
This commit is contained in:
parent
cda98581a5
commit
9a5d3d9d3d
1 changed files with 59 additions and 4 deletions
|
@ -13,6 +13,10 @@
|
|||
///
|
||||
|
||||
/// QUESTION TYPE CLASS //////////////////
|
||||
/**
|
||||
* @package questionbank
|
||||
* @subpackage questiontypes
|
||||
*/
|
||||
class embedded_cloze_qtype extends default_questiontype {
|
||||
|
||||
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 ($oldwrappedid = array_shift($oldwrappedids)) {
|
||||
$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->parent = $question->id;
|
||||
|
@ -81,8 +101,9 @@ class embedded_cloze_qtype extends default_questiontype {
|
|||
|
||||
// Delete redundant wrapped questions
|
||||
if(is_array($oldwrappedids) && count($oldwrappedids)){
|
||||
$oldwrappedids = implode(',', $oldwrappedids);
|
||||
delete_records_select('question', "id IN ($oldwrappedids)");
|
||||
foreach ($oldwrappedids as $id) {
|
||||
delete_question($id) ;
|
||||
}
|
||||
}
|
||||
|
||||
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\" ".
|
||||
"class=\"icon\" alt=\"".get_string('clozeaid','qtype_multichoice')."\" /> ";
|
||||
}
|
||||
|
||||
echo '<div class="ablock clearfix">';
|
||||
// For this question type, we better print the image on top:
|
||||
if ($image = get_question_image($question, $cmoptions->course)) {
|
||||
echo('<img class="qimage" src="' . $image . '" alt="" /><br />');
|
||||
|
@ -290,8 +313,39 @@ class embedded_cloze_qtype extends default_questiontype {
|
|||
switch ($wrapped->qtype) {
|
||||
case 'shortanswer':
|
||||
case 'numerical':
|
||||
echo " <input $style $readonly $popup name=\"$inputname\"
|
||||
type=\"text\" value=\"".s($response, true)."\" size=\"12\" /> ";
|
||||
$size = 1 ;
|
||||
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)) {
|
||||
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:
|
||||
echo $qtextremaining;
|
||||
$this->print_question_submit_buttons($question, $state, $cmoptions, $options);
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
function grade_responses(&$question, &$state, $cmoptions) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue