本文整理汇总了PHP中quiz_report_qm_filter_select函数的典型用法代码示例。如果您正苦于以下问题:PHP quiz_report_qm_filter_select函数的具体用法?PHP quiz_report_qm_filter_select怎么用?PHP quiz_report_qm_filter_select使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了quiz_report_qm_filter_select函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: quiz_get_average_grade_for_questions
function quiz_get_average_grade_for_questions($quiz, $userids)
{
global $CFG;
$qmfilter = quiz_report_qm_filter_select($quiz);
$questionavgssql = "SELECT qs.question, AVG(qs.grade) FROM " . "{$CFG->prefix}question_sessions qns, " . "{$CFG->prefix}quiz_attempts qa, " . "{$CFG->prefix}question_states qs " . "WHERE qns.attemptid = qa.uniqueid AND " . "qa.quiz = {$quiz->id} AND " . ($qmfilter ? $qmfilter . ' AND ' : '') . "qa.userid IN ({$userids}) AND " . "qs.event IN (" . QUESTION_EVENTS_GRADED . ") AND " . "qns.newgraded = qs.id GROUP BY qs.question";
return get_records_sql_menu($questionavgssql);
}
示例2: init
/**
* Initialise various aspects of this report.
*
* @param string $mode
* @param string $formclass
* @param object $quiz
* @param object $cm
* @param object $course
*/
protected function init($mode, $formclass, $quiz, $cm, $course)
{
$this->mode = $mode;
$this->context = context_module::instance($cm->id);
list($currentgroup, $students, $groupstudents, $allowed) = $this->load_relevant_students($cm, $course);
$this->qmsubselect = quiz_report_qm_filter_select($quiz);
$this->form = new $formclass($this->get_base_url(), array('quiz' => $quiz, 'currentgroup' => $currentgroup, 'context' => $this->context));
return array($currentgroup, $students, $groupstudents, $allowed);
}
示例3: display
public function display($quiz, $cm, $course)
{
global $CFG, $COURSE, $DB, $OUTPUT;
$this->context = get_context_instance(CONTEXT_MODULE, $cm->id);
$download = optional_param('download', '', PARAM_ALPHA);
list($currentgroup, $students, $groupstudents, $allowed) = $this->load_relevant_students($cm);
$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) {
$qmfilter = $fromform->qmfilter;
} else {
$qmfilter = 0;
}
$regradefilter = !empty($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);
}
$this->validate_common_options($attemptsmode, $pagesize, $course, $currentgroup);
$displayoptions = array();
$displayoptions['attemptsmode'] = $attemptsmode;
$displayoptions['qmfilter'] = $qmfilter;
$displayoptions['regradefilter'] = $regradefilter;
$mform->set_data($displayoptions + array('detailedmarks' => $detailedmarks, 'pagesize' => $pagesize));
if (!$this->should_show_grades($quiz)) {
$detailedmarks = 0;
}
// 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', $this->context) && $attemptsmode != QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH_NO;
if ($attemptsmode == QUIZ_REPORT_ATTEMPTS_ALL) {
// This option is only available to users who can access all groups in
// groups mode, so setting allowed to empty (which means all quiz attempts
// are accessible, is not a security porblem.
$allowed = array();
}
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
$courseshortname = format_string($course->shortname, true, array('context' => $coursecontext));
$displaycoursecontext = get_context_instance(CONTEXT_COURSE, $COURSE->id);
$displaycourseshortname = format_string($COURSE->shortname, true, array('context' => $displaycoursecontext));
// Load the required questions.
$questions = quiz_report_get_significant_questions($quiz);
$table = new quiz_report_overview_table($quiz, $this->context, $qmsubselect, $groupstudents, $students, $detailedmarks, $questions, $candelete, $reporturl, $displayoptions);
$filename = quiz_report_download_filename(get_string('overviewfilename', 'quiz_overview'), $courseshortname, $quiz->name);
$table->is_downloading($download, $filename, $displaycourseshortname . ' ' . format_string($quiz->name, true));
if ($table->is_downloading()) {
raise_memory_limit(MEMORY_EXTRA);
}
// Process actions.
if (empty($currentgroup) || $groupstudents) {
if (optional_param('delete', 0, PARAM_BOOL) && confirm_sesskey()) {
if ($attemptids = optional_param('attemptid', array(), PARAM_INT)) {
require_capability('mod/quiz:deleteattempts', $this->context);
$this->delete_selected_attempts($quiz, $cm, $attemptids, $allowed);
redirect($reporturl->out(false, $displayoptions));
}
} else {
if (optional_param('regrade', 0, PARAM_BOOL) && confirm_sesskey()) {
if ($attemptids = optional_param('attemptid', array(), PARAM_INT)) {
require_capability('mod/quiz:regrade', $this->context);
$this->regrade_attempts($quiz, false, $groupstudents, $attemptids);
redirect($reporturl->out(false, $displayoptions));
}
}
}
}
if ($regradeall && confirm_sesskey()) {
require_capability('mod/quiz:regrade', $this->context);
$this->regrade_attempts($quiz, false, $groupstudents);
redirect($reporturl->out(false, $displayoptions), '', 5);
} else {
if ($regradealldry && confirm_sesskey()) {
require_capability('mod/quiz:regrade', $this->context);
$this->regrade_attempts($quiz, true, $groupstudents);
redirect($reporturl->out(false, $displayoptions), '', 5);
} else {
if ($regradealldrydo && confirm_sesskey()) {
//.........这里部分代码省略.........
示例4: 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);
//.........这里部分代码省略.........
示例5: test_quiz_report_qm_filter_select_first_last_best
public function test_quiz_report_qm_filter_select_first_last_best()
{
global $DB;
$this->resetAfterTest();
$fakeattempt = new stdClass();
$fakeattempt->userid = 123;
$fakeattempt->quiz = 456;
$fakeattempt->layout = '1,2,0,3,4,0,5';
$fakeattempt->state = quiz_attempt::FINISHED;
// We intentionally insert these in a funny order, to test the SQL better.
// The test data is:
// id | quizid | user | attempt | sumgrades | state
// ---------------------------------------------------
// 4 | 456 | 123 | 1 | 30 | finished
// 2 | 456 | 123 | 2 | 50 | finished
// 1 | 456 | 123 | 3 | 50 | finished
// 3 | 456 | 123 | 4 | null | inprogress
// 5 | 456 | 1 | 1 | 100 | finished
// layout is only given because it has a not-null constraint.
// uniqueid values are meaningless, but that column has a unique constraint.
$fakeattempt->attempt = 3;
$fakeattempt->sumgrades = 50;
$fakeattempt->uniqueid = 13;
$DB->insert_record('quiz_attempts', $fakeattempt);
$fakeattempt->attempt = 2;
$fakeattempt->sumgrades = 50;
$fakeattempt->uniqueid = 26;
$DB->insert_record('quiz_attempts', $fakeattempt);
$fakeattempt->attempt = 4;
$fakeattempt->sumgrades = null;
$fakeattempt->uniqueid = 39;
$fakeattempt->state = quiz_attempt::IN_PROGRESS;
$DB->insert_record('quiz_attempts', $fakeattempt);
$fakeattempt->attempt = 1;
$fakeattempt->sumgrades = 30;
$fakeattempt->uniqueid = 52;
$fakeattempt->state = quiz_attempt::FINISHED;
$DB->insert_record('quiz_attempts', $fakeattempt);
$fakeattempt->attempt = 1;
$fakeattempt->userid = 1;
$fakeattempt->sumgrades = 100;
$fakeattempt->uniqueid = 65;
$DB->insert_record('quiz_attempts', $fakeattempt);
$quiz = new stdClass();
$quiz->attempts = 10;
$quiz->grademethod = QUIZ_ATTEMPTFIRST;
$firstattempt = $DB->get_records_sql("\n SELECT * FROM {quiz_attempts} quiza WHERE userid = ? AND quiz = ? AND " . quiz_report_qm_filter_select($quiz), array(123, 456));
$this->assertEquals(1, count($firstattempt));
$firstattempt = reset($firstattempt);
$this->assertEquals(1, $firstattempt->attempt);
$quiz->grademethod = QUIZ_ATTEMPTLAST;
$lastattempt = $DB->get_records_sql("\n SELECT * FROM {quiz_attempts} quiza WHERE userid = ? AND quiz = ? AND " . quiz_report_qm_filter_select($quiz), array(123, 456));
$this->assertEquals(1, count($lastattempt));
$lastattempt = reset($lastattempt);
$this->assertEquals(3, $lastattempt->attempt);
$quiz->attempts = 0;
$quiz->grademethod = QUIZ_GRADEHIGHEST;
$bestattempt = $DB->get_records_sql("\n SELECT * FROM {quiz_attempts} qa_alias WHERE userid = ? AND quiz = ? AND " . quiz_report_qm_filter_select($quiz, 'qa_alias'), array(123, 456));
$this->assertEquals(1, count($bestattempt));
$bestattempt = reset($bestattempt);
$this->assertEquals(2, $bestattempt->attempt);
}
示例6: test_report_sql
public function test_report_sql()
{
global $DB, $SITE;
$this->resetAfterTest(true);
$generator = $this->getDataGenerator();
$quizgenerator = $generator->get_plugin_generator('mod_quiz');
$quiz = $quizgenerator->create_instance(array('course' => $SITE->id, 'grademethod' => QUIZ_GRADEHIGHEST, 'grade' => 100.0, 'sumgrades' => 10.0, 'attempts' => 10));
$student1 = $generator->create_user();
$student2 = $generator->create_user();
$student3 = $generator->create_user();
$quizid = 123;
$timestamp = 1234567890;
// The test data.
$fields = array('quiz', 'userid', 'attempt', 'sumgrades', 'state');
$attempts = array(array($quiz->id, $student1->id, 1, 0.0, quiz_attempt::FINISHED), array($quiz->id, $student1->id, 2, 5.0, quiz_attempt::FINISHED), array($quiz->id, $student1->id, 3, 8.0, quiz_attempt::FINISHED), array($quiz->id, $student1->id, 4, null, quiz_attempt::ABANDONED), array($quiz->id, $student1->id, 5, null, quiz_attempt::IN_PROGRESS), array($quiz->id, $student2->id, 1, null, quiz_attempt::ABANDONED), array($quiz->id, $student2->id, 2, null, quiz_attempt::ABANDONED), array($quiz->id, $student2->id, 3, 7.0, quiz_attempt::FINISHED), array($quiz->id, $student2->id, 4, null, quiz_attempt::ABANDONED), array($quiz->id, $student2->id, 5, null, quiz_attempt::ABANDONED));
// Load it in to quiz attempts table.
$uniqueid = 1;
foreach ($attempts as $attempt) {
$data = array_combine($fields, $attempt);
$data['timestart'] = $timestamp + 3600 * $data['attempt'];
$data['timemodifed'] = $data['timestart'];
if ($data['state'] == quiz_attempt::FINISHED) {
$data['timefinish'] = $data['timestart'] + 600;
$data['timemodifed'] = $data['timefinish'];
}
$data['layout'] = '';
// Not used, but cannot be null.
$data['uniqueid'] = $uniqueid++;
$data['preview'] = 0;
$DB->insert_record('quiz_attempts', $data);
}
// Actually getting the SQL to run is quit hard. Do a minimal set up of
// some objects.
$context = context_module::instance($quiz->cmid);
$cm = get_coursemodule_from_id('quiz', $quiz->cmid);
$qmsubselect = quiz_report_qm_filter_select($quiz);
$reportstudents = array($student1->id, $student2->id, $student3->id);
// Set the options.
$reportoptions = new quiz_overview_options('overview', $quiz, $cm, null);
$reportoptions->attempts = quiz_attempts_report::ENROLLED_ALL;
$reportoptions->onlygraded = true;
$reportoptions->states = array(quiz_attempt::IN_PROGRESS, quiz_attempt::OVERDUE, quiz_attempt::FINISHED);
// Now do a minimal set-up of the table class.
$table = new quiz_overview_table($quiz, $context, $qmsubselect, $reportoptions, array(), $reportstudents, array(1), null);
$table->define_columns(array('attempt'));
$table->sortable(true, 'uniqueid');
$table->define_baseurl(new moodle_url('/mod/quiz/report.php'));
$table->setup();
// Run the query.
list($fields, $from, $where, $params) = $table->base_sql($reportstudents);
$table->set_sql($fields, $from, $where, $params);
$table->query_db(30, false);
// Verify what was returned: Student 1's best and in progress attempts.
// Stuent 2's finshed attempt, and Student 3 with no attempt.
// The array key is {student id}#{attempt number}.
$this->assertEquals(4, count($table->rawdata));
$this->assertArrayHasKey($student1->id . '#3', $table->rawdata);
$this->assertEquals(1, $table->rawdata[$student1->id . '#3']->gradedattempt);
$this->assertArrayHasKey($student1->id . '#3', $table->rawdata);
$this->assertEquals(0, $table->rawdata[$student1->id . '#5']->gradedattempt);
$this->assertArrayHasKey($student2->id . '#3', $table->rawdata);
$this->assertEquals(1, $table->rawdata[$student2->id . '#3']->gradedattempt);
$this->assertArrayHasKey($student3->id . '#0', $table->rawdata);
$this->assertEquals(0, $table->rawdata[$student3->id . '#0']->gradedattempt);
}
示例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: display
public function display($quiz, $cm, $course)
{
global $CFG, $COURSE, $DB, $PAGE, $OUTPUT;
$this->context = get_context_instance(CONTEXT_MODULE, $cm->id);
$download = optional_param('download', '', PARAM_ALPHA);
list($currentgroup, $students, $groupstudents, $allowed) = $this->load_relevant_students($cm);
$pageoptions = array();
$pageoptions['id'] = $cm->id;
$pageoptions['mode'] = 'responses';
$reporturl = new moodle_url('/mod/quiz/report.php', $pageoptions);
$qmsubselect = quiz_report_qm_filter_select($quiz);
$mform = new mod_quiz_report_responses_settings($reporturl, array('qmsubselect' => $qmsubselect, 'quiz' => $quiz, 'currentgroup' => $currentgroup, 'context' => $this->context));
if ($fromform = $mform->get_data()) {
$attemptsmode = $fromform->attemptsmode;
if ($qmsubselect) {
$qmfilter = $fromform->qmfilter;
} else {
$qmfilter = 0;
}
set_user_preference('quiz_report_responses_qtext', $fromform->qtext);
set_user_preference('quiz_report_responses_resp', $fromform->resp);
set_user_preference('quiz_report_responses_right', $fromform->right);
set_user_preference('quiz_report_pagesize', $fromform->pagesize);
$includeqtext = $fromform->qtext;
$includeresp = $fromform->resp;
$includeright = $fromform->right;
$pagesize = $fromform->pagesize;
} else {
$attemptsmode = optional_param('attemptsmode', null, PARAM_INT);
if ($qmsubselect) {
$qmfilter = optional_param('qmfilter', 0, PARAM_INT);
} else {
$qmfilter = 0;
}
$includeqtext = get_user_preferences('quiz_report_responses_qtext', 0);
$includeresp = get_user_preferences('quiz_report_responses_resp', 1);
$includeright = get_user_preferences('quiz_report_responses_right', 0);
$pagesize = get_user_preferences('quiz_report_pagesize', 0);
}
$this->validate_common_options($attemptsmode, $pagesize, $course, $currentgroup);
if (!$includeqtext && !$includeresp && !$includeright) {
$includeresp = 1;
set_user_preference('quiz_report_responses_resp', 1);
}
// 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', $this->context) && $attemptsmode != QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH_NO;
$displayoptions = array();
$displayoptions['attemptsmode'] = $attemptsmode;
$displayoptions['qmfilter'] = $qmfilter;
$displayoptions['qtext'] = $includeqtext;
$displayoptions['resp'] = $includeresp;
$displayoptions['right'] = $includeright;
$mform->set_data($displayoptions + array('pagesize' => $pagesize));
if ($attemptsmode == QUIZ_REPORT_ATTEMPTS_ALL) {
// This option is only available to users who can access all groups in
// groups mode, so setting allowed to empty (which means all quiz attempts
// are accessible, is not a security porblem.
$allowed = array();
}
$attemptids = optional_param_array('attemptid', array(), PARAM_INT);
if ($attemptids && confirm_sesskey()) {
require_capability('mod/quiz:deleteattempts', $this->context);
$this->delete_selected_attempts($quiz, $cm, $attemptids, $allowed);
redirect($reporturl->out(false, $displayoptions));
}
// Load the required questions.
$questions = quiz_report_get_significant_questions($quiz);
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
$courseshortname = format_string($course->shortname, true, array('context' => $coursecontext));
$displaycoursecontext = get_context_instance(CONTEXT_COURSE, $COURSE->id);
$displaycourseshortname = format_string($COURSE->shortname, true, array('context' => $displaycoursecontext));
$table = new quiz_report_responses_table($quiz, $this->context, $qmsubselect, $groupstudents, $students, $questions, $candelete, $reporturl, $displayoptions);
$filename = quiz_report_download_filename(get_string('responsesfilename', 'quiz_responses'), $courseshortname, $quiz->name);
$table->is_downloading($download, $filename, $displaycourseshortname . ' ' . format_string($quiz->name, true));
if ($table->is_downloading()) {
raise_memory_limit(MEMORY_EXTRA);
}
if (!$table->is_downloading()) {
// Only print headers if not asked to download data
$this->print_header_and_tabs($cm, $course, $quiz, 'responses');
}
if ($groupmode = groups_get_activity_groupmode($cm)) {
// Groups are being used
if (!$table->is_downloading()) {
groups_print_activity_menu($cm, $reporturl->out(true, $displayoptions));
}
}
// Print information on the number of existing attempts
if (!$table->is_downloading()) {
//do not print notices when downloading
if ($strattemptnum = quiz_num_attempt_summary($quiz, $cm, true, $currentgroup)) {
echo '<div class="quizattemptcounts">' . $strattemptnum . '</div>';
}
}
$hasquestions = quiz_questions_in_quiz($quiz->questions);
if (!$table->is_downloading()) {
if (!$hasquestions) {
echo quiz_no_questions_message($quiz, $cm, $this->context);
} else {
//.........这里部分代码省略.........
示例9: 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;
//.........这里部分代码省略.........
示例10: quiz_get_average_grade_for_questions
function quiz_get_average_grade_for_questions($quiz, $userids)
{
global $CFG, $DB;
$qmfilter = quiz_report_qm_filter_select($quiz);
list($usql, $params) = $DB->get_in_or_equal($userids);
$params[] = $quiz->id;
$questionavgssql = "SELECT qns.questionid, AVG(qs.grade) FROM\n {quiz_attempts} qa\n LEFT JOIN {question_sessions} qns ON (qns.attemptid = qa.uniqueid)\n LEFT JOIN {question_states} qs ON (qns.newgraded = qs.id AND qs.event IN (" . QUESTION_EVENTS_GRADED . "))\n WHERE " . ($qmfilter ? $qmfilter . ' AND ' : '') . "qa.userid {$usql} AND " . "qa.quiz = ? " . "GROUP BY qns.questionid";
return $DB->get_records_sql_menu($questionavgssql, $params);
}
示例11: load_average_question_grades
/**
* Load the average grade for each question, averaged over particular users.
* @param array $userids the user ids to average over.
*/
protected function load_average_question_grades($userids) {
global $DB;
$qmfilter = '';
if ($this->quiz->attempts != 1) {
$qmfilter = '(' . quiz_report_qm_filter_select($this->quiz, 'quiza') . ') AND ';
}
list($usql, $params) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED, 'u');
$params['quizid'] = $this->quiz->id;
$qubaids = new qubaid_join(
'{quiz_attempts} quiza',
'quiza.uniqueid',
"quiza.userid $usql AND quiza.quiz = :quizid",
$params);
$dm = new question_engine_data_mapper();
return $dm->load_average_marks($qubaids, array_keys($this->questions));
}
示例12: resolve_dependencies
/**
* Check the settings, and remove any 'impossible' combinations.
*/
public function resolve_dependencies() {
if ($this->group) {
// Default for when a group is selected.
if ($this->attempts === null || $this->attempts == quiz_attempts_report::ALL_ATTEMPTS) {
$this->attempts = quiz_attempts_report::STUDENTS_WITH;
}
} else if (!$this->group && $this->course->id == SITEID) {
// Force report on front page to show all, unless a group is selected.
$this->attempts = quiz_attempts_report::ALL_ATTEMPTS;
} else if ($this->attempts === null) {
$this->attempts = quiz_attempts_report::ALL_ATTEMPTS;
}
if ($this->pagesize < 1) {
$this->pagesize = quiz_attempts_report::DEFAULT_PAGE_SIZE;
}
if (!quiz_report_qm_filter_select($this->quiz)) {
// A grading mode like 'average' has been selected, so we cannot do
// the show the attempt that gave the final grade thing.
$this->onlygraded = false;
}
if ($this->attempts == quiz_attempts_report::STUDENTS_WITH_NO) {
$this->onlygraded = false;
}
}