本文整理汇总了PHP中quiz_get_reviewoptions函数的典型用法代码示例。如果您正苦于以下问题:PHP quiz_get_reviewoptions函数的具体用法?PHP quiz_get_reviewoptions怎么用?PHP quiz_get_reviewoptions使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了quiz_get_reviewoptions函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: quiz_get_combined_reviewoptions
/**
* Combines the review options from a number of different quiz attempts.
* Returns an array of two ojects, so he suggested way of calling this
* funciton is:
* list($someoptions, $alloptions) = quiz_get_combined_reviewoptions(...)
*
* @param object $quiz the quiz instance.
* @param array $attempts an array of attempt objects.
* @param $context the roles and permissions context,
* normally the context for the quiz module instance.
*
* @return array of two options objects, one showing which options are true for
* at least one of the attempts, the other showing which options are true
* for all attempts.
*/
function quiz_get_combined_reviewoptions($quiz, $attempts, $context = null)
{
$fields = array('readonly', 'scores', 'feedback', 'correct_responses', 'solutions', 'generalfeedback', 'overallfeedback');
$someoptions = new stdClass();
$alloptions = new stdClass();
foreach ($fields as $field) {
$someoptions->{$field} = false;
$alloptions->{$field} = true;
}
foreach ($attempts as $attempt) {
$attemptoptions = quiz_get_reviewoptions($quiz, $attempt, $context);
foreach ($fields as $field) {
$someoptions->{$field} = $someoptions->{$field} || $attemptoptions->{$field};
$alloptions->{$field} = $alloptions->{$field} && $attemptoptions->{$field};
}
}
return array($someoptions, $alloptions);
}
示例2: get_string
$table->align[] = 'center';
$table->size[] = '';
}
if ($feedbackcolumn) {
$table->head[] = get_string('feedback', 'quiz');
$table->align[] = 'left';
$table->size[] = '';
}
if (isset($quiz->showtimetaken)) {
$table->head[] = get_string('timetaken', 'quiz');
$table->align[] = 'left';
$table->size[] = '';
}
// One row for each attempt
foreach ($attempts as $attempt) {
$attemptoptions = quiz_get_reviewoptions($quiz, $attempt, $context);
$row = array();
// Add the attempt number, making it a link, if appropriate.
if ($attemptcolumn) {
if ($attempt->preview) {
$row[] = get_string('preview', 'quiz');
} else {
$row[] = $attempt->attempt;
}
}
// prepare strings for time taken and date completed
$timetaken = '';
$datecompleted = '';
if ($attempt->timefinish > 0) {
// attempt has finished
$timetaken = format_time($attempt->timefinish - $attempt->timestart);
示例3: display
/**
* Display the report.
*/
function display($quiz, $cm, $course)
{
global $CFG, $COURSE, $DB, $PAGE, $OUTPUT;
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
// Work out some display options - whether there is feedback, and whether scores should be shown.
$hasfeedback = quiz_has_feedback($quiz);
$fakeattempt = new stdClass();
$fakeattempt->preview = false;
$fakeattempt->timefinish = $quiz->timeopen;
$fakeattempt->userid = 0;
$reviewoptions = quiz_get_reviewoptions($quiz, $fakeattempt, $context);
$showgrades = quiz_has_grades($quiz) && $reviewoptions->scores;
$download = optional_param('download', '', PARAM_ALPHA);
if ($attemptids = optional_param('attemptid', array(), PARAM_INT)) {
//attempts need to be deleted
require_capability('mod/quiz:deleteattempts', $context);
$attemptids = optional_param('attemptid', array(), PARAM_INT);
foreach ($attemptids as $attemptid) {
add_to_log($course->id, 'quiz', 'delete attempt', 'report.php?id=' . $cm->id, $attemptid, $cm->id);
quiz_delete_attempt($attemptid, $quiz);
}
//No need for a redirect, any attemptids that do not exist are ignored.
//So no problem if the user refreshes and tries to delete the same attempts
//twice.
}
$pageoptions = array();
$pageoptions['id'] = $cm->id;
$pageoptions['q'] = $quiz->id;
$pageoptions['mode'] = 'responses';
$reporturl = new moodle_url($CFG->wwwroot . '/mod/quiz/report.php', $pageoptions);
$qmsubselect = quiz_report_qm_filter_select($quiz);
/// find out current groups mode
$currentgroup = groups_get_activity_group($cm, true);
$mform = new mod_quiz_report_responses_settings($reporturl, array('qmsubselect' => $qmsubselect, 'quiz' => $quiz, 'currentgroup' => $currentgroup));
if ($fromform = $mform->get_data()) {
$attemptsmode = $fromform->attemptsmode;
if ($qmsubselect) {
//control is not on the form if
//the grading method is not set
//to grade one attempt per user eg. for average attempt grade.
$qmfilter = $fromform->qmfilter;
} else {
$qmfilter = 0;
}
set_user_preference('quiz_report_pagesize', $fromform->pagesize);
$pagesize = $fromform->pagesize;
} else {
$qmfilter = optional_param('qmfilter', 0, PARAM_INT);
$attemptsmode = optional_param('attemptsmode', null, PARAM_INT);
if ($attemptsmode === null) {
//default
$attemptsmode = QUIZ_REPORT_ATTEMPTS_ALL;
} else {
if ($currentgroup) {
//default for when a group is selected
if ($attemptsmode === null || $attemptsmode == QUIZ_REPORT_ATTEMPTS_ALL) {
$attemptsmode = QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH;
}
} else {
if (!$currentgroup && $course->id == SITEID) {
//force report on front page to show all, unless a group is selected.
$attemptsmode = QUIZ_REPORT_ATTEMPTS_ALL;
}
}
}
$pagesize = get_user_preferences('quiz_report_pagesize', 0);
}
if ($pagesize < 1) {
$pagesize = QUIZ_REPORT_DEFAULT_PAGE_SIZE;
}
// We only want to show the checkbox to delete attempts
// if the user has permissions and if the report mode is showing attempts.
$candelete = has_capability('mod/quiz:deleteattempts', $context) && $attemptsmode != QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH_NO;
$displayoptions = array();
$displayoptions['attemptsmode'] = $attemptsmode;
$displayoptions['qmfilter'] = $qmfilter;
//work out the sql for this table.
if (!($students = get_users_by_capability($context, array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'), '', '', '', '', '', '', false))) {
$students = array();
} else {
$students = array_keys($students);
}
if (empty($currentgroup)) {
// all users who can attempt quizzes
$allowed = $students;
$groupstudents = array();
} else {
// all users who can attempt quizzes and who are in the currently selected group
if (!($groupstudents = get_users_by_capability($context, array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'), '', '', '', '', $currentgroup, '', false))) {
$groupstudents = array();
} else {
$groupstudents = array_keys($groupstudents);
}
$allowed = $groupstudents;
}
$questions = quiz_report_load_questions($quiz);
$table = new quiz_report_responses_table($quiz, $qmsubselect, $groupstudents, $students, $questions, $candelete, $reporturl, $displayoptions);
//.........这里部分代码省略.........
示例4: print_questions_and_form
/**
* Prints questions with comment and grade form underneath each question
*
* @return void
* @todo Finish documenting this function
**/
function print_questions_and_form($quiz, $question, $userid, $attemptid, $gradeungraded, $gradenextungraded, $ungraded)
{
global $CFG;
// TODO get the context, and put in proper roles an permissions checks.
$context = NULL;
$questions[$question->id] =& $question;
$usehtmleditor = can_use_richtext_editor();
list($select, $from, $where) = $this->attempts_sql($quiz->id, false, $question->id, $userid, $attemptid, $gradeungraded, $gradenextungraded);
$sort = 'ORDER BY u.firstname, u.lastname, qa.attempt ASC';
if ($gradenextungraded) {
$attempts = get_records_sql($select . $from . $where . $sort, 0, QUIZ_REPORT_DEFAULT_GRADING_PAGE_SIZE);
} else {
$attempts = get_records_sql($select . $from . $where . $sort);
}
if ($attempts) {
$firstattempt = current($attempts);
$fullname = fullname($firstattempt);
if ($gradeungraded) {
// getting all ungraded attempts
print_heading(get_string('gradingungraded', 'quiz_grading', $ungraded), '', 3);
} else {
if ($gradenextungraded) {
// getting next ungraded attempts
print_heading(get_string('gradingnextungraded', 'quiz_grading', QUIZ_REPORT_DEFAULT_GRADING_PAGE_SIZE), '', 3);
} else {
if ($userid) {
print_heading(get_string('gradinguser', 'quiz_grading', $fullname), '', 3);
} else {
if ($attemptid) {
$a = new object();
$a->fullname = $fullname;
$a->attempt = $firstattempt->attempt;
print_heading(get_string('gradingattempt', 'quiz_grading', $a), '', 3);
} else {
print_heading(get_string('gradingall', 'quiz_grading', count($attempts)), '', 3);
}
}
}
}
// Display the form with one part for each selected attempt
echo '<form method="post" action="report.php">' . '<input type="hidden" name="mode" value="grading" />' . '<input type="hidden" name="q" value="' . $quiz->id . '" />' . '<input type="hidden" name="sesskey" value="' . sesskey() . '" />' . '<input type="hidden" name="questionid" value="' . $question->id . '" />';
foreach ($attempts as $attempt) {
// 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];
$options = quiz_get_reviewoptions($quiz, $attempt, $context);
unset($options->questioncommentlink);
$options->noeditlink = true;
$copy = $state->manualcomment;
$state->manualcomment = '';
$options->readonly = 1;
$gradedclass = question_state_is_graded($state) ? ' class="highlightgraded" ' : '';
$gradedstring = question_state_is_graded($state) ? ' ' . get_string('graded', 'quiz_grading') : '';
$a = new object();
$a->fullname = fullname($attempt, true);
$a->attempt = $attempt->attempt;
// print the user name, attempt count, the question, and some more hidden fields
echo '<div class="boxaligncenter" width="80%" style="clear:left;padding:15px;">';
echo "<span{$gradedclass}>" . get_string('gradingattempt', 'quiz_grading', $a);
echo $gradedstring . "</span>";
print_question($question, $state, '', $quiz, $options);
$prefix = "manualgrades[{$attempt->uniqueid}]";
if (!question_state_is_graded($state)) {
$grade = '';
} else {
$grade = round($state->last_graded->grade, 3);
}
$state->manualcomment = $copy;
include $CFG->dirroot . '/question/comment.html';
echo '</div>';
}
echo '<div class="boxaligncenter"><input type="submit" value="' . get_string('savechanges') . '" /></div>' . '</form>';
if ($usehtmleditor) {
use_html_editor();
}
} else {
notify(get_string('noattemptstoshow', 'quiz'));
}
}
示例5: quiz_get_recent_mod_activity
/**
* Returns all quiz graded users since a given time for specified quiz
*/
function quiz_get_recent_mod_activity(&$activities, &$index, $timestart, $courseid, $cmid, $userid = 0, $groupid = 0)
{
global $CFG, $COURSE, $USER;
require_once 'locallib.php';
if ($COURSE->id == $courseid) {
$course = $COURSE;
} else {
$course = get_record('course', 'id', $courseid);
}
$modinfo =& get_fast_modinfo($course);
$cm = $modinfo->cms[$cmid];
$quiz = get_record('quiz', 'id', $cm->instance);
if ($userid) {
$userselect = "AND u.id = {$userid}";
} else {
$userselect = '';
}
if ($groupid) {
$groupselect = "AND gm.groupid = {$groupid}";
$groupjoin = "JOIN {$CFG->prefix}groups_members gm ON gm.userid = u.id";
} else {
$groupselect = '';
$groupjoin = '';
}
if (!($attempts = get_records_sql("\n SELECT qa.*,\n u.firstname, u.lastname, u.email, u.picture, u.imagealt\n FROM {$CFG->prefix}quiz_attempts qa\n JOIN {$CFG->prefix}user u ON u.id = qa.userid\n {$groupjoin}\n WHERE qa.timefinish > {$timestart}\n AND qa.quiz = {$quiz->id}\n AND qa.preview = 0\n {$userselect}\n {$groupselect}\n ORDER BY qa.timefinish ASC"))) {
return;
}
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$accessallgroups = has_capability('moodle/site:accessallgroups', $context);
$viewfullnames = has_capability('moodle/site:viewfullnames', $context);
$grader = has_capability('mod/quiz:viewreports', $context);
$groupmode = groups_get_activity_groupmode($cm, $course);
if (is_null($modinfo->groups)) {
$modinfo->groups = groups_get_user_groups($course->id);
// load all my groups and cache it in modinfo
}
$hasgrades = $quiz->grade != 0 && $quiz->sumgrades != 0;
$usersgroups = null;
$aname = format_string($cm->name, true);
foreach ($attempts as $attempt) {
if ($attempt->userid != $USER->id) {
if (!$grader) {
// Grade permission required
continue;
}
if ($groupmode == SEPARATEGROUPS and !$accessallgroups) {
if (is_null($usersgroups)) {
$usersgroups = groups_get_all_groups($course->id, $attempt->userid, $cm->groupingid);
if (is_array($usersgroups)) {
$usersgroups = array_keys($usersgroups);
} else {
$usersgroups = array();
}
}
if (!array_intersect($usersgroups, $modinfo->groups[$cm->id])) {
continue;
}
}
}
$options = quiz_get_reviewoptions($quiz, $attempt, $context);
$tmpactivity = new stdClass();
$tmpactivity->type = 'quiz';
$tmpactivity->cmid = $cm->id;
$tmpactivity->name = $aname;
$tmpactivity->sectionnum = $cm->sectionnum;
$tmpactivity->timestamp = $attempt->timefinish;
$tmpactivity->content->attemptid = $attempt->id;
$tmpactivity->content->attempt = $attempt->attempt;
if ($hasgrades && $options->scores) {
$tmpactivity->content->sumgrades = round($attempt->sumgrades, $quiz->decimalpoints);
$tmpactivity->content->maxgrade = round($quiz->sumgrades, $quiz->decimalpoints);
} else {
$tmpactivity->content->sumgrades = null;
$tmpactivity->content->maxgrade = null;
}
$tmpactivity->user->userid = $attempt->userid;
$tmpactivity->user->fullname = fullname($attempt, $viewfullnames);
$tmpactivity->user->picture = $attempt->picture;
$tmpactivity->user->imagealt = $attempt->imagealt;
$activities[$index++] = $tmpactivity;
}
return;
}
示例6: display
/**
* Display the report.
*/
function display($quiz, $cm, $course) {
global $CFG, $COURSE, $DB, $OUTPUT;
$this->context = get_context_instance(CONTEXT_MODULE, $cm->id);
// Work out some display options - whether there is feedback, and whether scores should be shown.
$hasfeedback = quiz_has_feedback($quiz);
$fakeattempt = new stdClass();
$fakeattempt->preview = false;
$fakeattempt->timefinish = $quiz->timeopen;
$fakeattempt->userid = 0;
$reviewoptions = quiz_get_reviewoptions($quiz, $fakeattempt, $this->context);
$showgrades = quiz_has_grades($quiz) && $reviewoptions->scores;
$download = optional_param('download', '', PARAM_ALPHA);
/// find out current groups mode
$currentgroup = groups_get_activity_group($cm, true);
if (!$students = get_users_by_capability($this->context, array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'),'u.id,1','','','','','',false)) {
$students = array();
} else {
$students = array_keys($students);
}
if (empty($currentgroup)) {
// all users who can attempt quizzes
$allowed = $students;
$groupstudents = array();
} else {
// all users who can attempt quizzes and who are in the currently selected group
if (!$groupstudents = get_users_by_capability($this->context, array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'),'u.id,1','','','',$currentgroup,'',false)) {
$groupstudents = array();
} else {
$groupstudents = array_keys($groupstudents);
}
$allowed = $groupstudents;
}
$pageoptions = array();
$pageoptions['id'] = $cm->id;
$pageoptions['mode'] = 'overview';
$reporturl = new moodle_url('/mod/quiz/report.php', $pageoptions);
$qmsubselect = quiz_report_qm_filter_select($quiz);
$mform = new mod_quiz_report_overview_settings($reporturl, array('qmsubselect'=> $qmsubselect, 'quiz'=>$quiz,
'currentgroup'=>$currentgroup, 'context'=>$this->context));
if ($fromform = $mform->get_data()) {
$regradeall = false;
$regradealldry = false;
$regradealldrydo = false;
$attemptsmode = $fromform->attemptsmode;
if ($qmsubselect) {
//control is not on the form if
//the grading method is not set
//to grade one attempt per user eg. for average attempt grade.
$qmfilter = $fromform->qmfilter;
} else {
$qmfilter = 0;
}
$regradefilter = $fromform->regradefilter;
set_user_preference('quiz_report_overview_detailedmarks', $fromform->detailedmarks);
set_user_preference('quiz_report_pagesize', $fromform->pagesize);
$detailedmarks = $fromform->detailedmarks;
$pagesize = $fromform->pagesize;
} else {
$regradeall = optional_param('regradeall', 0, PARAM_BOOL);
$regradealldry = optional_param('regradealldry', 0, PARAM_BOOL);
$regradealldrydo = optional_param('regradealldrydo', 0, PARAM_BOOL);
$attemptsmode = optional_param('attemptsmode', null, PARAM_INT);
if ($qmsubselect) {
$qmfilter = optional_param('qmfilter', 0, PARAM_INT);
} else {
$qmfilter = 0;
}
$regradefilter = optional_param('regradefilter', 0, PARAM_INT);
$detailedmarks = get_user_preferences('quiz_report_overview_detailedmarks', 1);
$pagesize = get_user_preferences('quiz_report_pagesize', 0);
}
if ($currentgroup) {
//default for when a group is selected
if ($attemptsmode === null || $attemptsmode == QUIZ_REPORT_ATTEMPTS_ALL) {
$attemptsmode = QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH;
}
} else if (!$currentgroup && $course->id == SITEID) {
//force report on front page to show all, unless a group is selected.
$attemptsmode = QUIZ_REPORT_ATTEMPTS_ALL;
} else if ($attemptsmode === null) {
//default
$attemptsmode = QUIZ_REPORT_ATTEMPTS_ALL;
}
if (!$reviewoptions->scores) {
$detailedmarks = 0;
}
if ($pagesize < 1) {
$pagesize = QUIZ_REPORT_DEFAULT_PAGE_SIZE;
//.........这里部分代码省略.........
示例7: display
/**
* Display the report.
*/
function display($quiz, $cm, $course)
{
global $CFG, $db;
// Define some strings
$strreallydel = addslashes(get_string('deleteattemptcheck', 'quiz'));
$strtimeformat = get_string('strftimedatetime');
$strreviewquestion = get_string('reviewresponse', 'quiz');
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
// Only print headers if not asked to download data
if (!($download = optional_param('download', NULL))) {
$this->print_header_and_tabs($cm, $course, $quiz, "overview");
}
if ($attemptids = optional_param('attemptid', array(), PARAM_INT)) {
//attempts need to be deleted
require_capability('mod/quiz:deleteattempts', $context);
$attemptids = optional_param('attemptid', array(), PARAM_INT);
foreach ($attemptids as $attemptid) {
add_to_log($course->id, 'quiz', 'delete attempt', 'report.php?id=' . $cm->id, $attemptid, $cm->id);
quiz_delete_attempt($attemptid, $quiz);
}
//No need for a redirect, any attemptids that do not exist are ignored.
//So no problem if the user refreshes and tries to delete the same attempts
//twice.
}
// Work out some display options - whether there is feedback, and whether scores should be shown.
$hasfeedback = quiz_has_feedback($quiz->id) && $quiz->grade > 1.0E-7 && $quiz->sumgrades > 1.0E-7;
$fakeattempt = new stdClass();
$fakeattempt->preview = false;
$fakeattempt->timefinish = $quiz->timeopen;
$reviewoptions = quiz_get_reviewoptions($quiz, $fakeattempt, $context);
$showgrades = $quiz->grade && $quiz->sumgrades && $reviewoptions->scores;
$pageoptions = array();
$pageoptions['id'] = $cm->id;
$pageoptions['q'] = $quiz->id;
$pageoptions['mode'] = 'overview';
/// find out current groups mode
$currentgroup = groups_get_activity_group($cm, true);
$reporturl = new moodle_url($CFG->wwwroot . '/mod/quiz/report.php', $pageoptions);
$qmsubselect = quiz_report_qm_filter_select($quiz);
$mform = new mod_quiz_report_overview_settings($reporturl, compact('qmsubselect', 'quiz', 'currentgroup'));
if ($fromform = $mform->get_data()) {
$attemptsmode = $fromform->attemptsmode;
if ($qmsubselect) {
//control is not on the form if
//the grading method is not set
//to grade one attempt per user eg. for average attempt grade.
$qmfilter = $fromform->qmfilter;
} else {
$qmfilter = 0;
}
set_user_preference('quiz_report_overview_detailedmarks', $fromform->detailedmarks);
set_user_preference('quiz_report_pagesize', $fromform->pagesize);
$detailedmarks = $fromform->detailedmarks;
$pagesize = $fromform->pagesize;
} else {
$qmfilter = optional_param('qmfilter', 0, PARAM_INT);
$attemptsmode = optional_param('attemptsmode', QUIZ_REPORT_ATTEMPTS_ALL, PARAM_INT);
$detailedmarks = get_user_preferences('quiz_report_overview_detailedmarks', 1);
$pagesize = get_user_preferences('quiz_report_pagesize', 0);
}
if ($attemptsmode == QUIZ_REPORT_ATTEMPTS_ALL && $currentgroup) {
$attemptsmode = QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH;
}
if (!$reviewoptions->scores) {
$detailedmarks = 0;
}
if ($pagesize < 1) {
$pagesize = QUIZ_REPORT_DEFAULT_PAGE_SIZE;
}
// We only want to show the checkbox to delete attempts
// if the user has permissions and if the report mode is showing attempts.
$candelete = has_capability('mod/quiz:deleteattempts', $context) && $attemptsmode != QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH_NO;
$displayoptions = array();
$displayoptions['attemptsmode'] = $attemptsmode;
$displayoptions['qmfilter'] = $qmfilter;
$reporturlwithdisplayoptions = new moodle_url($CFG->wwwroot . '/mod/quiz/report.php', $pageoptions + $displayoptions);
if ($groupmode = groups_get_activity_groupmode($cm)) {
// Groups are being used
if (!$download) {
groups_print_activity_menu($cm, $reporturlwithdisplayoptions->out());
}
}
// Print information on the number of existing attempts
if (!$download) {
//do not print notices when downloading
if ($strattemptnum = quiz_num_attempt_summary($quiz, $cm, true, $currentgroup)) {
echo '<div class="quizattemptcounts">' . $strattemptnum . '</div>';
}
}
$nostudents = false;
if (!($students = get_users_by_capability($context, array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'), '', '', '', '', '', '', false))) {
notify(get_string('nostudentsyet'));
$nostudents = true;
$studentslist = '';
} else {
$studentslist = join(',', array_keys($students));
}
//.........这里部分代码省略.........
示例8: print_questions_and_form
/**
* Prints questions with comment and grade form underneath each question
*
* @return void
* @todo Finish documenting this function
**/
function print_questions_and_form($quiz, $question)
{
global $CFG, $db;
// grade question specific parameters
$gradeall = optional_param('gradeall', 0, PARAM_INT);
$userid = optional_param('userid', 0, PARAM_INT);
$attemptid = optional_param('attemptid', 0, PARAM_INT);
// TODO get the context, and put in proper roles an permissions checks.
$context = NULL;
$questions[$question->id] =& $question;
$usehtmleditor = can_use_richtext_editor();
$users = get_course_students($quiz->course);
$userids = implode(',', array_keys($users));
// this sql joins the attempts table and the user table
$select = 'SELECT ' . sql_concat('u.id', '\'#\'', $db->IfNull('qa.attempt', '0')) . ' AS userattemptid,
qa.id AS attemptid, qa.uniqueid, qa.attempt, qa.timefinish, qa.preview,
u.id AS userid, u.firstname, u.lastname, u.picture ';
$from = 'FROM ' . $CFG->prefix . 'user u LEFT JOIN ' . $CFG->prefix . 'quiz_attempts qa ON (u.id = qa.userid AND qa.quiz = ' . $quiz->id . ') ';
if ($gradeall) {
// get all user attempts
$where = 'WHERE u.id IN (' . $userids . ') ';
} else {
if ($userid) {
// get all the attempts for a specific user
$where = 'WHERE u.id=' . $userid . ' ';
} else {
// get a specific attempt
$where = 'WHERE qa.id=' . $attemptid . ' ';
}
}
// ignore previews
$where .= ' AND preview = 0 ';
$where .= 'AND ' . $db->IfNull('qa.attempt', '0') . ' != 0 ';
$where .= 'AND ' . $db->IfNull('qa.timefinish', '0') . ' != 0 ';
$sort = 'ORDER BY u.firstname, u.lastname, qa.attempt ASC';
$attempts = get_records_sql($select . $from . $where . $sort);
// Display the form with one part for each selected attempt
echo '<form method="post" action="report.php">' . '<input type="hidden" name="mode" value="grading" />' . '<input type="hidden" name="q" value="' . $quiz->id . '" />' . '<input type="hidden" name="sesskey" value="' . sesskey() . '" />' . '<input type="hidden" name="action" value="viewquestion" />' . '<input type="hidden" name="questionid" value="' . $question->id . '" />';
foreach ($attempts as $attempt) {
// 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];
$options = quiz_get_reviewoptions($quiz, $attempt, $context);
unset($options->questioncommentlink);
$copy = $state->manualcomment;
$state->manualcomment = '';
$options->readonly = 1;
// print the user name, attempt count, the question, and some more hidden fields
echo '<div class="boxaligncenter" width="80%" style="padding:15px;">' . fullname($attempt, true) . ': ' . get_string('attempt', 'quiz') . $attempt->attempt;
print_question($question, $state, '', $quiz, $options);
$prefix = "manualgrades[{$attempt->uniqueid}]";
$grade = round($state->last_graded->grade, 3);
$state->manualcomment = $copy;
include $CFG->dirroot . '/question/comment.html';
echo '</div>';
}
echo '<div class="boxaligncenter"><input type="submit" value="' . get_string('savechanges') . '" /></div>' . '</form>';
if ($usehtmleditor) {
use_html_editor();
}
}
示例9: print_questions_and_form
/**
* Prints questions with comment and grade form underneath each question
*
* @return void
* @todo Finish documenting this function
**/
function print_questions_and_form($quiz, $question, $userid, $attemptid, $gradeungraded, $gradenextungraded, $ungraded)
{
global $CFG, $DB, $OUTPUT;
$context = get_context_instance(CONTEXT_MODULE, $this->cm->id);
$questions[$question->id] =& $question;
$usehtmleditor = can_use_html_editor();
list($select, $from, $where, $params) = $this->attempts_sql($quiz->id, false, $question->id, $userid, $attemptid, $gradeungraded, $gradenextungraded);
$sort = 'ORDER BY u.firstname, u.lastname, qa.attempt ASC';
if ($gradenextungraded) {
$attempts = $DB->get_records_sql($select . $from . $where . $sort, $params, 0, QUIZ_REPORT_DEFAULT_GRADING_PAGE_SIZE);
} else {
$attempts = $DB->get_records_sql($select . $from . $where . $sort, $params);
}
if ($attempts) {
$firstattempt = current($attempts);
$fullname = fullname($firstattempt);
if ($gradeungraded) {
// getting all ungraded attempts
echo $OUTPUT->heading(get_string('gradingungraded', 'quiz_grading', $ungraded), 3);
} else {
if ($gradenextungraded) {
// getting next ungraded attempts
echo $OUTPUT->heading(get_string('gradingnextungraded', 'quiz_grading', QUIZ_REPORT_DEFAULT_GRADING_PAGE_SIZE), 3);
} else {
if ($userid) {
echo $OUTPUT->heading(get_string('gradinguser', 'quiz_grading', $fullname), 3);
} else {
if ($attemptid) {
$a = new object();
$a->fullname = $fullname;
$a->attempt = $firstattempt->attempt;
echo $OUTPUT->heading(get_string('gradingattempt', 'quiz_grading', $a), 3);
} else {
echo $OUTPUT->heading(get_string('gradingall', 'quiz_grading', count($attempts)), 3);
}
}
}
}
// Display the form with one part for each selected attempt
echo '<form method="post" action="report.php" class="mform" id="manualgradingform">' . '<input type="hidden" name="mode" value="grading" />' . '<input type="hidden" name="q" value="' . $quiz->id . '" />' . '<input type="hidden" name="sesskey" value="' . sesskey() . '" />' . '<input type="hidden" name="questionid" value="' . $question->id . '" />';
foreach ($attempts as $attempt) {
// 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];
$options = quiz_get_reviewoptions($quiz, $attempt, $context);
unset($options->questioncommentlink);
$options->readonly = 1;
if (question_state_is_graded($state)) {
$gradedclass = 'main highlightgraded';
$gradedstring = ' ' . get_string('graded', 'quiz_grading');
} else {
$gradedclass = 'main';
$gradedstring = '';
}
$a = new object();
$a->fullname = fullname($attempt, true);
$a->attempt = $attempt->attempt;
// print the user name, attempt count, the question, and some more hidden fields
echo '<div class="boxaligncenter" width="80%" style="clear:left;padding:15px;">';
echo $OUTPUT->heading(get_string('gradingattempt', 'quiz_grading', $a) . $gradedstring, 3, $gradedclass);
// Print the question, without showing any previous comment.
$copy = $state->manualcomment;
$state->manualcomment = '';
$options->noeditlink = true;
print_question($question, $state, '', $quiz, $options);
// The print the comment and grade fields, putting back the previous comment.
$state->manualcomment = $copy;
question_print_comment_fields($question, $state, 'manualgrades[' . $attempt->uniqueid . ']', $quiz, get_string('manualgrading', 'quiz'));
echo '</div>';
}
echo '<div class="boxaligncenter"><input type="submit" value="' . get_string('savechanges') . '" /></div>' . '</form>';
} else {
echo $OUTPUT->notification(get_string('noattemptstoshow', 'quiz'));
}
}
示例10: quiz_get_recent_mod_activity
/**
* Returns all quiz graded users since a given time for specified quiz
*/
function quiz_get_recent_mod_activity(&$activities, &$index, $timestart,
$courseid, $cmid, $userid = 0, $groupid = 0) {
global $CFG, $COURSE, $USER, $DB;
require_once('locallib.php');
if ($COURSE->id == $courseid) {
$course = $COURSE;
} else {
$course = $DB->get_record('course', array('id' => $courseid));
}
$modinfo =& get_fast_modinfo($course);
$cm = $modinfo->cms[$cmid];
$quiz = $DB->get_record('quiz', array('id' => $cm->instance));
if ($userid) {
$userselect = "AND u.id = :userid";
$params['userid'] = $userid;
} else {
$userselect = '';
}
if ($groupid) {
$groupselect = 'AND gm.groupid = :groupid';
$groupjoin = 'JOIN {groups_members} gm ON gm.userid=u.id';
$params['groupid'] = $groupid;
} else {
$groupselect = '';
$groupjoin = '';
}
$params['timestart'] = $timestart;
$params['quizid'] = $quiz->id;
if (!$attempts = $DB->get_records_sql("
SELECT qa.*,
u.firstname, u.lastname, u.email, u.picture, u.imagealt
FROM {quiz_attempts} qa
JOIN {user} u ON u.id = qa.userid
$groupjoin
WHERE qa.timefinish > :timestart
AND qa.quiz = :quizid
AND qa.preview = 0
$userselect
$groupselect
ORDER BY qa.timefinish ASC", $params)) {
return;
}
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$accessallgroups = has_capability('moodle/site:accessallgroups', $context);
$viewfullnames = has_capability('moodle/site:viewfullnames', $context);
$grader = has_capability('mod/quiz:viewreports', $context);
$groupmode = groups_get_activity_groupmode($cm, $course);
if (is_null($modinfo->groups)) {
$modinfo->groups = groups_get_user_groups($course->id); // load all my groups and cache it in modinfo
}
$usersgroups = null;
$aname = format_string($cm->name,true);
foreach ($attempts as $attempt) {
if ($attempt->userid != $USER->id) {
if (!$grader) {
// Grade permission required
continue;
}
if ($groupmode == SEPARATEGROUPS and !$accessallgroups) {
if (is_null($usersgroups)) {
$usersgroups = groups_get_all_groups($course->id,
$attempt->userid, $cm->groupingid);
if (is_array($usersgroups)) {
$usersgroups = array_keys($usersgroups);
} else {
$usersgroups = array();
}
}
if (!array_intersect($usersgroups, $modinfo->groups[$cm->id])) {
continue;
}
}
}
$options = quiz_get_reviewoptions($quiz, $attempt, $context);
$tmpactivity = new stdClass;
$tmpactivity->type = 'quiz';
$tmpactivity->cmid = $cm->id;
$tmpactivity->name = $aname;
$tmpactivity->sectionnum = $cm->sectionnum;
$tmpactivity->timestamp = $attempt->timefinish;
$tmpactivity->content->attemptid = $attempt->id;
$tmpactivity->content->attempt = $attempt->attempt;
//.........这里部分代码省略.........
示例11: get_review_options
/**
* Wrapper that calls quiz_get_reviewoptions with the appropriate arguments.
*
* @return object the review options for this user on this attempt.
*/
public function get_review_options()
{
if (is_null($this->reviewoptions)) {
$this->reviewoptions = quiz_get_reviewoptions($this->quiz, $this->attempt, $this->context);
}
return $this->reviewoptions;
}