本文整理汇总了PHP中quiz_questions_in_quiz函数的典型用法代码示例。如果您正苦于以下问题:PHP quiz_questions_in_quiz函数的具体用法?PHP quiz_questions_in_quiz怎么用?PHP quiz_questions_in_quiz使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了quiz_questions_in_quiz函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: quiz_report_load_questions
/**
* Load the question data necessary in the reports.
* - Remove description questions.
* - Order questions in order that they are in the quiz
* - Add question numbers.
* - Add grade from quiz_questions_instance
*/
function quiz_report_load_questions($quiz)
{
global $CFG;
$questionlist = quiz_questions_in_quiz($quiz->questions);
//In fact in most cases the id IN $questionlist below is redundant
//since we are also doing a JOIN on the qqi table. But will leave it in
//since this double check will probably do no harm.
if (!($questions = get_records_sql("SELECT q.*, qqi.grade " . "FROM {$CFG->prefix}question q, " . "{$CFG->prefix}quiz_question_instances qqi " . "WHERE q.id IN ({$questionlist}) AND " . "qqi.question = q.id AND " . "qqi.quiz =" . $quiz->id))) {
print_error('No questions found');
}
//Now we have an array of questions from a quiz we work out there question nos and remove
//questions with zero length ie. description questions etc.
//also put questions in order.
$number = 1;
$realquestions = array();
$questionids = explode(',', $questionlist);
foreach ($questionids as $id) {
if ($questions[$id]->length) {
// Ignore questions of zero length
$realquestions[$id] = $questions[$id];
$realquestions[$id]->number = $number;
$number += $questions[$id]->length;
}
}
return $realquestions;
}
示例2: quiz_report_get_significant_questions
/**
* Get the slots of real questions (not descriptions) in this quiz, in order.
* @param object $quiz the quiz.
* @return array of slot => $question object with fields
* ->slot, ->id, ->maxmark, ->number, ->length.
*/
function quiz_report_get_significant_questions($quiz)
{
global $DB;
$questionids = quiz_questions_in_quiz($quiz->questions);
if (empty($questionids)) {
return array();
}
list($usql, $params) = $DB->get_in_or_equal(explode(',', $questionids));
$params[] = $quiz->id;
$questions = $DB->get_records_sql("\nSELECT\n q.id,\n q.length,\n qqi.grade AS maxmark\n\nFROM {question} q\nJOIN {quiz_question_instances} qqi ON qqi.question = q.id\n\nWHERE\n q.id {$usql} AND\n qqi.quiz = ? AND\n length > 0", $params);
$qsbyslot = array();
$number = 1;
foreach (explode(',', $questionids) as $key => $id) {
if (!array_key_exists($id, $questions)) {
continue;
}
$slot = $key + 1;
$question = $questions[$id];
$question->slot = $slot;
$question->number = $number;
$qsbyslot[$slot] = $question;
$number += $question->length;
}
return $qsbyslot;
}
示例3: test_quiz_questions_in_quiz
public function test_quiz_questions_in_quiz() {
$this->assertEquals(quiz_questions_in_quiz(''), '');
$this->assertEquals(quiz_questions_in_quiz('0'), '');
$this->assertEquals(quiz_questions_in_quiz('0,0'), '');
$this->assertEquals(quiz_questions_in_quiz('0,0,0'), '');
$this->assertEquals(quiz_questions_in_quiz('1'), '1');
$this->assertEquals(quiz_questions_in_quiz('1,2'), '1,2');
$this->assertEquals(quiz_questions_in_quiz('1,0,2'), '1,2');
$this->assertEquals(quiz_questions_in_quiz('0,1,0,0,2,0'), '1,2');
}
示例4: display
public function display($quiz, $cm, $course)
{
global $CFG, $DB, $PAGE;
$this->quiz = $quiz;
$this->cm = $cm;
$this->course = $course;
// Get the URL options.
$slot = optional_param('slot', null, PARAM_INT);
$questionid = optional_param('qid', null, PARAM_INT);
$grade = optional_param('grade', null, PARAM_ALPHA);
$includeauto = optional_param('includeauto', false, PARAM_BOOL);
if (!in_array($grade, array('all', 'needsgrading', 'autograded', 'manuallygraded'))) {
$grade = null;
}
$pagesize = optional_param('pagesize', self::DEFAULT_PAGE_SIZE, PARAM_INT);
$page = optional_param('page', 0, PARAM_INT);
$order = optional_param('order', self::DEFAULT_ORDER, PARAM_ALPHA);
// Assemble the options requried to reload this page.
$optparams = array('includeauto', 'page');
foreach ($optparams as $param) {
if (${$param}) {
$this->viewoptions[$param] = ${$param};
}
}
if ($pagesize != self::DEFAULT_PAGE_SIZE) {
$this->viewoptions['pagesize'] = $pagesize;
}
if ($order != self::DEFAULT_ORDER) {
$this->viewoptions['order'] = $order;
}
// Check permissions.
$this->context = context_module::instance($cm->id);
require_capability('mod/quiz:grade', $this->context);
$shownames = has_capability('quiz/grading:viewstudentnames', $this->context);
$showidnumbers = has_capability('quiz/grading:viewidnumber', $this->context);
// Validate order.
if (!in_array($order, array('random', 'date', 'studentfirstname', 'studentlastname', 'idnumber'))) {
$order = self::DEFAULT_ORDER;
} else {
if (!$shownames && ($order == 'studentfirstname' || $order == 'studentlastname')) {
$order = self::DEFAULT_ORDER;
} else {
if (!$showidnumbers && $order == 'idnumber') {
$order = self::DEFAULT_ORDER;
}
}
}
if ($order == 'random') {
$page = 0;
}
// Get the list of questions in this quiz.
$this->questions = quiz_report_get_significant_questions($quiz);
if ($slot && !array_key_exists($slot, $this->questions)) {
throw new moodle_exception('unknownquestion', 'quiz_grading');
}
// Process any submitted data.
if ($data = data_submitted() && confirm_sesskey() && $this->validate_submitted_marks()) {
$this->process_submitted_data();
redirect($this->grade_question_url($slot, $questionid, $grade, $page + 1));
}
// Get the group, and the list of significant users.
$this->currentgroup = $this->get_current_group($cm, $course, $this->context);
if ($this->currentgroup == self::NO_GROUPS_ALLOWED) {
$this->users = array();
} else {
$this->users = get_users_by_capability($this->context, array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'), '', '', '', '', $this->currentgroup, '', false);
}
$questionsinquiz = quiz_questions_in_quiz($quiz->questions);
$counts = null;
if ($slot && $questionsinquiz) {
// Make sure there is something to do.
$statecounts = $this->get_question_state_summary(array($slot));
foreach ($statecounts as $record) {
if ($record->questionid == $questionid) {
$counts = $record;
break;
}
}
// If not, redirect back to the list.
if (!$counts || $counts->{$grade} == 0) {
redirect($this->list_questions_url(), get_string('alldoneredirecting', 'quiz_grading'));
}
}
// Start output.
$this->print_header_and_tabs($cm, $course, $quiz, 'grading');
// What sort of page to display?
if (!$questionsinquiz) {
echo quiz_no_questions_message($quiz, $cm, $this->context);
} else {
if (!$slot) {
$this->display_index($includeauto);
} else {
$this->display_grading_interface($slot, $questionid, $grade, $pagesize, $page, $shownames, $showidnumbers, $order, $counts);
}
}
return true;
}
示例5: print_heading
/// Print heading and tabs if this is part of a preview
if (has_capability('mod/quiz:preview', $context)) {
if ($attempt->userid == $USER->id) {
// this is the report on a preview
$currenttab = 'preview';
} else {
$currenttab = 'reports';
$mode = '';
}
include 'tabs.php';
} else {
print_heading(format_string($quiz->name));
}
/// Load all the questions and states needed by this script
// load the questions needed by page
$pagelist = $showall ? quiz_questions_in_quiz($attempt->layout) : quiz_questions_on_page($attempt->layout, $page);
$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 ({$pagelist})";
if (!($questions = get_records_sql($sql))) {
error('No questions found');
}
// Load the question type specific information
if (!get_question_options($questions)) {
error('Could not load question options');
}
// Restore the question sessions to their most recent states
// creating new sessions where required
if (!($states = get_question_states($questions, $quiz, $attempt))) {
error('Could not restore question sessions');
}
/// Print infobox
$timelimit = (int) $quiz->timelimit * 60;
示例6: quiz_upgrade_states
/**
* Upgrade states for an attempt to Moodle 1.5 model
*
* Any state that does not yet have its timestamp set to nonzero has not yet been upgraded from Moodle 1.4
* The reason these are still around is that for large sites it would have taken too long to
* upgrade all states at once. This function sets the timestamp field and creates an entry in the
* question_sessions table.
* @param object $attempt The attempt whose states need upgrading
*/
function quiz_upgrade_states($attempt)
{
global $CFG;
// The old quiz model only allowed a single response per quiz attempt so that there will be
// only one state record per question for this attempt.
// We set the timestamp of all states to the timemodified field of the attempt.
execute_sql("UPDATE {$CFG->prefix}question_states SET timestamp = '{$attempt->timemodified}' WHERE attempt = '{$attempt->uniqueid}'", false);
// For each state we create an entry in the question_sessions table, with both newest and
// newgraded pointing to this state.
// Actually we only do this for states whose question is actually listed in $attempt->layout.
// We do not do it for states associated to wrapped questions like for example the questions
// used by a RANDOM question
$session = new stdClass();
$session->attemptid = $attempt->uniqueid;
$questionlist = quiz_questions_in_quiz($attempt->layout);
if ($questionlist and $states = get_records_select('question_states', "attempt = '{$attempt->uniqueid}' AND question IN ({$questionlist})")) {
foreach ($states as $state) {
$session->newgraded = $state->id;
$session->newest = $state->id;
$session->questionid = $state->question;
insert_record('question_sessions', $session, false);
}
}
}
示例7: print_error
if (!$success) {
$pagebit = '';
if ($page) {
$pagebit = '&page=' . $page;
}
print_error('errorprocessingresponses', 'question', $CFG->wwwroot . '/mod/quiz/attempt.php?q=' . $quiz->id . $pagebit);
}
$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;
示例8: display
//.........这里部分代码省略.........
$questionids[] = $question->id;
}
$fullquestions = question_load_questions($questionids);
foreach ($questions as $qno => $question) {
$q = $fullquestions[$question->id];
$q->maxmark = $question->maxmark;
$q->slot = $qno;
$q->number = $question->number;
$questions[$qno] = $q;
}
// Get the data to be displayed.
list($quizstats, $questions, $subquestions, $s) =
$this->get_quiz_and_questions_stats($quiz, $currentgroup,
$nostudentsingroup, $useallattempts, $groupstudents, $questions);
$quizinfo = $this->get_formatted_quiz_info_data($course, $cm, $quiz, $quizstats);
// Set up the table, if there is data.
if ($s) {
$this->table->statistics_setup($quiz, $cm->id, $reporturl, $s);
}
// Print the page header stuff (if not downloading.
if (!$this->table->is_downloading()) {
$this->print_header_and_tabs($cm, $course, $quiz, 'statistics');
if (groups_get_activity_groupmode($cm)) {
groups_print_activity_menu($cm, $reporturl->out());
if ($currentgroup && !$groupstudents) {
$OUTPUT->notification(get_string('nostudentsingroup', 'quiz_statistics'));
}
}
if (!quiz_questions_in_quiz($quiz->questions)) {
echo quiz_no_questions_message($quiz, $cm, $this->context);
} else if (!$this->table->is_downloading() && $s == 0) {
echo $OUTPUT->notification(get_string('noattempts', 'quiz'));
}
// Print display options form.
$mform->set_data(array('useallattempts' => $useallattempts));
$mform->display();
}
if ($everything) { // Implies is downloading.
// Overall report, then the analysis of each question.
$this->download_quiz_info_table($quizinfo);
if ($s) {
$this->output_quiz_structure_analysis_table($s, $questions, $subquestions);
if ($this->table->is_downloading() == 'xhtml') {
$this->output_statistics_graph($quizstats->id, $s);
}
foreach ($questions as $question) {
if (question_bank::get_qtype(
$question->qtype, false)->can_analyse_responses()) {
$this->output_individual_question_response_analysis(
$question, $reporturl, $quizstats);
} else if (!empty($question->_stats->subquestions)) {
$subitemstodisplay = explode(',', $question->_stats->subquestions);
foreach ($subitemstodisplay as $subitemid) {
$this->output_individual_question_response_analysis(
$subquestions[$subitemid], $reporturl, $quizstats);
示例9: regrade_selected_attempts
function regrade_selected_attempts($quiz, $attemptids, $groupstudents) {
global $DB;
require_capability('mod/quiz:regrade', $this->context);
if ($groupstudents) {
list($usql, $params) = $DB->get_in_or_equal($groupstudents);
$where = "qa.userid $usql AND ";
} else {
$params = array();
$where = '';
}
list($asql, $aparams) = $DB->get_in_or_equal($attemptids);
$where = "qa.id $asql AND ";
$params = array_merge($params, $aparams);
$where .= "qa.quiz = ? AND qa.preview = 0";
$params[] = $quiz->id;
if (!$attempts = $DB->get_records_sql('SELECT qa.* FROM {quiz_attempts} qa WHERE '. $where, $params)) {
print_error('noattemptstoregrade', 'quiz_overview');
}
// Fetch all questions
$questions = question_load_questions(explode(',',quiz_questions_in_quiz($quiz->questions)), 'qqi.grade AS maxgrade, qqi.id AS instance',
'{quiz_question_instances} qqi ON qqi.quiz = ' . $quiz->id . ' AND q.id = qqi.question');
$updateoverallgrades = array();
foreach($attempts as $attempt) {
foreach ($questions as $question) {
$changed = regrade_question_in_attempt($question, $attempt, $quiz, true);
}
$updateoverallgrades[] = $attempt->uniqueid;
}
$this->check_overall_grades($quiz, array(), $updateoverallgrades);
}
示例10: view_questions
/**
* Prints a table containing all manually graded questions
*
* @param object $quiz Quiz object of the currrent quiz
* @param object $course Course object of the current course
* @param string $userids Comma-separated list of userids in this course
* @return boolean
* @todo Look for the TODO in this code to see what still needs to be done
**/
function view_questions($quiz)
{
global $CFG, $QTYPE_MANUAL;
$users = get_course_students($quiz->course);
if (empty($users)) {
print_heading(get_string("noattempts", "quiz"));
return true;
}
// setup the table
$table = new stdClass();
$table->head = array(get_string("essayquestions", "quiz"), get_string("ungraded", "quiz"));
$table->align = array("left", "left");
$table->wrap = array("wrap", "wrap");
$table->width = "20%";
$table->size = array("*", "*");
$table->data = array();
// get the essay questions
$questionlist = quiz_questions_in_quiz($quiz->questions);
$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})" . " AND q.qtype IN ({$QTYPE_MANUAL})" . " ORDER BY q.name";
if (empty($questionlist) or !($questions = get_records_sql($sql))) {
print_heading(get_string('noessayquestionsfound', 'quiz'));
return false;
}
notify(get_string('essayonly', 'quiz_grading'));
// get all the finished attempts by the users
$userids = implode(', ', array_keys($users));
if ($attempts = get_records_select('quiz_attempts', "quiz = {$quiz->id} and timefinish > 0 AND userid IN ({$userids}) AND preview = 0", 'userid, attempt')) {
foreach ($questions as $question) {
$link = "<a href=\"report.php?mode=grading&q={$quiz->id}&action=viewquestion&questionid={$question->id}\">" . $question->name . "</a>";
// determine the number of ungraded attempts
$ungraded = 0;
foreach ($attempts as $attempt) {
if (!$this->is_graded($question, $attempt)) {
$ungraded++;
}
}
$table->data[] = array($link, $ungraded);
}
print_table($table);
} else {
print_heading(get_string('noattempts', 'quiz'));
}
return true;
}
示例11: __construct
/**
* Constructor, assuming we already have the necessary data loaded.
*
* @param object $quiz the row from the quiz table.
* @param object $cm the course_module object for this quiz.
* @param object $course the row from the course table for the course we belong to.
* @param bool $getcontext intended for testing - stops the constructor getting the context.
*/
public function __construct($quiz, $cm, $course, $getcontext = true)
{
$this->quiz = $quiz;
$this->cm = $cm;
$this->quiz->cmid = $this->cm->id;
$this->course = $course;
if ($getcontext && !empty($cm->id)) {
$this->context = get_context_instance(CONTEXT_MODULE, $cm->id);
}
$this->questionids = explode(',', quiz_questions_in_quiz($this->quiz->questions));
}
示例12: quiz_report_load_questions
/**
* Load the question data necessary in the reports.
* - Remove description questions.
* - Order questions in order that they are in the quiz
* - Add question numbers.
* - Add grade from quiz_questions_instance
*/
function quiz_report_load_questions($quiz)
{
global $CFG, $DB;
$questionlist = quiz_questions_in_quiz($quiz->questions);
//In fact in most cases the id IN $questionlist below is redundant
//since we are also doing a JOIN on the qqi table. But will leave it in
//since this double check will probably do no harm.
list($usql, $params) = $DB->get_in_or_equal(explode(',', $questionlist));
$params[] = $quiz->id;
if (!($questions = $DB->get_records_sql("SELECT q.*, qqi.grade AS maxgrade\n FROM {question} q,\n {quiz_question_instances} qqi\n WHERE q.id {$usql} AND\n qqi.question = q.id AND\n qqi.quiz = ?", $params))) {
print_error('noquestionsfound', 'quiz');
}
//Now we have an array of questions from a quiz we work out there question nos and remove
//questions with zero length ie. description questions etc.
//also put questions in order.
$number = 1;
$realquestions = array();
$questionids = explode(',', $questionlist);
foreach ($questionids as $id) {
if ($questions[$id]->length) {
// Ignore questions of zero length
$realquestions[$id] = $questions[$id];
$realquestions[$id]->number = $number;
$number += $questions[$id]->length;
}
}
return $realquestions;
}
示例13: quiz_get_slot_for_question
/**
* Get the slot for a question with a particular id.
* @param object $quiz the quiz settings.
* @param int $questionid the of a question in the quiz.
* @return int the corresponding slot. Null if the question is not in the quiz.
*/
function quiz_get_slot_for_question($quiz, $questionid) {
$questionids = quiz_questions_in_quiz($quiz->questions);
foreach (explode(',', $questionids) as $key => $id) {
if ($id == $questionid) {
return $key + 1;
}
}
return null;
}
示例14: quiz_upgrade_states
/**
* Upgrade states for an attempt to Moodle 1.5 model
*
* Any state that does not yet have its timestamp set to nonzero has not yet been upgraded from Moodle 1.4
* The reason these are still around is that for large sites it would have taken too long to
* upgrade all states at once. This function sets the timestamp field and creates an entry in the
* question_sessions table.
* @param object $attempt The attempt whose states need upgrading
*/
function quiz_upgrade_states($attempt)
{
global $DB;
global $CFG;
// The old quiz model only allowed a single response per quiz attempt so that there will be
// only one state record per question for this attempt.
// We set the timestamp of all states to the timemodified field of the attempt.
$DB->execute("UPDATE {question_states} SET timestamp = ? WHERE attempt = ?", array($attempt->timemodified, $attempt->uniqueid));
// For each state we create an entry in the question_sessions table, with both newest and
// newgraded pointing to this state.
// Actually we only do this for states whose question is actually listed in $attempt->layout.
// We do not do it for states associated to wrapped questions like for example the questions
// used by a RANDOM question
$session = new stdClass();
$session->attemptid = $attempt->uniqueid;
$questionlist = quiz_questions_in_quiz($attempt->layout);
$params = array($attempt->uniqueid);
list($usql, $question_params) = $DB->get_in_or_equal(explode(',', $questionlist));
$params = array_merge($params, $question_params);
if ($questionlist and $states = $DB->get_records_select('question_states', "attempt = ? AND question {$usql}", $params)) {
foreach ($states as $state) {
$session->newgraded = $state->id;
$session->newest = $state->id;
$session->questionid = $state->question;
$DB->insert_record('question_sessions', $session, false);
}
}
}
示例15: __construct
/**
* Constructor, assuming we already have the necessary data loaded.
*
* @param object $quiz the row from the quiz table.
* @param object $cm the course_module object for this quiz.
* @param object $course the row from the course table for the course we belong to.
* @param bool $getcontext intended for testing - stops the constructor getting the context.
*/
public function __construct($quiz, $cm, $course, $getcontext = true)
{
$this->quiz = $quiz;
$this->cm = $cm;
$this->quiz->cmid = $this->cm->id;
$this->course = $course;
if ($getcontext && !empty($cm->id)) {
$this->context = context_module::instance($cm->id);
}
$questionids = quiz_questions_in_quiz($this->quiz->questions);
if ($questionids) {
$this->questionids = explode(',', quiz_questions_in_quiz($this->quiz->questions));
} else {
$this->questionids = array();
// Which idiot made explode(',', '') = array('')?
}
}