本文整理汇总了PHP中get_question_options函数的典型用法代码示例。如果您正苦于以下问题:PHP get_question_options函数的具体用法?PHP get_question_options怎么用?PHP get_question_options使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_question_options函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: question_preview_question_pluginfile
/**
* Called via pluginfile.php -> question_pluginfile to serve files belonging to
* a question in a question_attempt when that attempt is a preview.
*
* @param object $course course settings object
* @param object $context context object
* @param string $component the name of the component we are serving files for.
* @param string $filearea the name of the file area.
* @param array $args the remaining bits of the file path.
* @param bool $forcedownload whether the user must be forced to download the file.
* @return bool false if file not found, does not return if found - justsend the file
*/
function question_preview_question_pluginfile($course, $context, $component, $filearea, $attemptid, $questionid, $args, $forcedownload)
{
global $USER, $SESSION, $DB, $CFG;
require_once $CFG->dirroot . '/mod/quiz/locallib.php';
if (!($question = $DB->get_record('question', array('id' => $questionid)))) {
return send_file_not_found();
}
if (!question_has_capability_on($question, 'use', $question->category)) {
send_file_not_found();
}
if (!isset($SESSION->quizpreview->states) || $SESSION->quizpreview->questionid != $questionid) {
send_file_not_found();
}
$states = end($SESSION->quizpreview->states);
if (!array_key_exists($question->id, $states)) {
send_file_not_found();
}
$state = $states[$question->id];
// Build fake cmoptions
$quiz = new cmoptions();
$quiz->id = 0;
$quiz->review = get_config('quiz', 'review');
if (empty($course->id)) {
$quiz->course = SITEID;
} else {
$quiz->course = $course->id;
}
$quiz->decimalpoints = get_config('quiz', 'decimalpoints');
$questions[$question->id] = $question;
get_question_options($questions);
// Build fake attempt
$timenow = time();
$attempt = new stdClass();
$attempt->quiz = $quiz->id;
$attempt->userid = $USER->id;
$attempt->attempt = 0;
$attempt->sumgrades = 0;
$attempt->timestart = $timenow;
$attempt->timefinish = 0;
$attempt->timemodified = $timenow;
$attempt->uniqueid = 0;
$attempt->id = 0;
$attempt->layout = $question->id;
$options = quiz_get_renderoptions($quiz, $attempt, $context, $state);
$options->noeditlink = true;
// XXX: mulitichoice type needs quiz id to get maxgrade
$options->quizid = 0;
if (!question_check_file_access($question, $state, $options, $context->id, $component, $filearea, $args, $forcedownload)) {
send_file_not_found();
}
$fs = get_file_storage();
$relativepath = implode('/', $args);
$fullpath = "/{$context->id}/{$component}/{$filearea}/{$relativepath}";
if (!($file = $fs->get_file_by_hash(sha1($fullpath))) or $file->is_directory()) {
send_file_not_found();
}
send_stored_file($file, 0, 0, $forcedownload);
}
开发者ID:vuchannguyen,项目名称:web,代码行数:70,代码来源:previewlib.php
示例2: blended_generate_quiz
/**
*
* Creates a new PDF with the questions of a quiz's attempt.
*
* @param unknown_type $attempt record with the attempt info
* @param unknown_type $quiz
* @param unknown_type $pdf1
* @param unknown_type $blended
* @param unknown_type $options array with formatting options
* @param unknown_type $pdfFile
* @throws PDFError
*/
function blended_generate_quiz($attempt, $quiz, $pdf1, $blended, $options, $pdfFile)
{
global $QTYPES;
global $CFG;
global $COURSE;
$uniqueid = $attempt->id;
$activity_code = $uniqueid;
$identifyLabel = $options['identifyLabel'];
/*
switch($identifyLabel)
{
case 'id':
$idText= $activity_code;
break;
case 'none': $idText='';
break;
}
*/
$markSize = 3;
$quizname = $quiz->name;
$images->ok_marks = '<img src="' . $CFG->wwwroot . '/mod/blended/images/ok_marks.png" height="10" />';
$images->ko_marks = '<img src="' . $CFG->wwwroot . '/mod/blended/images/ko_marks.png" height="10" />';
// $images->ok_marks='<img src="mod/blended/images/ok_marks.png" height="10" />';
// $images->ko_marks='<img src="mod/blended/images/ko_marks.png" height="10"/>';
$howToMark = get_string('howToMarkInstructions', 'blended', $images);
$instructions = $quiz->intro . ' ' . $howToMark;
$fullname = "nombre persona";
$style = array('position' => 'S', 'border' => false, 'padding' => 1, 'fgcolor' => array(0, 0, 0), 'bgcolor' => false, 'text' => true, 'font' => 'courier', 'fontsize' => $options['fontsize'], 'stretchtext' => 4);
$headeroptions = new stdClass();
$headeroptions->rowHeight = 6;
$headeroptions->logoWidth = 30;
$headeroptions->codebarWidth = 40;
$headeroptions->textStyle = $style;
if (isset($options['logourl'])) {
$headeroptions->logo_url = $options['logourl'];
} else {
$headeroptions->logo_url = $CFG->dirroot . '/mod/blended/pix/UVa_logo.jpg';
}
$headeroptions->cellHtmlText = get_string('modulename', 'quiz') . ':' . $quizname;
//Nombre:
$headeroptions->cellHtmlDate = '';
$headeroptions->cellHtmlUser = get_string('Student', 'blended') . ':';
// Alumno:
$headeroptions->cellCourseName = $COURSE->fullname;
$headeroptions->evaluationmarksize = 3;
// if null evaluation marks are not included in header
$headeroptions->marksName = 'EVAL';
$headeroptions->codebarType = $blended->codebartype;
$headeroptions->identifyLabel = $identifyLabel;
// show readable text for codebars 'none' if not to be shown
$headeroptions->instructions = $instructions;
/**
* Give precedence to the selected number of columns in the $options
*/
if (isset($options['columns'])) {
$numcols = $options['columns'];
} else {
if (!isset($blended->numcols) || $blended->numcols == 0) {
$numcols = 2;
} else {
$numcols = $blended->numcols;
}
}
unset($quiz->questionsinuse);
unset($QTYPES["random"]->catrandoms);
$pagelist = quiz_questions_on_page($attempt->layout, 0);
$pagequestions = explode(',', $pagelist);
$questionlist = quiz_questions_in_quiz($attempt->layout);
if (!$questionlist) {
throw new PDFError("Quiz layout is empty", PDFError::QUIZ_IS_EMPTY);
}
$sql = "SELECT q.*, i.grade AS maxgrade, i.id AS instance" . " FROM {$CFG->prefix}question q," . " {$CFG->prefix}quiz_question_instances i" . " WHERE i.quiz = '{$quiz->id}' AND q.id = i.question" . " AND q.id IN ({$questionlist})";
if (!($questions = get_records_sql($sql))) {
throw new PDFError("Questions not found. ", PDFError::QUESTIONS_NOT_FOUND);
}
//Carga las preguntas con sus opciones
if (!get_question_options($questions)) {
throw new PDFError("Could not load question options", PDFError::COULD_NOT_LOAD_QUESTION_OPTIONS);
}
$quiz_userid = 4;
$acode = $attempt->id;
if (!($attemptnumber = (int) get_field_sql('SELECT MAX(attempt)+1 FROM ' . "{$CFG->prefix}quiz_attempts WHERE quiz = '{$quiz->id}' AND " . "userid = '{$quiz_userid}' AND timefinish > 0 AND preview != 1"))) {
$attemptnumber = 1;
}
$quiz_uniqueid = $attempt->attempt;
$timenow = time();
$quiz_attempt = create_new_attempt($quiz, $attemptnumber, $quiz_userid, $acode, $quiz_uniqueid, $timenow);
// Save the attempt
//.........这里部分代码省略.........
开发者ID:juacas,项目名称:moodle-mod_blended,代码行数:101,代码来源:omrlib.php
示例3: offlinequiz_create_pdf_answer
function offlinequiz_create_pdf_answer($maxanswers, $templateusage, $offlinequiz, $group, $courseid, $context)
{
global $CFG, $DB, $OUTPUT, $USER;
$letterstr = ' abcdefghijklmnopqrstuvwxyz';
$groupletter = strtoupper($letterstr[$group->number]);
$fm = new stdClass();
$fm->q = 0;
$fm->a = 0;
$texfilter = new filter_tex($context, array());
$pdf = new offlinequiz_answer_pdf('P', 'mm', 'A4');
$title = offlinequiz_str_html_pdf($offlinequiz->name);
if (!empty($offlinequiz->time)) {
$title = $title . ": " . offlinequiz_str_html_pdf(userdate($offlinequiz->time));
}
$pdf->set_title($title);
$pdf->group = $groupletter;
$pdf->groupid = $group->number;
$pdf->offlinequiz = $offlinequiz->id;
$pdf->formtype = 4;
$pdf->colwidth = 7 * 6.5;
if ($maxanswers > 5) {
$pdf->formtype = 3;
$pdf->colwidth = 9 * 6.5;
}
if ($maxanswers > 7) {
$pdf->formtype = 2;
$pdf->colwidth = 14 * 6.5;
}
if ($maxanswers > 12) {
$pdf->formtype = 1;
$pdf->colwidth = 26 * 6.5;
}
if ($maxanswers > 26) {
print_error('Too many answers in one question');
}
$pdf->userid = $USER->id;
$pdf->SetMargins(15, 20, 15);
$pdf->SetAutoPageBreak(true, 20);
$pdf->AddPage();
// Load all the questions and quba slots needed by this script.
$slots = $templateusage->get_slots();
$sql = "SELECT q.*, c.contextid, ogq.page, ogq.slot, ogq.maxmark \n FROM {offlinequiz_group_questions} ogq,\n {question} q,\n {question_categories} c\n WHERE ogq.offlinequizid = :offlinequizid\n AND ogq.offlinegroupid = :offlinegroupid\n AND q.id = ogq.questionid\n AND q.category = c.id\n ORDER BY ogq.slot ASC ";
$params = array('offlinequizid' => $offlinequiz->id, 'offlinegroupid' => $group->id);
if (!($questions = $DB->get_records_sql($sql, $params))) {
echo $OUTPUT->box_start();
echo $OUTPUT->error_text(get_string('noquestionsfound', 'offlinequiz', $groupletter));
echo $OUTPUT->box_end();
return;
}
// Load the question type specific information.
if (!get_question_options($questions)) {
print_error('Could not load question options');
}
// Counting the total number of multichoice questions in the question usage.
$totalnumber = offlinequiz_count_multichoice_questions($templateusage);
$number = 0;
$col = 1;
$offsety = 105.5;
$offsetx = 17.3;
$page = 1;
$pdf->SetY($offsety);
$pdf->SetFont('FreeSans', 'B', 10);
foreach ($slots as $key => $slot) {
set_time_limit(120);
$slotquestion = $templateusage->get_question($slot);
$currentquestionid = $slotquestion->id;
$attempt = $templateusage->get_question_attempt($slot);
$order = $slotquestion->get_order($attempt);
// Order of the answers.
// Get the question data.
$question = $questions[$currentquestionid];
// Only look at multichoice questions.
if ($question->qtype != 'multichoice' && $question->qtype != 'multichoiceset') {
continue;
}
// Print the answer letters every 8 questions.
if ($number % 8 == 0) {
$pdf->SetFont('FreeSans', '', 8);
$pdf->SetX(($col - 1) * $pdf->colwidth + $offsetx + 5);
for ($i = 0; $i < $maxanswers; $i++) {
$pdf->Cell(3.5, 3.5, number_in_style($i, $question->options->answernumbering), 0, 0, 'C');
$pdf->Cell(3, 3.5, '', 0, 0, 'C');
}
$pdf->Ln(4.5);
$pdf->SetFont('FreeSans', 'B', 10);
}
$pdf->SetX(($col - 1) * $pdf->colwidth + $offsetx);
$pdf->Cell(5, 1, $number + 1 . ") ", 0, 0, 'R');
// Print one empty box for each answer.
$x = $pdf->GetX();
$y = $pdf->GetY();
for ($i = 1; $i <= count($order); $i++) {
// Move the boxes slightly down to align with question number.
$pdf->Rect($x, $y + 0.6, 3.5, 3.5, '', array('all' => array('width' => 0.2)));
$x += 6.5;
}
$pdf->SetX($x);
$pdf->Ln(6.5);
// // Save the answer page number in the group questions table.
// $DB->set_field('offlinequiz_group_questions', 'pagenumber', $page, array('offlinequizid' => $offlinequiz->id,
//.........这里部分代码省略.........
开发者ID:frankkoch,项目名称:moodle-mod_offlinequiz,代码行数:101,代码来源:pdflib.php
示例4: display
//.........这里部分代码省略.........
$where = 'qa.id IS NOT NULL AND qa.preview = 0';
break;
case QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH:
// Show only students with attempts
list($allowed_usql, $allowed_params) = $DB->get_in_or_equal($allowed, SQL_PARAMS_NAMED, 'u0000');
$params += $allowed_params;
$where = "u.id {$allowed_usql} AND qa.preview = 0 AND qa.id IS NOT NULL";
break;
case QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH_NO:
// Show only students without attempts
list($allowed_usql, $allowed_params) = $DB->get_in_or_equal($allowed, SQL_PARAMS_NAMED, 'u0000');
$params += $allowed_params;
$where = "u.id {$allowed_usql} AND qa.id IS NULL";
break;
case QUIZ_REPORT_ATTEMPTS_ALL_STUDENTS:
// Show all students with or without attempts
list($allowed_usql, $allowed_params) = $DB->get_in_or_equal($allowed, SQL_PARAMS_NAMED, 'u0000');
$params += $allowed_params;
$where = "u.id {$allowed_usql} AND (qa.preview = 0 OR qa.preview IS NULL)";
break;
}
$table->set_count_sql("SELECT COUNT(1) FROM {$from} WHERE {$where}", $params);
$table->set_sql($fields, $from, $where, $params);
// Define table columns
$columns = array();
$headers = array();
if (!$table->is_downloading() && $candelete) {
$columns[] = 'checkbox';
$headers[] = NULL;
}
if (!$table->is_downloading() && $CFG->grade_report_showuserimage) {
$columns[] = 'picture';
$headers[] = '';
}
if (!$table->is_downloading()) {
$columns[] = 'fullname';
$headers[] = get_string('name');
} else {
$columns[] = 'lastname';
$headers[] = get_string('lastname');
$columns[] = 'firstname';
$headers[] = get_string('firstname');
}
if ($CFG->grade_report_showuseridnumber) {
$columns[] = 'idnumber';
$headers[] = get_string('idnumber');
}
if ($table->is_downloading()) {
$columns[] = 'institution';
$headers[] = get_string('institution');
$columns[] = 'department';
$headers[] = get_string('department');
$columns[] = 'email';
$headers[] = get_string('email');
$columns[] = 'timestart';
$headers[] = get_string('startedon', 'quiz');
$columns[] = 'timefinish';
$headers[] = get_string('timecompleted', 'quiz');
$columns[] = 'duration';
$headers[] = get_string('attemptduration', 'quiz');
}
if ($showgrades) {
$columns[] = 'sumgrades';
$headers[] = get_string('grade', 'quiz') . '/' . quiz_format_grade($quiz, $quiz->grade);
}
if ($hasfeedback) {
$columns[] = 'feedbacktext';
$headers[] = get_string('feedback', 'quiz');
}
// we want to display responses for all questions
foreach ($questions as $id => $question) {
// Ignore questions of zero length
$columns[] = 'qsanswer' . $id;
$headers[] = '#' . $question->number;
$question->formattedname = strip_tags(format_string($question->name));
}
// Load the question type specific information
if (!get_question_options($questions)) {
print_error('cannotloadoptions', 'quiz_responses');
}
$table->define_columns($columns);
$table->define_headers($headers);
$table->sortable(true, 'concattedid');
// Set up the table
$table->define_baseurl($reporturl->out(false, $displayoptions));
$table->collapsible(true);
$table->column_suppress('picture');
$table->column_suppress('fullname');
$table->column_suppress('idnumber');
$table->no_sorting('feedbacktext');
$table->column_class('picture', 'picture');
$table->column_class('lastname', 'bold');
$table->column_class('firstname', 'bold');
$table->column_class('fullname', 'bold');
$table->column_class('sumgrades', 'bold');
$table->set_attribute('id', 'attempts');
$table->out($pagesize, true);
}
return true;
}
开发者ID:ajv,项目名称:Offline-Caching,代码行数:101,代码来源:report.php
示例5: quiz_questions_in_quiz
}
$attempt->timemodified = $timestamp;
// We have now finished processing form data
}
/// Finish attempt if requested
if ($finishattempt) {
// Set the attempt to be finished
$attempt->timefinish = $timestamp;
// load all the questions
$closequestionlist = quiz_questions_in_quiz($attempt->layout);
$sql = "SELECT q.*, i.grade AS maxgrade, i.id AS instance" . " FROM {$CFG->prefix}question q," . " {$CFG->prefix}quiz_question_instances i" . " WHERE i.quiz = '{$quiz->id}' AND q.id = i.question" . " AND q.id IN ({$closequestionlist})";
if (!($closequestions = get_records_sql($sql))) {
error('Questions missing');
}
// Load the question type specific information
if (!get_question_options($closequestions)) {
error('Could not load question options');
}
// Restore the question sessions
if (!($closestates = get_question_states($closequestions, $quiz, $attempt))) {
error('Could not restore question sessions');
}
$success = true;
foreach ($closequestions as $key => $question) {
$action->event = QUESTION_EVENTCLOSE;
$action->responses = $closestates[$key]->responses;
$action->timestamp = $closestates[$key]->timestamp;
if (question_process_responses($question, $closestates[$key], $action, $quiz, $attempt)) {
save_question_session($question, $closestates[$key]);
} else {
$success = false;
开发者ID:edwinphillips,项目名称:moodle-485cb39,代码行数:31,代码来源:attempt.php
示例6: question_load_questions
/**
* Load a set of questions, given a list of ids. The $join and $extrafields arguments can be used
* together to pull in extra data. See, for example, the usage in mod/quiz/attempt.php, and
* read the code below to see how the SQL is assembled. Throws exceptions on error.
*
* @param array $questionids array of question ids.
* @param string $extrafields extra SQL code to be added to the query.
* @param string $join extra SQL code to be added to the query.
* @param array $extraparams values for any placeholders in $join.
* You are strongly recommended to use named placeholder.
*
* @return array question objects.
*/
function question_load_questions($questionids, $extrafields = '', $join = '')
{
$questions = question_preload_questions($questionids, $extrafields, $join);
// Load the question type specific information
if (!get_question_options($questions)) {
return 'Could not load the question options';
}
return $questions;
}
开发者ID:tyleung,项目名称:CMPUT401MoodleExams,代码行数:22,代码来源:questionlib.php
示例7: load_questions
/**
* Fully load some or all of the questions for this quiz. You must call
* {@link preload_questions()} first.
*
* @param array $questionids question ids of the questions to load. null for all.
*/
public function load_questions($questionids = null)
{
if (is_null($questionids)) {
$questionids = $this->questionids;
}
$questionstoprocess = array();
foreach ($questionids as $id) {
if (array_key_exists($id, $this->questions)) {
$questionstoprocess[$id] = $this->questions[$id];
}
}
get_question_options($questionstoprocess);
}
开发者ID:eamador,项目名称:moodle-course-custom-fields,代码行数:19,代码来源:attemptlib.php
示例8: display_analysis
/**
* Display analysis of a particular question in this quiz.
* @param object $question the row from the question table for the question to analyse.
*/
public function display_analysis($question)
{
get_question_options($question);
$this->display_question_information($question);
$dm = new question_engine_data_mapper();
$this->attempts = $dm->load_attempts_at_question($question->id, $this->qubaids);
// Setup useful internal arrays for report generation.
$this->inputs = array_keys($question->inputs);
$this->prts = array_keys($question->prts);
// TODO: change this to be a list of all *deployed* notes, not just those *used*.
$qnotes = array();
foreach ($this->attempts as $qa) {
$q = $qa->get_question();
$qnotes[$q->get_question_summary()] = true;
}
$this->qnotes = array_keys($qnotes);
// Compute results.
list($results, $answernoteresults, $answernoteresultsraw) = $this->input_report();
list($validresults, $invalidresults) = $this->input_report_separate();
// Display the results.
// Overall results.
$i = 0;
$list = '';
$tablehead = array();
foreach ($this->qnotes as $qnote) {
$list .= html_writer::tag('li', stack_ouput_castext($qnote));
$i++;
$tablehead[] = $i;
}
$tablehead[] = format_string(get_string('questionreportingtotal', 'quiz_stack'));
$tablehead = array_merge(array(''), $tablehead, $tablehead);
echo html_writer::tag('p', get_string('notesused', 'quiz_stack'));
echo html_writer::tag('ol', $list);
// Complete anwernotes.
$inputstable = new html_table();
$inputstable->head = $tablehead;
$data = array();
foreach ($answernoteresults as $prt => $anotedata) {
if (count($answernoteresults) > 1) {
$inputstable->data[] = array(html_writer::tag('b', $this->prts[$prt]));
}
$cstats = $this->column_stats($anotedata);
foreach ($anotedata as $anote => $a) {
$inputstable->data[] = array_merge(array($anote), $a, array(array_sum($a)), $cstats[$anote]);
}
}
echo html_writer::tag('p', get_string('completenotes', 'quiz_stack'));
echo html_writer::table($inputstable);
// Split anwernotes.
$inputstable = new html_table();
$inputstable->head = $tablehead;
foreach ($answernoteresultsraw as $prt => $anotedata) {
if (count($answernoteresultsraw) > 1) {
$inputstable->data[] = array(html_writer::tag('b', $this->prts[$prt]));
}
$cstats = $this->column_stats($anotedata);
foreach ($anotedata as $anote => $a) {
$inputstable->data[] = array_merge(array($anote), $a, array(array_sum($a)), $cstats[$anote]);
}
}
echo html_writer::tag('p', get_string('splitnotes', 'quiz_stack'));
echo html_writer::table($inputstable);
// Maxima analysis.
$maxheader = array();
$maxheader[] = "STACK input data for the question '" . $question->name . "'";
$maxheader[] = new moodle_url($this->get_base_url(), array('questionid' => $question->id));
$maxheader[] = "Data generated: " . date("Y-m-d H:i:s");
$maximacode = $this->maxima_comment($maxheader);
$maximacode .= "\ndisplay2d:true\$\nload(\"stackreporting\")\$\n";
$maximacode .= "stackdata:[]\$\n";
$variants = array();
foreach ($this->qnotes as $qnote) {
$variants[] = '"' . $qnote . '"';
}
$inputs = array();
foreach ($this->inputs as $input) {
$inputs[] = $input;
}
$anymaximadata = false;
// Results for each question note.
foreach ($this->qnotes as $qnote) {
echo html_writer::tag('h2', get_string('variantx', 'quiz_stack') . stack_ouput_castext($qnote));
$inputstable = new html_table();
$inputstable->attributes['class'] = 'generaltable stacktestsuite';
$inputstable->head = array_merge(array(get_string('questionreportingsummary', 'quiz_stack'), '', get_string('questionreportingscore', 'quiz_stack')), $this->prts);
foreach ($results[$qnote] as $dsummary => $summary) {
foreach ($summary as $key => $res) {
$inputstable->data[] = array_merge(array($dsummary, $res['count'], $res['fraction']), $res['answernotes']);
}
}
echo html_writer::table($inputstable);
// Separate out inputs and look at validity.
$validresultsdata = array();
foreach ($this->inputs as $input) {
$inputstable = new html_table();
$inputstable->attributes['class'] = 'generaltable stacktestsuite';
//.........这里部分代码省略.........
开发者ID:sanyaade-teachings,项目名称:quiz_stack,代码行数:101,代码来源:report.php
示例9: quiz_get_questions
function quiz_get_questions($quiz_id)
{
global $USER, $CFG, $QTYPES, $_SESSION, $DB;
include_once $CFG->dirroot . '/mod/quiz/locallib.php';
// Check to see we haven't already gotten these questions. If we have return from the session
if (!empty($_SESSION['retrived_question_ids'][$quiz_id])) {
$question_ids = $_SESSION['retrived_question_ids'][$quiz_id];
} else {
$question_ids = $DB->get_records('quiz_question_instances', array('quiz' => $quiz_id));
}
$questions = array();
if (empty($question_ids)) {
return false;
}
$_SESSION['retrived_question_ids'][$quiz_id] = $question_ids;
if (!empty($_SESSION['retrived_questions'][$quiz_id])) {
$questions = $_SESSION['retrived_questions'][$quiz_id];
} else {
foreach ($question_ids as $index => $question) {
$db_question = $DB->get_record('question', array('id' => $question->question));
$questions[$db_question->id] = $db_question;
}
get_question_options($questions);
$_SESSION['retrived_questions'][$quiz_id] = $questions;
}
return $questions;
}
开发者ID:rtcn2,项目名称:moodle-jmeter-script-generator,代码行数:27,代码来源:lib.php
示例10: load_question
/**
* Load a question definition from the database. The object returned
* will actually be of an appropriate {@link question_definition} subclass.
* @param int $questionid the id of the question to load.
* @param bool $allowshuffle if false, then any shuffle option on the selected
* quetsion is disabled.
* @return question_definition loaded from the database.
*/
public static function load_question($questionid, $allowshuffle = true) {
global $DB;
if (self::$testmode) {
// Evil, test code in production, but now way round it.
return self::return_test_question_data($questionid);
}
$questiondata = $DB->get_record_sql('
SELECT q.*, qc.contextid
FROM {question} q
JOIN {question_categories} qc ON q.category = qc.id
WHERE q.id = :id', array('id' => $questionid), MUST_EXIST);
get_question_options($questiondata);
if (!$allowshuffle) {
$questiondata->options->shuffleanswers = false;
}
return self::make_question($questiondata);
}
开发者ID:JP-Git,项目名称:moodle,代码行数:27,代码来源:bank.php
示例11: required_param
// along with Stack. If not, see <http://www.gnu.org/licenses/>.
/**
* Script to download the export of a single STACK question.
*
* @copyright 2015 the Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once __DIR__ . '/../../../config.php';
require_once $CFG->libdir . '/questionlib.php';
require_once $CFG->dirroot . '/question/format/xml/format.php';
require_once __DIR__ . '/locallib.php';
// Get the parameters from the URL.
$questionid = required_param('questionid', PARAM_INT);
// Load the necessary data.
$questiondata = $DB->get_record('question', array('id' => $questionid), '*', MUST_EXIST);
get_question_options($questiondata);
$question = question_bank::load_question($questionid);
// Process any other URL parameters, and do require_login.
list($context, $seed, $urlparams) = qtype_stack_setup_question_test_page($question);
$contexts = new question_edit_contexts($context);
// Check permissions.
question_require_capability_on($questiondata, 'edit');
require_sesskey();
// Initialise $PAGE.
$nexturl = new moodle_url('/question/type/stack/questiontestrun.php', $urlparams);
$PAGE->set_url($nexturl);
// Since this script always ends in a redirect.
$PAGE->set_heading($COURSE->fullname);
$PAGE->set_pagelayout('admin');
// Set up the export format.
$qformat = new qformat_xml();
开发者ID:sowirepo,项目名称:moodle-qtype_stack,代码行数:31,代码来源:exportone.php
示例12: evaluate_quiz
function evaluate_quiz($acode, $jobid, $newattempt, $blended)
{
global $USER;
global $CFG;
mtrace("Evaluation QUIZ Processing..." . "<BR><BR>");
try {
print "New Attempt is: " . $newattempt . "<BR/>";
$detected_userid = find_userid($acode, $jobid);
if ($detected_userid == null or $detected_userid == '') {
throw new EvaluationError(get_string('ErrorUserIDEmpty', 'blended'), EvaluationError::USERID_IS_EMPTY);
}
$user_reg = blended_get_user($detected_userid, $blended);
if ($user_reg == null) {
throw new EvaluationError(get_string('ErrorUserNotInCourse', 'blended'), EvaluationError::USER_NOT_IN_THIS_COURSE);
}
$userid = $user_reg->id;
mtrace('Obtained USERID value: ' . $userid . " OK. <BR/>");
$quiz = get_quiz($acode);
$attempts = quiz_get_user_attempts($quiz->id, $userid, 'all', true);
mtrace("Searching quiz... Success." . "<BR/>");
$uniqueid = get_uniqueid($acode);
mtrace('Obtained uniqueid: OK. <BR/>');
$timestamp = get_timestamp($acode);
mtrace('Obtained timestamp: OK. <BR/>');
if (!get_record('quiz_attempts', 'uniqueid', $uniqueid)) {
$newattempt = true;
} else {
$newattempt = false;
mtrace("User {$userid} had opened this attempt already.");
}
$attemptnumber = 1;
if ($newattempt == false) {
mtrace('Obtaining user attempt...<BR/>');
set_attempt_unfinished($uniqueid);
$attempt = quiz_get_user_attempt_unfinished($quiz->id, $userid);
} elseif ($newattempt == true) {
mtrace('Creating new attempt...<BR/>');
$attempt = create_new_attempt($quiz, $attemptnumber, $userid, $acode, $uniqueid, $timestamp);
// Save the attempt
if (!insert_record('quiz_attempts', $attempt)) {
throw new EvaluationError(get_string('ErrorCouldNotCreateAttempt', 'blended'), EvaluationError::CREATE_QUIZ_ATTEMPT_ERROR);
}
// Actualizamos el estado de las imágenes para indicar que ya está creado un nuevo attempt
update_images_status($acode, $jobid);
}
update_question_attempts($uniqueid);
// /*
mtrace('<BR>Getting questions and question options... ');
$questions = get_questions($attempt, $quiz);
if (!get_question_options($questions)) {
error('Could not load question options');
}
mtrace('Success! <BR>');
// print ("<BR>He obtenido questions: ");
//print_object($questions);
$lastattemptid = false;
// if ($attempt->attempt > 1 and $quiz->attemptonlast and !$attempt->preview) {
// Find the previous attempt
// if (!$lastattemptid = get_field('quiz_attempts', 'uniqueid', 'quiz', $attempt->quiz, 'userid', $attempt->userid, 'attempt', $attempt->attempt-1)) {
// error('Could not find previous attempt to build on');
// }
//}
//print ('He obtenido lastattemptid');
mtrace('Getting question states... ');
if (!($states = get_question_states($questions, $quiz, $attempt, $lastattemptid))) {
error('Could not restore question sessions');
}
mtrace('Success! <BR>');
mtrace('Getting responses... <BR>');
$responses = get_responses($acode, $jobid, $attempt);
//print('Estas son las responses:');
//print_object($responses);
//$timestamp=time();
$event = 8;
$actions = question_extract_responses($questions, $responses, $event);
$questionids = get_questionids($acode);
// print $questionids;
$questionidarray = explode(',', $questionids);
$success = true;
mtrace('<BR> Processing responses and saving session... ');
foreach ($questionidarray as $i) {
if (!isset($actions[$i])) {
$actions[$i]->responses = array('' => '');
$actions[$i]->event = QUESTION_EVENTOPEN;
}
$actions[$i]->timestamp = $timestamp;
if (question_process_responses($questions[$i], $states[$i], $actions[$i], $quiz, $attempt)) {
save_question_session($questions[$i], $states[$i]);
} else {
$success = false;
}
}
mtrace('Success! <BR>');
// Set the attempt to be finished
$timestamp = time();
//$attempt->timefinish = $timestamp;
// Update the quiz attempt and the overall grade for the quiz
mtrace('<BR> Finishing the attempt... ');
// print_object ($attempt);
if (set_field('quiz_attempts', 'timefinish', $timestamp, 'uniqueid', $uniqueid) == false) {
//.........这里部分代码省略.........
开发者ID:juacas,项目名称:moodle-mod_blended,代码行数:101,代码来源:evaluationlib.php
示例13: display
/**
* Displays the report.
*/
function display($quiz, $cm, $course)
{
global $CFG, $QTYPES, $DB, $OUTPUT, $PAGE;
$viewoptions = array('mode' => 'grading', 'q' => $quiz->id);
if ($questionid = optional_param('questionid', 0, PARAM_INT)) {
$viewoptions += array('questionid' => $questionid);
}
// grade question specific parameters
if ($userid = optional_param('userid', 0, PARAM_INT)) {
$viewoptions += array('userid' => $userid);
}
if ($attemptid = optional_param('attemptid', 0, PARAM_INT)) {
$viewoptions += array('attemptid' => $attemptid);
}
if ($gradeall = optional_param('gradeall', 0, PARAM_INT)) {
$viewoptions += array('gradeall' => $gradeall);
}
if ($gradeungraded = optional_param('gradeungraded', 0, PARAM_INT)) {
$viewoptions += array('gradeungraded' => $gradeungraded);
}
if ($gradenextungraded = optional_param('gradenextungraded', 0, PARAM_INT)) {
$viewoptions += array('gradenextungraded' => $gradenextungraded);
}
$this->cm = $cm;
$this->print_header_and_tabs($cm, $course, $quiz, $reportmode = "grading");
// Check permissions
$this->context = get_context_instance(CONTEXT_MODULE, $cm->id);
if (!has_capability('mod/quiz:grade', $this->context)) {
echo $OUTPUT->notification(get_string('gradingnotallowed', 'quiz_grading'));
return true;
}
$gradeableqs = quiz_report_load_questions($quiz);
$questionsinuse = implode(',', array_keys($gradeableqs));
foreach ($gradeableqs as $qid => $question) {
if (!$QTYPES[$question->qtype]->is_question_manual_graded($question, $questionsinuse)) {
unset($gradeableqs[$qid]);
}
}
if (empty($gradeableqs)) {
echo $OUTPUT->heading(get_string('noessayquestionsfound', 'quiz'));
return true;
} else {
if (count($gradeableqs) == 1) {
$questionid = array_shift(array_keys($gradeableqs));
}
}
$currentgroup = groups_get_activity_group($this->cm, true);
$this->users = get_users_by_capability($this->context, array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'), '', '', '', '', $currentgroup, '', false);
if (!empty($questionid)) {
if (!isset($gradeableqs[$questionid])) {
print_error('invalidquestionid', 'quiz_grading', '', $questionid);
} else {
$question =& $gradeableqs[$questionid];
}
// Some of the questions code is optimised to work with several questions
// at once so it wants the question to be in an array. The array key
// must be the question id.
$key = $question->id;
$questions[$key] =& $question;
// We need to add additional questiontype specific information to
// the question objects.
if (!get_question_options($questions)) {
print_error('cannotloadquestioninfo', 'quiz_grading');
}
// This will have extended the question object so that it now holds
// all the information about the questions that may be needed later.
}
add_to_log($course->id, "quiz", "manualgrading", "report.php?mode=grading&q={$quiz->id}", "{$quiz->id}", "{$cm->id}");
if ($data = data_submitted()) {
// post data submitted, process it
if (confirm_sesskey() && $this->users) {
// now go through all of the responses and save them.
$allok = true;
foreach ($data->manualgrades as $uniqueid => $response) {
// get our attempt
$uniqueid = clean_param($uniqueid, PARAM_INT);
list($usql, $params) = $DB->get_in_or_equal(array_keys($this->users));
if (!($attempt = $DB->get_record_sql("SELECT * FROM {quiz_attempts} " . "WHERE uniqueid = ? AND " . "userid {$usql} AND " . "quiz=?", array_merge(array($uniqueid), $params, array($quiz->id))))) {
print_error('invalidattemptid', 'quiz_grading');
}
// Load the state for this attempt (The questions array was created earlier)
$states = get_question_states($questions, $quiz, $attempt);
// The $states array is indexed by question id but because we are dealing
// with only one question there is only one entry in this array
$state =& $states[$question->id];
// the following will update the state and attempt
$error = question_process_comment($question, $state, $attempt, $response['comment'], FORMAT_HTML, $response['grade']);
if (is_string($error)) {
echo $OUTPUT->notification($error);
$allok = false;
} else {
if ($state->changed) {
// If the state has changed save it and update the quiz grade
save_question_session($question, $state);
quiz_save_best_grade($quiz, $attempt->userid);
}
}
//.........这里部分代码省略.........
开发者ID:vuchannguyen,项目名称:web,代码行数:101,代码来源:report.php
示例14: load_many_for_cache
public function load_many_for_cache(array $questionids) {
global $DB;
list($idcondition, $params) = $DB->get_in_or_equal($questionids);
$questiondata = $DB->get_records_sql('
SELECT q.*, qc.contextid
FROM {question} q
JOIN {question_categories} qc ON q.category = qc.id
WHERE q.id ' . $idcondition, $params);
foreach ($questionids as $id) {
if (!array_key_exists($id, $questionids)) {
throw new dml_missing_record_exception('question', '', array('id' => $id));
}
get_question_options($questiondata[$id]);
}
return $questiondata;
}
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:17,代码来源:bank.php
示例15: load_questions
/**
* Fully load some or all of the questions for this quiz. You must call {@link preload_questions()} first.
*
* @param array $questionids question ids of the questions to load. null for all.
*/
public function load_questions($questionids = null)
{
if (is_null($questionids)) {
$questionids = $this->questionids;
}
$questionstoprocess = array();
foreach ($questionids as $id) {
$questionstoprocess[$id] = $this->questions[$id];
}
if (!get_question_options($questionstoprocess)) {
throw new moodle_quiz_exception($this, 'loadingquestionsfailed', implode(', ', $questionids));
}
}
开发者ID:vuchannguyen,项目名称:web,代码行数:18,代码来源:attemptlib.php
示例16: display
/**
* Displays the report.
*/
function display($quiz, $cm, $course)
{
global $CFG, $QTYPES;
$viewoptions = array('mode' => 'grading', 'q' => $quiz->id);
if ($questionid = optional_param('questionid', 0, PARAM_INT)) {
$viewoptions += array('questionid' => $questionid);
}
// grade question specific parameters
$gradeungraded = optional_param('gradeungraded', 0, PARAM_INT);
if ($userid = optional_param('userid', 0, PARAM_INT)) {
$viewoptions += array('userid' => $userid);
}
if ($attemptid = optional_param('attemptid', 0, PARAM_INT)) {
$viewoptions += array('attemptid' => $attemptid);
}
if ($gradeall = optional_param('gradeall', 0, PARAM_INT)) {
$viewoptions += array('gradeall' => $gradeall);
}
if ($gradeungra
|
请发表评论