Ejemplo n.º 1
0
 public function save_question($question, $fromform)
 {
     if (!empty($fromform->fixdollars)) {
         $this->fix_dollars_in_form_data($fromform);
     }
     return parent::save_question($question, $fromform);
 }
Ejemplo n.º 2
0
 public function save_question($question, $form)
 {
     // Make very sure that descriptions can'e be created with a grade of
     // anything other than 0.
     $form->defaultmark = 0;
     return parent::save_question($question, $form);
 }
Ejemplo n.º 3
0
 /**
  * this version save the available data at the different steps of the question editing process
  * without using global $SESSION as storage between steps
  * at the first step $wizardnow = 'question'
  *  when creating a new question
  *  when modifying a question
  *  when copying as a new question
  *  the general parameters and answers are saved using parent::save_question
  *  then the datasets are prepared and saved
  * at the second step $wizardnow = 'datasetdefinitions'
  *  the datadefs final type are defined as private, category or not a datadef
  * at the third step $wizardnow = 'datasetitems'
  *  the datadefs parameters and the data items are created or defined
  *
  * @param object question
  * @param object $form
  * @param int $course
  * @param PARAM_ALPHA $wizardnow should be added as we are coming from question2.php
  */
 public function save_question($question, $form)
 {
     global $DB;
     if ($this->wizardpagesnumber() == 1 || $question->qtype == 'calculatedsimple') {
         $question = parent::save_question($question, $form);
         return $question;
     }
     $wizardnow = optional_param('wizardnow', '', PARAM_ALPHA);
     $id = optional_param('id', 0, PARAM_INT);
     // Question id.
     // In case 'question':
     // For a new question $form->id is empty
     // when saving as new question.
     // The $question->id = 0, $form is $data from question2.php
     // and $data->makecopy is defined as $data->id is the initial question id.
     // Edit case. If it is a new question we don't necessarily need to
     // return a valid question object.
     // See where we're coming from.
     switch ($wizardnow) {
         case '':
         case 'question':
             // Coming from the first page, creating the second.
             if (empty($form->id)) {
                 // or a new question $form->id is empty.
                 $question = parent::save_question($question, $form);
                 // Prepare the datasets using default $questionfromid.
                 $this->preparedatasets($form);
                 $form->id = $question->id;
                 $this->save_dataset_definitions($form);
                 if (isset($form->synchronize) && $form->synchronize == 2) {
                     $this->addnamecategory($question);
                 }
             } else {
                 if (!empty($form->makecopy)) {
                     $questionfromid = $form->id;
                     $question = parent::save_question($question, $form);
                     // Prepare the datasets.
                     $this->preparedatasets($form, $questionfromid);
                     $form->id = $question->id;
                     $this->save_as_new_dataset_definitions($form, $questionfromid);
                     if (isset($form->synchronize) && $form->synchronize == 2) {
                         $this->addnamecategory($question);
                     }
                 } else {
                     // Editing a question.
                     $question = parent::save_question($question, $form);
                     // Prepare the datasets.
                     $this->preparedatasets($form, $question->id);
                     $form->id = $question->id;
                     $this->save_dataset_definitions($form);
                     if (isset($form->synchronize) && $form->synchronize == 2) {
                         $this->addnamecategory($question);
                     }
                 }
             }
             break;
         case 'datasetdefinitions':
             // Calculated options.
             // It cannot go here without having done the first page,
             // so the question_calculated_options should exist.
             // We only need to update the synchronize field.
             if (isset($form->synchronize)) {
                 $optionssynchronize = $form->synchronize;
             } else {
                 $optionssynchronize = 0;
             }
             $DB->set_field('question_calculated_options', 'synchronize', $optionssynchronize, array('question' => $question->id));
             if (isset($form->synchronize) && $form->synchronize == 2) {
                 $this->addnamecategory($question);
             }
             $this->save_dataset_definitions($form);
             break;
         case 'datasetitems':
             $this->save_dataset_items($question, $form);
             $this->save_question_calculated($question, $form);
             break;
         default:
             print_error('invalidwizardpage', 'question');
             break;
     }
     return $question;
 }
Ejemplo n.º 4
0
 public function save_question($question, $form) {
     $form->name = '';
     // Name is not a required field for random questions, but
     // parent::save_question Assumes that it is.
     return parent::save_question($question, $form);
 }
Ejemplo n.º 5
0
 public function save_question($authorizedquestion, $form)
 {
     $question = qtype_multianswer_extract_question($form->questiontext);
     if (isset($authorizedquestion->id)) {
         $question->id = $authorizedquestion->id;
     }
     $question->category = $authorizedquestion->category;
     $form->defaultmark = $question->defaultmark;
     $form->questiontext = $question->questiontext;
     $form->questiontextformat = 0;
     $form->options = clone $question->options;
     unset($question->options);
     return parent::save_question($question, $form);
 }
Ejemplo n.º 6
0
 /**
  *
  * @param type $question The current question
  * @param type $form The question editing form data
  * @return type object
  * Sets the default mark as 1* the number of gaps
  * Does not allow setting any other value per space/field at the moment
  */
 public function save_question($question, $form)
 {
     $gaps = $this->get_gaps($question, $form->delimitchars, $form->questiontext['text']);
     /* count the number of gaps
      * this is used to set the maximum
      * value for the whole question. Value for
      * each gap can be only 0 or 1
      */
     $form->defaultmark = count($gaps);
     return parent::save_question($question, $form);
 }
Ejemplo n.º 7
0
 public function save_question($question, $form)
 {
     $form->name = '';
     // In case someone set the question text to true/false in the old style, set it properly.
     if ($form->questiontext['text']) {
         $form->questiontext['text'] = '1';
     } else {
         $form->questiontext['text'] = '0';
     }
     $form->tags = array();
     // Name is not a required field for random questions, but
     // parent::save_question Assumes that it is.
     return parent::save_question($question, $form);
 }
Ejemplo n.º 8
0
 public function save_question($question, $form)
 {
     $form->name = '';
     $form->questiontextformat = FORMAT_MOODLE;
     $form->tags = array();
     // Name is not a required field for random questions, but
     // parent::save_question Assumes that it is.
     return parent::save_question($question, $form);
 }
Ejemplo n.º 9
0
 public function save_question($question, $form)
 {
     $form->isnew = empty($question->id);
     return parent::save_question($question, $form);
 }