Ejemplo n.º 1
0
 function save_question_options($question)
 {
     if (parent::save_question_options($question) !== false) {
         return wrsqz_save_question_options('match', 'wmatprom', $question);
     }
     return false;
 }
Ejemplo n.º 2
0
	function save_question_options($question) {
		if(parent::save_question_options($question) !== false) {
			return wrsqz_save_question_options('truefalse', 'wtrflsprom', $question);
		}
		
		return false;
	}
Ejemplo n.º 3
0
 function save_question_options($question)
 {
     if (parent::save_question_options($question) !== false) {
         return wrsqz_save_question_options('essay', 'wessaprom', $question);
     }
     return false;
 }
Ejemplo n.º 4
0
 function save_question_options($question)
 {
     if (parent::save_question_options($question) !== false) {
         return wrsqz_save_question_options('multichoice', 'wmultiprom', $question);
     }
     return false;
 }
Ejemplo n.º 5
0
 function save_question_options($question)
 {
     if (parent::save_question_options($question) !== false) {
         return wrsqz_save_question_options('shortanswer', 'wshanprom', $question);
     }
     return false;
 }
Ejemplo n.º 6
0
 function save_question_options($question)
 {
     global $QTYPES;
     $result = new stdClass();
     // This function needs to be able to handle the case where the existing set of wrapped
     // questions does not match the new set of wrapped questions so that some need to be
     // created, some modified and some deleted
     // Unfortunately the code currently simply overwrites existing ones in sequence. This
     // will make re-marking after a re-ordering of wrapped questions impossible and
     // will also create difficulties if questiontype specific tables reference the id.
     // First we get all the existing wrapped questions
     if (!($oldwrappedids = get_field('question_multianswer', 'sequence', 'question', $question->id))) {
         $oldwrappedquestions = array();
     } else {
         $oldwrappedquestions = get_records_list('question', 'id', $oldwrappedids, 'id ASC');
     }
     $sequence = array();
     foreach ($question->options->questions as $wrapped) {
         if (!empty($wrapped)) {
             // if we still have some old wrapped question ids, reuse the next of them
             if (is_array($oldwrappedquestions) && ($oldwrappedquestion = array_shift($oldwrappedquestions))) {
                 $wrapped->id = $oldwrappedquestion->id;
                 if ($oldwrappedquestion->qtype != $wrapped->qtype) {
                     switch ($oldwrappedquestion->qtype) {
                         case 'multichoicewiris':
                             delete_records('question_multichoicewiris', 'question', $oldwrappedquestion->id);
                         case 'multichoice':
                             delete_records('question_multichoice', 'question', $oldwrappedquestion->id);
                             break;
                         case 'shortanswerwiris':
                             delete_records('question_shortanswerwiris', 'question', $oldwrappedquestion->id);
                         case 'shortanswer':
                             delete_records('question_shortanswer', 'question', $oldwrappedquestion->id);
                             break;
                         case 'numerical':
                             delete_records('question_numerical', 'question', $oldwrappedquestion->id);
                             break;
                         default:
                             print_error('qtypenotrecognized', 'qtype_multianswer', '', $oldwrappedquestion->qtype);
                             $wrapped->id = 0;
                     }
                 }
             } else {
                 $wrapped->id = 0;
             }
         }
         $wrapped->name = $question->name;
         $wrapped->parent = $question->id;
         $previousid = $wrapped->id;
         $wrapped->category = $question->category . ',1';
         // save_question strips this extra bit off again.
         wrsqz_addWirisFieldsToWrapped($question, $wrapped);
         //$wrapped->hiddenCASValue = $question->hiddenCASValue;
         $wrapped = $QTYPES[$wrapped->qtype]->save_question($wrapped, $wrapped, $question->course);
         $sequence[] = $wrapped->id;
         if ($previousid != 0 && $previousid != $wrapped->id) {
             // for some reasons a new question has been created
             // so delete the old one
             delete_question($previousid);
         }
     }
     // Delete redundant wrapped questions
     if (is_array($oldwrappedquestions) && count($oldwrappedquestions)) {
         foreach ($oldwrappedquestions as $oldwrappedquestion) {
             delete_question($oldwrappedquestion->id);
         }
     }
     if (!empty($sequence)) {
         $multianswer = new stdClass();
         $multianswer->question = $question->id;
         $multianswer->sequence = implode(',', $sequence);
         if ($oldid = get_field('question_multianswer', 'id', 'question', $question->id)) {
             $multianswer->id = $oldid;
             if (!update_record("question_multianswer", $multianswer)) {
                 $result->error = "Could not update cloze question options! " . "(id={$multianswer->id})";
                 return $result;
             }
         } else {
             if (!insert_record("question_multianswer", $multianswer)) {
                 $result->error = "Could not insert cloze question options!";
                 return $result;
             }
         }
     }
     return wrsqz_save_question_options('multianswer', 'wmansprom', $question);
 }