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); }
/** * Loads the question type specific options for the question. * * @return boolean to indicate success or failure */ function get_question_options(&$question) { // Get additional information from database // and attach it to the question object if (!($question->options = get_record('question_imagedit', 'question', $question->id))) { notify('Error: Missing question options!'); return false; } // Get data from question_answers (for feedback) parent::get_question_options($question); return true; }
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 get_correct_responses(&$question, &$state) { $response = parent::get_correct_responses($question, $state); if (is_array($response)) { $response[''] = addslashes(str_replace('\\*', '*', stripslashes($response['']))); } return $response; }
/** * Runs all the code required to set up and save an essay question for testing purposes. * Alternate DB table prefix may be used to facilitate data deletion. */ function generate_test($name, $courseid = null) { list($form, $question) = parent::generate_test($name, $courseid); $question->category = $form->category; $form->questiontext = "How old is the sun?"; $form->generalfeedback = "General feedback"; $form->penalty = 0.1; $form->single = 1; $form->shuffleanswers = 1; $form->answernumbering = 'abc'; $form->noanswers = 3; $form->answer = array('Ancient', '5 billion years old', '4.5 billion years old'); $form->fraction = array(0.3, 0.9, 1); $form->feedback = array('True, but lacking in accuracy', 'Close, but no cigar!', 'Yep, that is it!'); $form->correctfeedback = 'Excellent!'; $form->incorrectfeedback = 'Nope!'; $form->partiallycorrectfeedback = 'Not bad'; if ($courseid) { $course = get_record('course', 'id', $courseid); } return $this->save_question($question, $form, $course); }
function check_file_access($question, $state, $options, $contextid, $component, $filearea, $args) { if ($component == 'question' && $filearea == 'answerfeedback') { $answerid = reset($args); // itemid is answer id. $answers =& $question->options->answers; if (isset($state->responses[''])) { $response = $state->responses['']; } else { $response = ''; } return $options->feedback && !empty($response); } else { return parent::check_file_access($question, $state, $options, $contextid, $component, $filearea, $args); } }
function replace_file_links($question, $fromcourseid, $tocourseid, $url, $destination) { parent::replace_file_links($question, $fromcourseid, $tocourseid, $url, $destination); // replace links in the question_match_sub table. if (isset($question->options->subquestions)) { foreach ($question->options->subquestions as $subquestion) { $subquestionchanged = false; $subquestion->questiontext = question_replace_file_links_in_html($subquestion->questiontext, $fromcourseid, $tocourseid, $url, $destination, $subquestionchanged); if ($subquestionchanged) { //need to update rec in db if (!update_record('question_match_sub', addslashes_recursive($subquestion))) { error('Couldn\'t update \'question_match_sub\' record ' . $subquestion->id); } } } } }
function check_file_access($question, $state, $options, $contextid, $component, $filearea, $args) { $itemid = reset($args); if ($filearea == 'subquestion') { // itemid is sub question id if (!array_key_exists($itemid, $question->options->subquestions)) { return false; } return true; } else { return parent::check_file_access($question, $state, $options, $contextid, $component, $filearea, $args); } }
/** * @desc Prints the questions buttons. * @param $question object The question object. * @param $state object The state object. * @param $cmoptions object The quizzes or other mods options * @param $options object The questions options. */ function print_question_submit_buttons(&$question, &$state, $cmoptions, $options) { $courseid = $cmoptions->course; $seed = $state->responses['seed']; $attempt = $state->attempt; echo "<table><tr><td>"; parent::print_question_submit_buttons($question, $state, $cmoptions, $options); echo "</td><td>"; if (!$options->readonly && $courseid != 1) { echo link_to_popup_window('/question/type/webwork/emailinstructor.php?qid=' . $question->id . '&aid=' . $attempt, 'emailinstructor', "<input type=\"button\" value=\"Email Instructor\" class=\"submit btn\">", 600, 700, "Email Instructor"); } echo "</td></tr></table>"; }
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); }
/** * Runs all the code required to set up and save an essay question for testing purposes. * Alternate DB table prefix may be used to facilitate data deletion. */ function generate_test($name, $courseid = null) { list($form, $question) = parent::generate_test($name, $courseid); $question->category = $form->category; $form->questiontext = "This question is really stupid"; $form->penalty = 1; $form->defaultgrade = 1; $form->correctanswer = 0; $form->feedbacktrue = array('Can you justify such a hasty judgment?'); $form->feedbackfalse = array('Wisdom has spoken!'); if ($courseid) { $course = get_record('course', 'id', $courseid); } return $this->save_question($question, $form, $course); }
/** * Runs all the code required to set up and save an essay question for testing purposes. * Alternate DB table prefix may be used to facilitate data deletion. */ function generate_test($name, $courseid = null) { global $DB; list($form, $question) = default_questiontype::generate_test($name, $courseid); $question->category = $form->category; $form->questiontext = "What is 674 * 36?"; $form->generalfeedback = "Thank you"; $form->penalty = 0.1; $form->defaultgrade = 1; $form->noanswers = 3; $form->answer = array('24264', '24264', '1'); $form->tolerance = array(10, 100, 0); $form->fraction = array(1, 0.5, 0); $form->nounits = 2; $form->unit = array(0 => null, 1 => null); $form->multiplier = array(1, 0); $form->feedback = array('Very good', 'Close, but not quite there', 'Well at least you tried....'); if ($courseid) { $course = $DB->get_record('course', array('id' => $courseid)); } return $this->save_question($question, $form); }
/** * If this question type requires extra CSS or JavaScript to function, * then this method will return an array of <link ...> tags that reference * those stylesheets. This function will also call require_js() * from ajaxlib.php, to get any necessary JavaScript linked in too. * * The YUI libraries needed for dragdrop have been added to the default * set of libraries. * * The two parameters match the first two parameters of print_question. * * @param object $question The question object. * @param object $state The state object. * * @return an array of bits of HTML to add to the head of pages where * this question is print_question-ed in the body. The array should use * integer array keys, which have no significance. */ function get_html_head_contributions(&$question, &$state) { // Load YUI libraries require_js("yui_yahoo"); require_js("yui_event"); require_js("yui_dom"); require_js("yui_dragdrop"); require_js("yui_animation"); $contributions = parent::get_html_head_contributions($question, $state); return $contributions; }
/** * Add styles.css to the page's header */ function get_html_head_contributions(&$question, &$state) { return parent::get_html_head_contributions($question, $state); }
function check_file_access($question, $state, $options, $contextid, $component, $filearea, $args) { $itemid = reset($args); if ($component == 'question' && $filearea == 'answerfeedback') { // check if answer id exists $result = $options->feedback && array_key_exists($itemid, $question->options->answers); if (!$result) { return false; } // check response if (!$this->check_response($question, $state)) { return false; } return true; } else { if ($filearea == 'instruction') { // TODO: should it be display all the time like questiontext? // check if question id exists if ($itemid != $question->id) { return false; } else { return true; } } else { if (in_array($filearea, array('correctfeedback', 'partiallycorrectfeedback', 'incorrectfeedback'))) { // TODO: calculated type doesn't display question feedback yet return false; } else { return parent::check_file_access($question, $state, $options, $contextid, $component, $filearea, $args); } } } }
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); }
/** * 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; }
/** * Runs all the code required to set up and save an essay question for testing purposes. * Alternate DB table prefix may be used to facilitate data deletion. */ function generate_test($name, $courseid = null) { global $DB; list($form, $question) = parent::generate_test($name, $courseid); $form->shuffleanswers = 1; $form->noanswers = 3; $form->subquestions = array('cat', 'dog', 'cow'); $form->subanswers = array('feline', 'canine', 'bovine'); if ($courseid) { $course = $DB->get_record('course', array('id' => $courseid)); } return $this->save_question($question, $form, $course); }
function display_question_editing_page(&$mform, $question, $wizardnow) { parent::display_question_editing_page($mform, $question, $wizardnow); }
/** * Runs all the code required to set up and save an essay question for testing purposes. * Alternate DB table prefix may be used to facilitate data deletion. */ function generate_test($name, $courseid = null) { list($form, $question) = parent::generate_test($name, $courseid); $question->category = $form->category; $form->questiontext = "What is the purpose of life, the universe, and everything"; $form->generalfeedback = "Congratulations, you may have solved my biggest problem!"; $form->penalty = 0.1; $form->usecase = false; $form->defaultgrade = 1; $form->noanswers = 3; $form->answer = array('42', 'who cares?', 'Be happy'); $form->fraction = array(1, 0.6, 0.8); $form->feedback = array('True, but what does that mean?', 'Well you do, dont you?', 'Yes, but thats not funny...'); $form->correctfeedback = 'Excellent!'; $form->incorrectfeedback = 'Nope!'; $form->partiallycorrectfeedback = 'Not bad'; if ($courseid) { $course = get_record('course', 'id', $courseid); } return $this->save_question($question, $form, $course); }
/** * Loads the question type specific options for the question. * * This function loads the compare algorithm type, disallowed strings and variables * into the class from the database table in which they are stored. It first uses the * parent class method to get the database information. * * @param object $question The question object for the question. This object * should be updated to include the question type * specific information (it is passed by reference). * @return bool Indicates success or failure. */ function get_question_options(&$question) { // Get the information from the database table. If this fails then immediately bail. // Note unlike the save_question_options base class method this method DOES get the question's // answers along with any answer extensions if (!parent::get_question_options($question)) { return false; } // Check that we have answers and if not then bail since this question type requires answers if (count($question->options->answers) == 0) { notify('Failed to load question answers from the table question_answers for questionid ' . $question->id); return false; } // Now get the variables from the database as well $question->options->variables = get_records('question_algebra_variables', 'question', $question->id, 'id ASC'); // Check that we have variables and if not then bail since this question type requires variables if (count($question->options->variables) == 0) { notify('Failed to load question variables from the table question_algebra_variables ' . "for questionid {$question->id}"); return false; } // Check to see if there are any allowed functions if ($question->options->allowedfuncs != '') { // Extract the allowed functions as an array $question->options->allowedfuncs = explode(',', $question->options->allowedfuncs); } else { $question->options->allowedfuncs = array(); } // Everything worked so return true return true; }
function check_file_access($question, $state, $options, $contextid, $component, $filearea, $args) { if ($component == 'question' && $filearea == 'answerfeedback') { $answers =& $question->options->answers; if (isset($state->responses[''])) { $response = $state->responses['']; } else { $response = ''; } $answerid = reset($args); // itemid is answer id. if (empty($options->feedback)) { return false; } foreach ($answers as $answer) { if ($this->test_response($question, $state, $answer)) { return true; } } return false; } else { return parent::check_file_access($question, $state, $options, $contextid, $component, $filearea, $args); } }
function save_question($question, $form, $course) { $form->defaultgrade = array_sum($form->answermark); return parent::save_question($question, $form, $course); }
/** * Runs all the code required to set up and save an essay question for testing purposes. * Alternate DB table prefix may be used to facilitate data deletion. */ function generate_test($name, $courseid = null) { list($form, $question) = parent::generate_test($name, $courseid); $question->category = $form->category; $form->questiontext = "This question consists of some text with an answer embedded right here {1:MULTICHOICE:Wrong answer#Feedback for this wrong answer~Another wrong answer#Feedback for the other wrong answer~=Correct answer#Feedback for correct answer~%50%Answer that gives half the credit#Feedback for half credit answer} and right after that you will have to deal with this short answer {1:SHORTANSWER:Wrong answer#Feedback for this wrong answer~=Correct answer#Feedback for correct answer~%50%Answer that gives half the credit#Feedback for half credit answer} and finally we have a floating point number {2:NUMERICAL:=23.8:0.1#Feedback for correct answer 23.8~%50%23.8:2#Feedback for half credit answer in the nearby region of the correct answer}.\n\nNote that addresses like www.moodle.org and smileys :-) all work as normal:\n a) How good is this? {:MULTICHOICE:=Yes#Correct~No#We have a different opinion}\n b) What grade would you give it? {3:NUMERICAL:=3:2}\n\nGood luck!\n"; $form->feedback = "feedback"; $form->generalfeedback = "General feedback"; $form->fraction = 0; $form->penalty = 0.1; $form->versioning = 0; if ($courseid) { $course = get_record('course', 'id', $courseid); } return $this->save_question($question, $form, $course); }
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); }
function get_all_responses(&$question, &$state) { $result = parent::get_all_responses($question, $state); foreach ($result->responses as $res) { if ($res->credit == 1) { return $result; } } $r = new stdClass(); $r->answer = '100%'; $r->credit = 1; $result->responses[0] = $r; return $result; }
/** * Runs all the code required to set up and save an essay question for testing purposes. * Alternate DB table prefix may be used to facilitate data deletion. */ function generate_test($name, $courseid = null) { global $DB; list($form, $question) = parent::generate_test($name, $courseid); $form->feedback = 1; $form->multiplier = array(1, 1); $form->shuffleanswers = 1; $form->noanswers = 1; $form->qtype = 'calculated'; $question->qtype = 'calculated'; $form->answers = array('{a} + {b}'); $form->fraction = array(1); $form->tolerance = array(0.01); $form->tolerancetype = array(1); $form->correctanswerlength = array(2); $form->correctanswerformat = array(1); $form->questiontext = "What is {a} + {b}?"; if ($courseid) { $course = $DB->get_record('course', array('id' => $courseid)); } $new_question = $this->save_question($question, $form, $course); $dataset_form = new stdClass(); $dataset_form->nextpageparam["forceregeneration"] = 1; $dataset_form->calcmin = array(1 => 1.0, 2 => 1.0); $dataset_form->calcmax = array(1 => 10.0, 2 => 10.0); $dataset_form->calclength = array(1 => 1, 2 => 1); $dataset_form->number = array(1 => 5.4, 2 => 4.9); $dataset_form->itemid = array(1 => '', 2 => ''); $dataset_form->calcdistribution = array(1 => 'uniform', 2 => 'uniform'); $dataset_form->definition = array(1 => "1-0-a", 2 => "1-0-b"); $dataset_form->nextpageparam = array('forceregeneration' => false); $dataset_form->addbutton = 1; $dataset_form->selectadd = 1; $dataset_form->courseid = $courseid; $dataset_form->cmid = 0; $dataset_form->id = $new_question->id; $this->save_dataset_items($new_question, $dataset_form); return $new_question; }
function replace_file_links($question, $fromcourseid, $tocourseid, $url, $destination) { parent::replace_file_links($question, $fromcourseid, $tocourseid, $url, $destination); // replace links in the question_match_sub table. // We need to use a separate object, because in load_question_options, $question->options->answers // is changed from a comma-separated list of ids to an array, so calling update_record on // $question->options stores 'Array' in that column, breaking the question. $optionschanged = false; $newoptions = new stdClass(); $newoptions->id = $question->options->id; $newoptions->correctfeedback = question_replace_file_links_in_html($question->options->correctfeedback, $fromcourseid, $tocourseid, $url, $destination, $optionschanged); $newoptions->partiallycorrectfeedback = question_replace_file_links_in_html($question->options->partiallycorrectfeedback, $fromcourseid, $tocourseid, $url, $destination, $optionschanged); $newoptions->incorrectfeedback = question_replace_file_links_in_html($question->options->incorrectfeedback, $fromcourseid, $tocourseid, $url, $destination, $optionschanged); if ($optionschanged) { if (!update_record('question_multichoice', addslashes_recursive($newoptions))) { error('Couldn\'t update \'question_multichoice\' record ' . $newoptions->id); } } $answerchanged = false; foreach ($question->options->answers as $answer) { $answer->answer = question_replace_file_links_in_html($answer->answer, $fromcourseid, $tocourseid, $url, $destination, $answerchanged); if ($answerchanged) { if (!update_record('question_answers', addslashes_recursive($answer))) { error('Couldn\'t update \'question_answers\' record ' . $answer->id); } } } }
/** * Runs all the code required to set up and save an essay question for testing purposes. * Alternate DB table prefix may be used to facilitate data deletion. */ function generate_test($name, $courseid = null) { list($form, $question) = parent::generate_test($name, $courseid); $form->questiontext = "What is the purpose of life?"; $form->feedback = "feedback"; $form->generalfeedback = "General feedback"; $form->fraction = 0; $form->penalty = 0; if ($courseid) { $course = get_record('course', 'id', $courseid); } return $this->save_question($question, $form, $course); }
function replace_file_links($question, $fromcourseid, $tocourseid, $url, $destination) { parent::replace_file_links($question, $fromcourseid, $tocourseid, $url, $destination); // replace links in the question_match_sub table. $optionschanged = false; $question->options->correctfeedback = question_replace_file_links_in_html($question->options->correctfeedback, $fromcourseid, $tocourseid, $url, $destination, $optionschanged); $question->options->partiallycorrectfeedback = question_replace_file_links_in_html($question->options->partiallycorrectfeedback, $fromcourseid, $tocourseid, $url, $destination, $optionschanged); $question->options->incorrectfeedback = question_replace_file_links_in_html($question->options->incorrectfeedback, $fromcourseid, $tocourseid, $url, $destination, $optionschanged); if ($optionschanged) { if (!update_record('question_multichoice', addslashes_recursive($question->options))) { error('Couldn\'t update \'question_multichoice\' record ' . $question->options->id); } } $answerchanged = false; foreach ($question->options->answers as $answer) { $answer->answer = question_replace_file_links_in_html($answer->answer, $fromcourseid, $tocourseid, $url, $destination, $answerchanged); if ($answerchanged) { if (!update_record('question_answers', addslashes_recursive($answer))) { error('Couldn\'t update \'question_answers\' record ' . $answer->id); } } } }