本文整理汇总了PHP中question_bank类的典型用法代码示例。如果您正苦于以下问题:PHP question_bank类的具体用法?PHP question_bank怎么用?PHP question_bank使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了question_bank类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: define_question_plugin_structure
/**
* Returns the qtype information to attach to question element.
*/
protected function define_question_plugin_structure()
{
$qtypeobj = question_bank::get_qtype($this->pluginname);
// Define the virtual plugin element with the condition to fulfill.
$plugin = $this->get_plugin_element(null, '../../qtype', $qtypeobj->name());
// Create one standard named plugin element (the visible container).
$pluginwrapper = new backup_nested_element($this->get_recommended_name());
// Connect the visible container ASAP.
$plugin->add_child($pluginwrapper);
// This qtype uses standard question_answers, add them here
// to the tree before any other information that will use them.
$this->add_question_question_answers($pluginwrapper);
$answers = $pluginwrapper->get_child('answers');
$answer = $answers->get_child('answer');
// Extra question fields.
$extraquestionfields = $qtypeobj->extra_question_fields();
if (!empty($extraquestionfields)) {
$tablename = array_shift($extraquestionfields);
$child = new backup_nested_element($qtypeobj->name(), array('id'), $extraquestionfields);
$pluginwrapper->add_child($child);
$child->set_source_table($tablename, array($qtypeobj->questionid_column_name() => backup::VAR_PARENTID));
}
// Extra answer fields.
$extraanswerfields = $qtypeobj->extra_answer_fields();
if (!empty($extraanswerfields)) {
$tablename = array_shift($extraanswerfields);
$child = new backup_nested_element('extraanswerdata', array('id'), $extraanswerfields);
$answer->add_child($child);
$child->set_source_table($tablename, array('answerid' => backup::VAR_PARENTID));
}
// Don't need to annotate ids nor files.
return $plugin;
}
示例2: definition_inner
protected function definition_inner($mform)
{
global $DB, $question;
$loaded_initialy = optional_param('reloaded_initialy', 1, PARAM_INT);
$qtype = question_bank::get_qtype('javaunittest');
$definitionoptions = $this->_customdata['definitionoptions'];
$attachmentoptions = $this->_customdata['attachmentoptions'];
// -------------------------- feedback options
$mform->addElement('select', 'feedbacklevel', get_string('feedbacklevel', 'qtype_javaunittest'), $qtype->feedback_levels());
$mform->setDefault('feedbacklevel', FEEDBACK_ONLY_TIMES);
// -------------------------- size of the response field
$mform->addElement('select', 'responsefieldlines', get_string('responsefieldlines', 'qtype_javaunittest'), $qtype->response_sizes());
$mform->setDefault('responsefieldlines', 15);
// -------------------------- "Given Code" Text-Area
$mform->addElement('textarea', 'givencode', get_string('givencode', 'qtype_javaunittest'), array('cols' => 80, 'rows' => 20));
$mform->setType('givencode', PARAM_RAW);
$mform->addHelpButton('givencode', 'givencode', 'qtype_javaunittest');
// -------------------------- "Test class" Text-Area
$mform->addElement('textarea', 'testclassname', get_string('testclassname', 'qtype_javaunittest'), array('cols' => 80, 'rows' => 1));
$mform->setType('testclassname', PARAM_ALPHANUMEXT);
$mform->addRule('testclassname', null, 'required');
$mform->addHelpButton('testclassname', 'testclassname', 'qtype_javaunittest');
$mform->addElement('textarea', 'junitcode', get_string('uploadtestclass', 'qtype_javaunittest'), array('cols' => 80, 'rows' => 20));
$mform->setType('junitcode', PARAM_RAW);
$mform->addRule('junitcode', null, 'required');
$mform->addHelpButton('junitcode', 'uploadtestclass', 'qtype_javaunittest');
}
示例3: get_questions_category
/**
* Function to read all questions for category into big array
*
* @param int $category category number
* @param bool $noparent if true only questions with NO parent will be selected
* @param bool $recurse include subdirectories
* @param bool $export set true if this is called by questionbank export
*/
function get_questions_category($category, $noparent = false, $recurse = true, $export = true)
{
global $DB;
// Build sql bit for $noparent
$npsql = '';
if ($noparent) {
$npsql = " and parent='0' ";
}
// Get list of categories
if ($recurse) {
$categorylist = question_categorylist($category->id);
} else {
$categorylist = array($category->id);
}
// Get the list of questions for the category
list($usql, $params) = $DB->get_in_or_equal($categorylist);
$questions = $DB->get_records_select('question', "category {$usql} {$npsql}", $params, 'qtype, name');
// Iterate through questions, getting stuff we need
$qresults = array();
foreach ($questions as $key => $question) {
$question->export_process = $export;
$qtype = question_bank::get_qtype($question->qtype, false);
if ($export && $qtype->name() == 'missingtype') {
// Unrecognised question type. Skip this question when exporting.
continue;
}
$qtype->get_question_options($question);
$qresults[] = $question;
}
return $qresults;
}
示例4: definition_inner
protected function definition_inner($mform)
{
global $PAGE, $CFG;
$PAGE->requires->js('/question/type/jme/jme_script.js');
$PAGE->requires->css('/question/type/jme/styles.css');
$mform->addElement('hidden', 'usecase', 1);
$mform->setType('usecase', PARAM_INT);
$optionscript = 'onClick = "setJSMEoptions()"';
$label = get_string('jmeoptions', 'qtype_jme');
$editoroptions[] = $mform->createElement('text', 'jmeoptions', '', array('size' => 50));
$editoroptions[] = $mform->createElement('button', 'setoptions', get_string('setoptions', 'qtype_jme'), $optionscript);
$mform->addElement('group', 'editoroptions', $label, $editoroptions, null, false);
$mform->setDefault('jmeoptions', $CFG->qtype_jme_options);
$mform->setType('jmeoptions', PARAM_RAW);
$mform->addHelpButton('editoroptions', 'jmeoptions', 'qtype_jme');
$mform->addElement('text', 'width', get_string('width', 'qtype_jme'), array('size' => 6));
$mform->setDefault('width', QTYPE_JME_APPLET_WIDTH);
$mform->setType('width', PARAM_INT);
$mform->addElement('text', 'height', get_string('height', 'qtype_jme'), array('size' => 6));
$mform->setDefault('height', QTYPE_JME_APPLET_HEIGHT);
$mform->setType('height', PARAM_INT);
$mform->addElement('static', 'answersinstruct', get_string('correctanswers', 'qtype_jme'), get_string('filloutoneanswer', 'qtype_jme'));
$mform->addElement('html', html_writer::tag('div', get_string('enablejavascript', 'qtype_jme'), array('class' => 'jme_applet', 'code' => 'JME.class', 'id' => 'jme1', 'name' => 'JME1', 'archive' => 'JME.jar', 'width' => '360', 'height' => '315', 'style' => 'margin: 1.5em auto')));
$mform->closeHeaderBefore('answersinstruct');
$this->add_per_answer_fields($mform, get_string('answerno', 'qtype_jme', '{no}'), question_bank::fraction_options());
$this->add_interactive_settings();
// Include JSME loader script as an html tag.
$jsmescript = $CFG->wwwroot . '/question/type/jme/jsme/jsme.nocache.js';
$mform->addElement('html', html_writer::tag('script', '', array('src' => $jsmescript)));
}
示例5: validation
public function validation($data, $files)
{
global $DB;
$errors = parent::validation($data, $files);
if (isset($data->categorymoveto)) {
list($category) = explode(',', $data['categorymoveto']);
} else {
list($category) = explode(',', $data['category']);
}
$saquestions = question_bank::get_qtype('randomsamatch')->get_sa_candidates($category);
$numberavailable = count($saquestions);
if ($saquestions === false) {
$a = new stdClass();
$a->catname = $DB->get_field('question_categories', 'name', array('id' => $category));
$errors['choose'] = get_string('nosaincategory', 'qtype_randomsamatch', $a);
} else {
if ($numberavailable < $data['choose']) {
$a = new stdClass();
$a->catname = $DB->get_field('question_categories', 'name', array('id' => $category));
$a->nosaquestions = $numberavailable;
$errors['choose'] = get_string('notenoughsaincategory', 'qtype_randomsamatch', $a);
}
}
return $errors;
}
示例6: definition_inner
protected function definition_inner($mform)
{
$qtype = question_bank::get_qtype('poodllrecording');
$mform->addElement('select', 'responseformat', get_string('responseformat', 'qtype_poodllrecording'), $qtype->response_formats());
$mform->setDefault('responseformat', 'editor');
$mform->addElement('editor', 'graderinfo', get_string('graderinfo', 'qtype_poodllrecording'), array('rows' => 10), $this->editoroptions);
}
示例7: test_core_question_update_flag
/**
* Test update question flag
*/
public function test_core_question_update_flag()
{
$questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
// Create a question category.
$cat = $questiongenerator->create_question_category();
$quba = question_engine::make_questions_usage_by_activity('core_question_update_flag', context_system::instance());
$quba->set_preferred_behaviour('deferredfeedback');
$questiondata = $questiongenerator->create_question('numerical', null, array('category' => $cat->id));
$question = question_bank::load_question($questiondata->id);
$slot = $quba->add_question($question);
$qa = $quba->get_question_attempt($slot);
self::setUser($this->student);
$quba->start_all_questions();
question_engine::save_questions_usage_by_activity($quba);
$qubaid = $quba->get_id();
$questionid = $question->id;
$qaid = $qa->get_database_id();
$checksum = md5($qubaid . "_" . $this->student->secret . "_" . $questionid . "_" . $qaid . "_" . $slot);
$flag = core_question_external::update_flag($qubaid, $questionid, $qaid, $slot, $checksum, true);
$this->assertTrue($flag['status']);
// Test invalid checksum.
try {
// Using random_string to force failing.
$checksum = md5($qubaid . "_" . random_string(11) . "_" . $questionid . "_" . $qaid . "_" . $slot);
core_question_external::update_flag($qubaid, $questionid, $qaid, $slot, $checksum, true);
$this->fail('Exception expected due to invalid checksum.');
} catch (moodle_exception $e) {
$this->assertEquals('errorsavingflags', $e->errorcode);
}
}
示例8: definition_inner
protected function definition_inner($mform)
{
$this->add_per_answer_fields($mform, get_string('answerno', 'qtype_numerical', '{no}'), question_bank::fraction_options());
$this->add_unit_options($mform);
$this->add_unit_fields($mform);
$this->add_interactive_settings();
}
示例9: definition_inner
protected function definition_inner($mform) {
$qtype = question_bank::get_qtype('essay');
$mform->addElement('editor', 'graderinfo', get_string('graderinfo', 'qtype_essay'),
array('rows' => 10), $this->editoroptions);
$mform->addElement('header', 'responseheader', get_string('responseheader', 'qtype_essay'));
$mform->addElement('select', 'responseformat',
get_string('responseformat', 'qtype_essay'), $qtype->response_formats());
$mform->setDefault('responseformat', 'editor');
$mform->addElement('select', 'responsefieldlines',
get_string('responsefieldlines', 'qtype_essay'), $qtype->response_sizes());
$mform->setDefault('responsefieldlines', 15);
$mform->addElement('select', 'attachments',
get_string('allowattachments', 'qtype_essay'), $qtype->attachment_options());
$mform->setDefault('attachments', 0);
$mform->addElement('select', 'responselimitpolicy',
get_string('responselimitpolicy', 'qtype_essay'), $qtype->response_limit_policies());
$mform->addHelpButton('responselimitpolicy', 'responselimitpolicy', 'qtype_essay');
$mform->addElement('text', 'wordlimit', get_string('wordlimit', 'qtype_essay'), array('size' => 3));
$mform->disabledIf('wordlimit', 'responselimitpolicy', 'eq', 0);
$mform->setType('wordlimit', PARAM_INT);
$mform->addElement('text', 'charlimit', get_string('charlimit', 'qtype_essay'), array('size' => 3));
$mform->disabledIf('charlimit', 'responselimitpolicy', 'eq', 0);
$mform->setType('charlimit', PARAM_INT);
}
示例10: make_question
public static function make_question($type, $answers = array("cat", "mat"))
{
question_bank::load_question_definition_classes($type);
$question = new qtype_gapfill_question();
test_question_maker::initialise_a_question($question);
$question->qtype = question_bank::get_qtype('gapfill');
$question->name = 'Gapfill Test Question';
$question->questiontext = "The [cat] sat on the [mat]";
$question->textfragments = array('The ', ' sat on the ');
$question->displayanswers = '1';
$question->casesensitive = '1';
$question->generalfeedback = 'congratulations on your knowledge of pets and floor covering';
$question->places[1] = $answers[0];
$question->places[2] = $answers[1];
$answer1 = new question_answer(43, $answers[0], 4, 1, 1);
$answer2 = new question_answer(44, $answers[1], 4, 1, 1);
$question->answers = array($answer1, $answer2);
$question->options = new stdClass();
$question->options->showanswers = false;
$question->options->delimitchars = "[]";
$question->options->casesensitive = false;
$question->options->correctfeedback = "";
$question->options->correctfeedbackformat = "";
$question->options->partiallycorrectfeedback = "";
$question->options->partiallycorrectfeedbackformat = "";
$question->options->incorrectfeedback = "";
$question->options->incorrectfeedbackformat = "";
$question->options->shuffledanswers = "mat,cat";
$question->options->wronganswers = "bat,dog";
$question->shuffledanswers = "mat,cat,bat,dog";
$answers = new stdClass();
$question->options->answers = array($answer1, $answer2);
$question->hints = array(new question_hint(1, 'This is the first hint.', FORMAT_HTML), new question_hint(2, 'This is the second hint.', FORMAT_HTML));
return $question;
}
示例11: test_grading_rounding_three_right
public function test_grading_rounding_three_right() {
question_bank::load_question_definition_classes('multichoice');
$mc = new qtype_multichoice_multi_question();
test_question_maker::initialise_a_question($mc);
$mc->name = 'Odd numbers';
$mc->questiontext = 'Which are the odd numbers?';
$mc->generalfeedback = '1, 3 and 5 are the odd numbers.';
$mc->qtype = question_bank::get_qtype('multichoice');
$mc->shuffleanswers = 0;
$mc->answernumbering = 'abc';
test_question_maker::set_standard_combined_feedback_fields($mc);
$mc->answers = array(
11 => new question_answer(11, '1', 0.3333333, '', FORMAT_HTML),
12 => new question_answer(12, '2', -1, '', FORMAT_HTML),
13 => new question_answer(13, '3', 0.3333333, '', FORMAT_HTML),
14 => new question_answer(14, '4', -1, '', FORMAT_HTML),
15 => new question_answer(15, '5', 0.3333333, '', FORMAT_HTML),
16 => new question_answer(16, '6', -1, '', FORMAT_HTML),
);
$mc->start_attempt(new question_attempt_step(), 1);
list($grade, $state) = $mc->grade_response(
array('choice0' => 1, 'choice2' => 1, 'choice4' => 1));
$this->assertEquals(1, $grade, '', 0.000001);
$this->assertEquals(question_state::$gradedright, $state);
}
示例12: test_import_match
public function test_import_match()
{
$xml = $this->make_test_xml();
$importer = new qformat_blackboard_six();
$questions = $importer->readquestions($xml);
$q = $questions[5];
// If qtype_ddmatch is installed, the formatter produces ddmatch
// qtypes, not match ones.
$ddmatchisinstalled = question_bank::is_qtype_installed('ddmatch');
$expectedq = new stdClass();
$expectedq->qtype = $ddmatchisinstalled ? 'ddmatch' : 'match';
$expectedq->name = 'Classify the animals.';
$expectedq->questiontext = '<i>Classify the animals.</i>';
$expectedq->questiontextformat = FORMAT_HTML;
$expectedq->correctfeedback = array('text' => '', 'format' => FORMAT_HTML);
$expectedq->partiallycorrectfeedback = array('text' => '', 'format' => FORMAT_HTML);
$expectedq->incorrectfeedback = array('text' => '', 'format' => FORMAT_HTML);
$expectedq->generalfeedback = '';
$expectedq->generalfeedbackformat = FORMAT_HTML;
$expectedq->defaultmark = 1;
$expectedq->length = 1;
$expectedq->penalty = 0.3333333;
$expectedq->shuffleanswers = get_config('quiz', 'shuffleanswers');
$expectedq->subquestions = array(array('text' => 'cat', 'format' => FORMAT_HTML), array('text' => '', 'format' => FORMAT_HTML), array('text' => 'frog', 'format' => FORMAT_HTML), array('text' => 'newt', 'format' => FORMAT_HTML));
if ($ddmatchisinstalled) {
$expectedq->subanswers = array(array('text' => 'mammal', 'format' => FORMAT_HTML), array('text' => 'insect', 'format' => FORMAT_HTML), array('text' => 'amphibian', 'format' => FORMAT_HTML), array('text' => 'amphibian', 'format' => FORMAT_HTML));
} else {
$expectedq->subanswers = array('mammal', 'insect', 'amphibian', 'amphibian');
}
$this->assert(new question_check_specified_fields_expectation($expectedq), $q);
}
示例13: __construct
/**
* Add question-type specific form fields.
*
* @param MoodleQuickForm $mform the form being built.
*/
public function __construct($submiturl, $question, $regenerate)
{
global $SESSION, $CFG, $DB;
$this->regenerate = $regenerate;
$this->question = $question;
$this->qtypeobj = question_bank::get_qtype($this->question->qtype);
// Validate the question category.
if (!($category = $DB->get_record('question_categories', array('id' => $question->category)))) {
print_error('categorydoesnotexist', 'question', $returnurl);
}
$this->category = $category;
$this->categorycontext = context::instance_by_id($category->contextid);
// Get the dataset defintions for this question.
if (empty($question->id)) {
$this->datasetdefs = $this->qtypeobj->get_dataset_definitions($question->id, $SESSION->calculated->definitionform->dataset);
} else {
if (empty($question->options)) {
$this->get_question_options($question);
}
$this->datasetdefs = $this->qtypeobj->get_dataset_definitions($question->id, array());
}
foreach ($this->datasetdefs as $datasetdef) {
// Get maxnumber.
if ($this->maxnumber == -1 || $datasetdef->itemcount < $this->maxnumber) {
$this->maxnumber = $datasetdef->itemcount;
}
}
foreach ($this->datasetdefs as $defid => $datasetdef) {
if (isset($datasetdef->id)) {
$this->datasetdefs[$defid]->items = $this->qtypeobj->get_database_dataset_items($datasetdef->id);
}
}
parent::__construct($submiturl);
}
示例14: readquestions
public function readquestions($lines)
{
question_bank::get_qtype('multianswer');
// Ensure the multianswer code is loaded.
// For this class the method has been simplified as
// there can never be more than one question for a
// multianswer import.
$questions = array();
$questiontext = array();
$questiontext['text'] = implode('', $lines);
$questiontext['format'] = FORMAT_MOODLE;
$questiontext['itemid'] = '';
$question = qtype_multianswer_extract_question($questiontext);
$question->questiontext = $question->questiontext['text'];
$question->questiontextformat = 0;
$question->qtype = 'multianswer';
$question->generalfeedback = '';
$question->generalfeedbackformat = FORMAT_MOODLE;
$question->length = 1;
$question->penalty = 0.3333333;
if (!empty($question)) {
$question->name = $this->create_default_question_name($question->questiontext, get_string('questionname', 'question'));
$questions[] = $question;
}
return $questions;
}
示例15: definition_inner
protected function definition_inner($mform)
{
$qtype = question_bank::get_qtype('essay');
$mform->addElement('header', 'responseoptions', get_string('responseoptions', 'qtype_essay'));
$mform->setExpanded('responseoptions');
$mform->addElement('select', 'responseformat', get_string('responseformat', 'qtype_essay'), $qtype->response_formats());
$mform->setDefault('responseformat', 'editor');
$mform->addElement('select', 'responserequired', get_string('responserequired', 'qtype_essay'), $qtype->response_required_options());
$mform->setDefault('responserequired', 1);
$mform->disabledIf('responserequired', 'responseformat', 'eq', 'noinline');
$mform->addElement('select', 'responsefieldlines', get_string('responsefieldlines', 'qtype_essay'), $qtype->response_sizes());
$mform->setDefault('responsefieldlines', 15);
$mform->disabledIf('responsefieldlines', 'responseformat', 'eq', 'noinline');
$mform->addElement('select', 'attachments', get_string('allowattachments', 'qtype_essay'), $qtype->attachment_options());
$mform->setDefault('attachments', 0);
$mform->addElement('select', 'attachmentsrequired', get_string('attachmentsrequired', 'qtype_essay'), $qtype->attachments_required_options());
$mform->setDefault('attachmentsrequired', 0);
$mform->addHelpButton('attachmentsrequired', 'attachmentsrequired', 'qtype_essay');
$mform->disabledIf('attachmentsrequired', 'attachments', 'eq', 0);
$mform->addElement('header', 'responsetemplateheader', get_string('responsetemplateheader', 'qtype_essay'));
$mform->addElement('editor', 'responsetemplate', get_string('responsetemplate', 'qtype_essay'), array('rows' => 10), array_merge($this->editoroptions, array('maxfiles' => 0)));
$mform->addHelpButton('responsetemplate', 'responsetemplate', 'qtype_essay');
$mform->addElement('header', 'graderinfoheader', get_string('graderinfoheader', 'qtype_essay'));
$mform->setExpanded('graderinfoheader');
$mform->addElement('editor', 'graderinfo', get_string('graderinfo', 'qtype_essay'), array('rows' => 10), $this->editoroptions);
}