exit; } // End of process actions ================================================== // Print the page heading. echo $OUTPUT->header(); echo $OUTPUT->heading(get_string('manageqtypes', 'admin')); // Set up the table. $table = new flexible_table('qtypeadmintable'); $table->define_baseurl($thispageurl); $table->define_columns(array('questiontype', 'numquestions', 'version', 'requires', 'availableto', 'delete', 'settings')); $table->define_headers(array(get_string('questiontype', 'question'), get_string('numquestions', 'question'), get_string('version'), get_string('requires', 'admin'), get_string('availableq', 'question'), get_string('delete'), get_string('settings'))); $table->set_attribute('id', 'qtypes'); $table->set_attribute('class', 'generaltable generalbox boxaligncenter boxwidthwide'); $table->setup(); // Add a row for each question type. $createabletypes = question_bank::get_creatable_qtypes(); foreach ($sortedqtypes as $qtypename => $localname) { $qtype = $qtypes[$qtypename]; $row = array(); // Question icon and name. $fakequestion = new stdClass(); $fakequestion->qtype = $qtypename; $icon = print_question_icon($fakequestion, true); $row[] = $icon . ' ' . $localname; // Number of questions of this type. if ($counts[$qtypename]->numquestions + $counts[$qtypename]->numhidden > 0) { if ($counts[$qtypename]->numhidden > 0) { $strcount = get_string('numquestionsandhidden', 'question', $counts[$qtypename]); } else { $strcount = $counts[$qtypename]->numquestions; }
/** * Print a form to let the user choose which question type to add. * When the form is submitted, it goes to the question.php script. * @param $hiddenparams hidden parameters to add to the form, in addition to * the qtype radio buttons. * @param $allowedqtypes optional list of qtypes that are allowed. If given, only * those qtypes will be shown. Example value array('description', 'multichoice'). */ function print_choose_qtype_to_add_form($hiddenparams, array $allowedqtypes = null, $enablejs = true) { global $CFG, $PAGE, $OUTPUT; if ($enablejs) { // Add the chooser. $PAGE->requires->yui_module('moodle-question-chooser', 'M.question.init_chooser', array(array())); } $realqtypes = array(); $fakeqtypes = array(); foreach (question_bank::get_creatable_qtypes() as $qtypename => $qtype) { if ($allowedqtypes && !in_array($qtypename, $allowedqtypes)) { continue; } if ($qtype->is_real_question_type()) { $realqtypes[] = $qtype; } else { $fakeqtypes[] = $qtype; } } $renderer = $PAGE->get_renderer('question', 'bank'); return $renderer->qbank_chooser($realqtypes, $fakeqtypes, $PAGE->course, $hiddenparams); }
public function generate_questions($courses, $modules) { global $DB, $CFG; if (!is_null($this->get('questions_per_course')) && count($courses) > 0 && is_array($courses)) { require_once $CFG->libdir . '/questionlib.php'; require_once $CFG->dirroot . '/mod/quiz/editlib.php'; $questions = array(); $questionsmenu = question_bank::get_creatable_qtypes(); $questiontypes = array(); foreach ($questionsmenu as $qtype => $qname) { $questiontypes[] = $qtype; } // Add the questions foreach ($courses as $courseid) { $questions[$courseid] = array(); for ($i = 0; $i < $this->get('questions_per_course'); $i++) { $qtype = $questiontypes[array_rand($questiontypes)]; // Only the following types are supported right now. Hang around for more! $supported_types = array('match', 'essay', 'multianswer', 'multichoice', 'shortanswer', 'numerical', 'truefalse', 'calculated'); $qtype = $supported_types[array_rand($supported_types)]; if ($qtype == 'calculated') { continue; } $classname = "question_{$qtype}_qtype"; if ($qtype == 'multianswer') { $classname = "embedded_cloze_qtype"; } $question = new $classname(); $question->qtype = $qtype; $questions[$courseid][] = $question->generate_test("question{$qtype}-{$i}", $courseid); $this->verbose("Generated a question of type {$qtype} for course id {$courseid}."); } } // Assign questions to quizzes, if such exist if (!empty($modules['quiz']) && !empty($questions) && !is_null($this->get('questions_per_quiz'))) { $quizzes = $modules['quiz']; // Cannot assign more questions per quiz than are available, so determine which is the largest $questions_per_quiz = max(count($questions), $this->get('questions_per_quiz')); foreach ($quizzes as $quiz) { $questions_added = array(); for ($i = 0; $i < $questions_per_quiz; $i++) { // Add a random question to the quiz do { if (empty($quiz->course)) { print_object($quizzes); die; } $random = rand(0, count($questions[$quiz->course])); } while (in_array($random, $questions_added) || !array_key_exists($random, $questions[$quiz->course])); if (!quiz_add_quiz_question($questions[$quiz->course][$random]->id, $quiz)) { // Could not add question to quiz!! report error if (!$this->get('quiet')) { echo "WARNING: Could not add question id {$random} to quiz id {$quiz->id}{$this->eolchar}"; } } else { $this->verbose("Adding question id {$random} to quiz id {$quiz->id}."); $questions_added[] = $random; } } } } return $questions; } return null; }
/** * Print a form to let the user choose which question type to add. * When the form is submitted, it goes to the question.php script. * @param $hiddenparams hidden parameters to add to the form, in addition to * the qtype radio buttons. * @param $allowedqtypes optional list of qtypes that are allowed. If given, only * those qtypes will be shown. Example value array('description', 'multichoice'). */ function print_choose_qtype_to_add_form($hiddenparams, array $allowedqtypes = null) { global $CFG, $PAGE, $OUTPUT; echo '<div id="chooseqtypehead" class="hd">' . "\n"; echo $OUTPUT->heading(get_string('chooseqtypetoadd', 'question'), 3); echo "</div>\n"; echo '<div id="chooseqtype">' . "\n"; echo '<form action="' . $CFG->wwwroot . '/question/question.php" method="get"><div id="qtypeformdiv">' . "\n"; foreach ($hiddenparams as $name => $value) { echo '<input type="hidden" name="' . s($name) . '" value="' . s($value) . '" />' . "\n"; } echo "</div>\n"; echo '<div class="qtypes">' . "\n"; echo '<div class="instruction">' . get_string('selectaqtypefordescription', 'question') . "</div>\n"; echo '<div class="alloptions">' . "\n"; echo '<div class="realqtypes">' . "\n"; $fakeqtypes = array(); foreach (question_bank::get_creatable_qtypes() as $qtypename => $qtype) { if ($allowedqtypes && !in_array($qtypename, $allowedqtypes)) { continue; } if ($qtype->is_real_question_type()) { print_qtype_to_add_option($qtype); } else { $fakeqtypes[] = $qtype; } } echo "</div>\n"; echo '<div class="fakeqtypes">' . "\n"; foreach ($fakeqtypes as $qtype) { print_qtype_to_add_option($qtype); } echo "</div>\n"; echo "</div>\n"; echo "</div>\n"; echo '<div class="submitbuttons">' . "\n"; echo '<input type="submit" value="' . get_string('next') . '" id="chooseqtype_submit" />' . "\n"; echo '<input type="submit" id="chooseqtypecancel" name="addcancel" value="' . get_string('cancel') . '" />' . "\n"; echo "</div></form>\n"; echo "</div>\n"; $PAGE->requires->js('/question/qengine.js'); $module = array( 'name' => 'qbank', 'fullpath' => '/question/qbank.js', 'requires' => array('yui2-dom', 'yui2-event', 'yui2-container'), 'strings' => array(), 'async' => false, ); $PAGE->requires->js_init_call('qtype_chooser.init', array('chooseqtype'), false, $module); }
/** * Print a form to let the user choose which question type to add. * When the form is submitted, it goes to the question.php script. * @param $hiddenparams hidden parameters to add to the form, in addition to * the qtype radio buttons. */ function print_choose_qtype_to_add_form($hiddenparams) { global $CFG, $PAGE, $OUTPUT; $PAGE->requires->js('/question/qbank.js'); echo '<div id="chooseqtypehead" class="hd">' . "\n"; echo $OUTPUT->heading(get_string('chooseqtypetoadd', 'question'), 3); echo "</div>\n"; echo '<div id="chooseqtype">' . "\n"; echo '<form action="' . $CFG->wwwroot . '/question/question.php" method="get"><div id="qtypeformdiv">' . "\n"; foreach ($hiddenparams as $name => $value) { echo '<input type="hidden" name="' . s($name) . '" value="' . s($value) . '" />' . "\n"; } echo "</div>\n"; echo '<div class="qtypes">' . "\n"; echo '<div class="instruction">' . get_string('selectaqtypefordescription', 'question') . "</div>\n"; echo '<div class="realqtypes">' . "\n"; $fakeqtypes = array(); foreach (question_bank::get_creatable_qtypes() as $qtype) { if ($qtype->is_real_question_type()) { print_qtype_to_add_option($qtype); } else { $fakeqtypes[] = $qtype; } } echo "</div>\n"; echo '<div class="fakeqtypes">' . "\n"; foreach ($fakeqtypes as $qtype) { print_qtype_to_add_option($qtype); } echo "</div>\n"; echo "</div>\n"; echo '<div class="submitbuttons">' . "\n"; echo '<input type="submit" value="' . get_string('next') . '" id="chooseqtype_submit" />' . "\n"; echo '<input type="submit" id="chooseqtypecancel" name="addcancel" value="' . get_string('cancel') . '" />' . "\n"; echo "</div></form>\n"; echo "</div>\n"; $PAGE->requires->js_init_call('qtype_chooser.init', array('chooseqtype')); }
// Moodle is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // Moodle is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see <http://www.gnu.org/licenses/>. /** * @package mod_activequiz * @author Andrew Hancox <*****@*****.**> * @copyright 2015 Synergy Learning * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die; require_once $CFG->dirroot . '/question/engine/bank.php'; if ($ADMIN->fulltree) { $choices = array(); $defaults = array(); foreach (question_bank::get_creatable_qtypes() as $qtypename => $qtype) { $fullpluginname = $qtype->plugin_name(); $qtypepluginname = explode('_', $fullpluginname)[1]; $choices[$qtypepluginname] = $qtype->menu_name(); $defaults[$qtypepluginname] = 1; } $settings->add(new admin_setting_configmulticheckbox('activequiz/enabledqtypes', get_string('enabledquestiontypes', 'activequiz'), get_string('enabledquestiontypes_info', 'activequiz'), $defaults, $choices)); }