Skip to content
Browse files

Merging MDL-12063 from HEAD qtype_questions where left orphans when q…

…uestions when deleted or

 qtype change
  • Loading branch information...
1 parent cda9858 commit 9a5d3d9d3d8977dfdc8aa1225c763e315d3915b9 pichetp committed Feb 19, 2008
Showing with 59 additions and 4 deletions.
  1. +59 −4 question/type/multianswer/questiontype.php
View
63 question/type/multianswer/questiontype.php
@@ -13,6 +13,10 @@
///
/// QUESTION TYPE CLASS //////////////////
+/**
+ * @package questionbank
+ * @subpackage questiontypes
+ */
class embedded_cloze_qtype extends default_questiontype {
function name() {
@@ -70,6 +74,22 @@ function save_question_options($question) {
// 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 @@ function save_question_options($question) {
// 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 @@ function print_question_formulation_and_controls(&$question, &$state, $cmoptions
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 @@ function print_question_formulation_and_controls(&$question, &$state, $cmoptions
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 @@ function print_question_formulation_and_controls(&$question, &$state, $cmoptions
// 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) {

0 comments on commit 9a5d3d9

Please sign in to comment.
Something went wrong with that request. Please try again.