function save_question($question, $form, $course)
 {
     // Make very sure that descriptions can'e be created with a grade of
     // anything other than 0.
     $form->defaultgrade = 0;
     return parent::save_question($question, $form, $course);
 }
Exemple #2
0
 function save_question($question, $form, $course)
 {
     // If the category is changing, set things up as default_questiontype::save_question expects.
     list($formcategory, $unused) = explode(',', $form->category);
     if (isset($question->id) && $formcategory != $question->category) {
         $form->categorymoveto = $form->category;
     }
     $form->name = '';
     $question = parent::save_question($question, $form, $course);
     if (!($category = get_record('question_categories', 'id', $question->category))) {
         error('Could retrieve question category');
     }
     $question->name = $this->question_name($category);
     if (!set_field('question', 'name', $question->name, 'id', $question->id)) {
         error('Could not update random question name');
     }
     return $question;
 }
 function save_question($authorizedquestion, $form, $course)
 {
     $question = qtype_multianswer_extract_question($form->questiontext);
     if (isset($authorizedquestion->id)) {
         $question->id = $authorizedquestion->id;
     }
     $question->category = $authorizedquestion->category;
     $form->course = $course;
     // To pass the course object to
     // save_question_options, where it is
     // needed to call type specific
     // save_question methods.
     $form->defaultgrade = $question->defaultgrade;
     $form->questiontext = $question->questiontext;
     $form->questiontextformat = 0;
     $form->options = clone $question->options;
     unset($question->options);
     return parent::save_question($question, $form, $course);
 }
Exemple #4
0
 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);
 }
 /**
  * @desc Saves the question object. Created to make some initial checks so we don't mess up the DB badly if stuff goes wrong.
  * @param $question object The question object holding new data.
  * @param $form object The form entries.
  * @param $course object The course object.
  */
 function save_question($question, $form, $course)
 {
     //check if we have a filepath key
     if (isset($form->storekey)) {
         $key = $form->storekey;
     } elseif (isset($question->storekey)) {
         $key = $question->storekey;
     } else {
         print_error('error_no_filepath', 'qtype_webwork');
         return false;
     }
     //check if we have a record
     try {
         $wwquestion = WebworkQuestionFactory::Retrieve($key);
         $form->webwork = $wwquestion;
         $temp = array();
         $form->questiontext = addslashes(base64_decode($wwquestion->render(0, $temp, 0)));
         $form->questiontextformat = FORMAT_MOODLE;
     } catch (Exception $e) {
         print_error('error_no_filepath_record', 'qtype_webwork');
     }
     //call parent
     return parent::save_question($question, $form, $course);
 }
 function save_question($question, $form, $course)
 {
     $form->defaultgrade = array_sum($form->answermark);
     return parent::save_question($question, $form, $course);
 }
Exemple #7
0
 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->defaultgrade = $question->defaultgrade;
     $form->questiontext = $question->questiontext;
     $form->questiontextformat = 0;
     $form->options = clone $question->options;
     unset($question->options);
     return parent::save_question($question, $form);
 }
Exemple #8
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
  */
 function save_question($question, $form, $course)
 {
     $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
     //   $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)) {
                 // for a new question $form->id is empty
                 $question = parent::save_question($question, $form, $course);
                 //prepare the datasets using default $questionfromid
                 $this->preparedatasets($form);
                 $form->id = $question->id;
                 $this->save_dataset_definitions($form);
             } else {
                 if (!empty($form->makecopy)) {
                     $questionfromid = $form->id;
                     $question = parent::save_question($question, $form, $course);
                     //prepare the datasets
                     $this->preparedatasets($form, $questionfromid);
                     $form->id = $question->id;
                     $this->save_as_new_dataset_definitions($form, $questionfromid);
                 } else {
                     // editing a question
                     $question = parent::save_question($question, $form, $course);
                     //prepare the datasets
                     $this->preparedatasets($form, $question->id);
                     $form->id = $question->id;
                     $this->save_dataset_definitions($form);
                 }
             }
             break;
         case 'datasetdefinitions':
             $this->save_dataset_definitions($form);
             break;
         case 'datasetitems':
             $this->save_dataset_items($question, $form);
             break;
         default:
             error('Incorrect or no wizard page specified!');
             break;
     }
     return $question;
 }
Exemple #9
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
  */
 function save_question($question, $form)
 {
     global $DB;
     if ($this->wizard_pages_number() == 1) {
         $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
     //   $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)) {
                 // for 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
             // only need to update the synchronize field
             if (isset($form->synchronize)) {
                 $options_synchronize = $form->synchronize;
             } else {
                 $options_synchronize = 0;
             }
             $DB->set_field('question_calculated_options', 'synchronize', $options_synchronize, 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;
 }
 function save_question($authorizedquestion, $form, $course)
 {
     wrsqz_presave_question('multianswer', 'wmansprom', $authorizedquestion, $form, $course);
     global $CFG;
     require_once $CFG->dirroot . '/wiris-quizzes/lib/libquestiontype.php';
     $question = wrsqz_qtype_multianswer_extract_question($form);
     if (isset($authorizedquestion->id)) {
         $question->id = $authorizedquestion->id;
     }
     $question->category = $authorizedquestion->category;
     $form->course = $course;
     // To pass the course object to
     // save_question_options, where it is
     // needed to call type specific
     // save_question methods.
     $form->defaultgrade = $question->defaultgrade;
     $form->questiontext = $question->questiontext;
     // We do not force MOODLE_FORMAT: it is incoherent with default
     // multianswer behavior, but MOODLE_FORMAT will introduce links,
     // smileys and other undesired features, and it is coherent with
     // default questiontype behavior.
     // $form->questiontextformat = 0;
     $form->options = clone $question->options;
     unset($question->options);
     return default_questiontype::save_question($question, $form, $course);
 }
Exemple #11
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
  */
 function save_question($question, $form, $course)
 {
     global $DB;
     $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
     //   $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)) {
                 // for a new question $form->id is empty
                 $question = parent::save_question($question, $form, $course);
                 //prepare the datasets using default $questionfromid
                 $this->preparedatasets($form);
                 $form->id = $question->id;
                 $this->save_dataset_definitions($form);
             } else {
                 if (!empty($form->makecopy)) {
                     $questionfromid = $form->id;
                     $question = parent::save_question($question, $form, $course);
                     //prepare the datasets
                     $this->preparedatasets($form, $questionfromid);
                     $form->id = $question->id;
                     $this->save_as_new_dataset_definitions($form, $questionfromid);
                 } else {
                     // editing a question
                     $question = parent::save_question($question, $form, $course);
                     //prepare the datasets
                     $this->preparedatasets($form, $question->id);
                     $form->id = $question->id;
                     $this->save_dataset_definitions($form);
                 }
             }
             break;
         case 'datasetdefinitions':
             // calculated options
             $update = true;
             $options = $DB->get_record("question_calculated_options", array("question" => $question->id));
             if (!$options) {
                 $update = false;
                 $options = new stdClass();
                 $options->question = $question->id;
             }
             $options->synchronize = $form->synchronize;
             if ($update) {
                 if (!$DB->update_record("question_calculated_options", $options)) {
                     $result->error = "Could not update calculated question options! (id={$options->id})";
                     return $result;
                 }
             } else {
                 if (!$DB->insert_record("question_calculated_options", $options)) {
                     $result->error = "Could not insert calculated question options!";
                     return $result;
                 }
             }
             $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;
 }
Exemple #12
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
  */
 function save_question($question, $form, $course)
 {
     $question = default_questiontype::save_question($question, $form, $course);
     return $question;
 }
 function save_question($question, $form, $course)
 {
     global $CFG, $COURSE;
     // save question as usual
     $question = parent::save_question($question, $form, $course);
     $params = array();
     $params['returnurl'] = $form->returnurl;
     $params['id'] = $question->id;
     $params['courseid'] = $COURSE->id;
     $params['cmid'] = $form->cmid;
     // figure out if the position hotspot submit button was clicked
     // if so, redirect to the arrange page
     if (isset($form->arrange) && $form->arrange == 'true') {
         $url = new moodle_url($CFG->wwwroot . '/question/type/dragdrop/arrange.php', $params);
         redirect($url->out());
     }
     return $question;
 }