From 4469159e2df8dc58a0c2f6afe8263cff70888524 Mon Sep 17 00:00:00 2001 From: jamiesensei Date: Tue, 6 May 2008 17:34:39 +0000 Subject: [PATCH] For the overview report : MDL-14199 "Option to only show / export final grade" and MDL-14198 "Make it clear which student attempt gives the final grade, if the scoring method is first, last or highest score" --- lang/en_utf8/quiz_overview.php | 11 +- .../report/overview/overviewsettings_form.php | 18 +- mod/quiz/report/overview/report.php | 241 ++++++++++-------- mod/quiz/report/reportlib.php | 34 +++ 4 files changed, 182 insertions(+), 122 deletions(-) diff --git a/lang/en_utf8/quiz_overview.php b/lang/en_utf8/quiz_overview.php index 5cf63421d9..e4388caacf 100644 --- a/lang/en_utf8/quiz_overview.php +++ b/lang/en_utf8/quiz_overview.php @@ -5,15 +5,20 @@ $string['allattempts'] = 'Show all attempts'; $string['allstudents'] = 'Show all $a'; $string['attemptsonly'] = 'Show $a with attempts only'; +$string['attemptsprepage'] = 'Attempts shown per page'; $string['noattemptsonly'] = 'Show $a with no attempts only'; $string['optallattempts'] = 'all attempts'; -$string['optallstudents'] = 'all $a'; -$string['optattemptsonly'] = '$a with attempts only'; -$string['optnoattemptsonly'] = '$a with no attempts only'; +$string['optallstudents'] = 'all \'$a\''; +$string['optattemptsonly'] = '\'$a\' with attempts only'; +$string['optnoattemptsonly'] = '\'$a\' with no attempts only'; +$string['optonlygradedattempts'] = 'only the attempt that is graded for each user'; $string['overview'] = 'Overview'; $string['overviewdownload'] = 'Overview download'; +$string['overviewdownload'] = 'Overview download'; +$string['pagesize'] = 'Page size'; $string['preferencespage'] = 'Preferences just for this page'; $string['preferencessave'] = 'Save preferences'; $string['preferencesuser'] = 'Your preferences for this report'; $string['show'] = 'Show'; +$string['showdetailedmarks'] = 'Show marks for each question'; ?> diff --git a/mod/quiz/report/overview/overviewsettings_form.php b/mod/quiz/report/overview/overviewsettings_form.php index 4c41abe88b..8feba688db 100644 --- a/mod/quiz/report/overview/overviewsettings_form.php +++ b/mod/quiz/report/overview/overviewsettings_form.php @@ -8,21 +8,25 @@ class mod_quiz_report_overview_settings extends moodleform { //------------------------------------------------------------------------------- $mform->addElement('header', 'general', get_string('preferencespage', 'quiz_overview')); - $options = array(0 => get_string('attemptsonly','quiz_overview', $COURSE->students)); + $options = array(); + $options[QUIZ_REPORT_ATTEMPTS_ALL] = get_string('optallattempts','quiz_overview'); if ($COURSE->id != SITEID) { - $options[1] = get_string('noattemptsonly', 'quiz_overview', $COURSE->students); - $options[2] = get_string('allstudents','quiz_overview', $COURSE->students); - $options[3] = get_string('allattempts','quiz_overview'); + $options[QUIZ_REPORT_ATTEMPTS_ALL_STUDENTS] = get_string('optallstudents','quiz_overview', $COURSE->students); + $options[QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH] = + get_string('optattemptsonly','quiz_overview', $COURSE->students); + $options[QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH_NO] = get_string('optnoattemptsonly', 'quiz_overview', $COURSE->students); } $mform->addElement('select', 'attemptsmode', get_string('show', 'quiz_overview'), $options); - + if ($this->_customdata['qmsubselect']){ + $mform->addElement('advcheckbox', 'qmfilter', get_string('show', 'quiz_overview'), get_string('optonlygradedattempts', 'quiz_overview'), array(0,1)); + } //------------------------------------------------------------------------------- $mform->addElement('header', 'general', get_string('preferencesuser', 'quiz_overview')); - $mform->addElement('text', 'pagesize', get_string('pagesize', 'quiz')); + $mform->addElement('text', 'pagesize', get_string('pagesize', 'quiz_overview')); $mform->setType('pagesize', PARAM_INT); - $mform->addElement('selectyesno', 'detailedmarks', get_string('showdetailedmarks', 'quiz')); + $mform->addElement('selectyesno', 'detailedmarks', get_string('showdetailedmarks', 'quiz_overview')); $this->add_action_buttons(false, get_string('preferencessave', 'quiz_overview')); } diff --git a/mod/quiz/report/overview/report.php b/mod/quiz/report/overview/report.php index 3a9b1d37eb..188530c380 100644 --- a/mod/quiz/report/overview/report.php +++ b/mod/quiz/report/overview/report.php @@ -74,15 +74,25 @@ class quiz_report extends quiz_default_report { $pageoptions['mode'] = 'overview'; $reporturl = new moodle_url($CFG->wwwroot.'/mod/quiz/report.php', $pageoptions); - $mform = new mod_quiz_report_overview_settings($reporturl); + $qmsubselect = quiz_report_qm_filter_subselect($quiz->grademethod); + $mform = new mod_quiz_report_overview_settings($reporturl, compact('qmsubselect')); 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 { - $attemptsmode = optional_param('attemptsmode', 0, PARAM_INT); + $qmfilter = optional_param('qmfilter', 0, PARAM_INT); + $attemptsmode = optional_param('attemptsmode', QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH, PARAM_INT); $detailedmarks = get_user_preferences('quiz_report_overview_detailedmarks', 1); $pagesize = get_user_preferences('quiz_report_pagesize', 0); } @@ -92,6 +102,7 @@ class quiz_report extends quiz_default_report { $displayoptions = array(); $displayoptions['attemptsmode'] = $attemptsmode; + $displayoptions['qmfilter'] = $qmfilter; $reporturlwithdisplayoptions = new moodle_url($CFG->wwwroot.'/mod/quiz/report.php', $pageoptions + $displayoptions); /// find out current groups mode @@ -302,7 +313,7 @@ class quiz_report extends quiz_default_report { // Get users with quiz attempt capability 'students'. // don't need to do this expensive call if we are listing all attempts though. - if ( $attemptsmode != 3 ) { + if ( $attemptsmode != QUIZ_REPORT_ATTEMPTS_ALL ) { if (empty($currentgroup)) { // all users who can attempt quizzes $allowed = join(',',array_keys(get_users_by_capability($context, 'mod/quiz:attempt','','','','','','',false))); @@ -315,27 +326,33 @@ class quiz_report extends quiz_default_report { // Construct the SQL $select = 'SELECT '.sql_concat('u.id', '\'#\'', $db->IfNull('qa.attempt', '0')).' AS uniqueid, '. + ($qmsubselect?$qmsubselect.' AS gradedattempt, ':''). 'qa.uniqueid AS attemptuniqueid, qa.id AS attempt, u.id AS userid, u.firstname, u.lastname, u.picture, '. 'qa.sumgrades, qa.timefinish, qa.timestart, qa.timefinish - qa.timestart AS duration '; // This part is the same for all cases - join users and quiz_attempts tables $from = 'FROM '.$CFG->prefix.'user u '; $from .= 'LEFT JOIN '.$CFG->prefix.'quiz_attempts qa ON qa.userid = u.id AND qa.quiz = '.$quiz->id; - - if ( $attemptsmode == 3 ) { // Show all attempts, including students who are no longer in the course - - $where = ' WHERE qa.id IS NOT NULL'; - // Comment out the following line to include preview attempts in the 'show all attempts' filter - $where .= ' AND qa.preview = 0'; - } else { // All non-admin users with quiz attempt capabilites - e.g. students - - $where = ' WHERE u.id IN (' .$allowed. ') AND (qa.preview = 0 OR qa.preview IS NULL)'; - - if ( empty( $attemptsmode )) { // Show only students with attempts - $where .= ' AND qa.id IS NOT NULL'; - } else if ( $attemptsmode == 1 ) { // Show only students without attempts - $where .= ' AND qa.id IS NULL'; - } + if ($qmsubselect && $qmfilter){ + $from .= ' AND '.$qmsubselect; + } + switch ($attemptsmode){ + case QUIZ_REPORT_ATTEMPTS_ALL: + // Show all attempts, including students who are no longer in the course + $where = ' WHERE qa.id IS NOT NULL AND qa.preview = 0'; + break; + case QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH: + // Show only students with attempts + $where = ' WHERE u.id IN (' .$allowed. ') AND qa.preview = 0 AND qa.id IS NOT NULL'; + break; + case QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH_NO: + // Show only students without attempts + $where = ' WHERE u.id IN (' .$allowed. ') AND qa.id IS NULL'; + break; + case QUIZ_REPORT_ATTEMPTS_ALL_STUDENTS: + // Show all students with or without attempts + $where = ' WHERE u.id IN (' .$allowed. ') AND (qa.preview = 0 OR qa.preview IS NULL)'; + break; } $countsql = 'SELECT COUNT(DISTINCT('.sql_concat('u.id', '\'#\'', $db->IfNull('qa.attempt', '0')).')) '.$from.$where; @@ -408,129 +425,130 @@ class quiz_report extends quiz_default_report { } else { $attempts = array(); } - // Build table rows if (!$download) { $table->initialbars($totalinitials>20); } - if(!empty($attempts) || !empty($attemptsmode)) { - if ($attempts) { - if($detailedmarks) { - //get all the attempt ids we want to display on this page - //or to export for download. - $attemptids = array(); - foreach ($attempts as $attempt){ - if ($attempt->attemptuniqueid > 0){ - $attemptids[] = $attempt->attemptuniqueid; - } + if ($attempts) { + if($detailedmarks) { + //get all the attempt ids we want to display on this page + //or to export for download. + $attemptids = array(); + foreach ($attempts as $attempt){ + if ($attempt->attemptuniqueid > 0){ + $attemptids[] = $attempt->attemptuniqueid; } - $gradedstatesbyattempt = quiz_get_newgraded_states($attemptids); } - foreach ($attempts as $attempt) { - $picture = print_user_picture($attempt->userid, $course->id, $attempt->picture, false, true); + $gradedstatesbyattempt = quiz_get_newgraded_states($attemptids); + } + foreach ($attempts as $attempt) { + $picture = print_user_picture($attempt->userid, $course->id, $attempt->picture, false, true); - $userlink = ''.fullname($attempt).''; + $userlink = ''.fullname($attempt).''; - // Username columns. - $row = array(); + // Username columns. + $row = array(); + if (!$download) { + if (!empty($attemptactions)) { + $row[] = ''; + } + $row[] = $picture; + $row[] = $userlink; + } else { + $row[] = fullname($attempt); + } + + // Timing columns. + if ($attempt->attempt) { + $startdate = userdate($attempt->timestart, $strtimeformat); if (!$download) { - if (!empty($attemptactions)) { - $row[] = ''; - } - $row[] = $picture; - $row[] = $userlink; + $row[] = ''.$startdate.''; } else { - $row[] = fullname($attempt); + $row[] = $startdate; } - - // Timing columns. - if ($attempt->attempt) { - $startdate = userdate($attempt->timestart, $strtimeformat); + if ($attempt->timefinish) { + $timefinish = userdate($attempt->timefinish, $strtimeformat); + $duration = format_time($attempt->duration); if (!$download) { - $row[] = ''.$startdate.''; + $row[] = ''.$timefinish.''; } else { - $row[] = $startdate; - } - if ($attempt->timefinish) { - $timefinish = userdate($attempt->timefinish, $strtimeformat); - $duration = format_time($attempt->duration); - if (!$download) { - $row[] = ''.$timefinish.''; - } else { - $row[] = $timefinish; - } - $row[] = $duration; - } else { - $row[] = '-'; - $row[] = get_string('unfinished', 'quiz'); + $row[] = $timefinish; } + $row[] = $duration; } else { $row[] = '-'; - $row[] = '-'; - $row[] = '-'; + $row[] = get_string('unfinished', 'quiz'); } + } else { + $row[] = '-'; + $row[] = '-'; + $row[] = '-'; + } - // Grades columns. - if ($showgrades) { - if ($attempt->timefinish) { - $grade = quiz_rescale_grade($attempt->sumgrades, $quiz); - if (!$download) { - $row[] = ''.$grade.''; - } else { - $row[] = $grade; + // Grades columns. + if ($showgrades) { + if ($attempt->timefinish) { + $grade = quiz_rescale_grade($attempt->sumgrades, $quiz); + if (!$download) { + $gradehtml = ''.$grade.''; + if ($qmsubselect && $attempt->gradedattempt){ + $gradehtml = '
'.$gradehtml.'
'; } + $row[] = $gradehtml; } else { - $row[] = '-'; + $row[] = $grade; } + } else { + $row[] = '-'; } + } - if($detailedmarks) { - if(empty($attempt->attempt)) { - foreach($questions as $question) { - $row[] = '-'; + if($detailedmarks) { + if(empty($attempt->attempt)) { + foreach($questions as $question) { + $row[] = '-'; + } + } else { + foreach($questions as $questionid => $question) { + $stateforqinattempt = $gradedstatesbyattempt[$attempt->attemptuniqueid][$questionid]; + if (question_state_is_graded($stateforqinattempt)) { + $grade = quiz_rescale_grade($stateforqinattempt->grade, $quiz); + } else { + $grade = '--'; } - } else { - foreach($questions as $questionid => $question) { - $stateforqinattempt = $gradedstatesbyattempt[$attempt->attemptuniqueid][$questionid]; - if (question_state_is_graded($stateforqinattempt)) { - $grade = quiz_rescale_grade($stateforqinattempt->grade, $quiz); - } else { - $grade = '--'; - } - if (!$download) { - $grade = $grade.'/'.quiz_rescale_grade($question->grade, $quiz); - $row[] = link_to_popup_window('/mod/quiz/reviewquestion.php?state='. - $stateforqinattempt->id.'&number='.$question->number, - 'reviewquestion', $grade, 450, 650, $strreviewquestion, 'none', true); - } else { - $row[] = $grade; - } + if (!$download) { + $grade = $grade.'/'.quiz_rescale_grade($question->grade, $quiz); + $row[] = link_to_popup_window('/mod/quiz/reviewquestion.php?state='. + $stateforqinattempt->id.'&number='.$question->number, + 'reviewquestion', $grade, 450, 650, $strreviewquestion, 'none', true); + } else { + $row[] = $grade; } } } + } - // Feedback column. - if ($hasfeedback) { - if ($attempt->timefinish) { - $row[] = format_text($attempt->feedbacktext, FORMAT_MOODLE, $nocleanformatoptions); - } else { - $row[] = '-'; - } + // Feedback column. + if ($hasfeedback) { + if ($attempt->timefinish) { + $row[] = format_text($attempt->feedbacktext, FORMAT_MOODLE, $nocleanformatoptions); + } else { + $row[] = '-'; } - if (!$download) { - $table->add_data($row); - } else if ($download == 'Excel' or $download == 'ODS') { - $colnum = 0; - foreach($row as $item){ - $myxls->write($rownum,$colnum,$item,$format); - $colnum++; - } - $rownum++; - } else if ($download=='CSV') { - $text = implode("\t", $row); - echo $text." \n"; + } + if (!$download) { + $table->add_data($row); + } else if ($download == 'Excel' or $download == 'ODS') { + $colnum = 0; + foreach($row as $item){ + $myxls->write($rownum,$colnum,$item,$format); + $colnum++; } + $rownum++; + } else if ($download=='CSV') { + $text = implode("\t", $row); + echo $text." \n"; } } if (!$download) { @@ -595,7 +613,6 @@ document.getElementById("noscriptmenuaction").style.display = "none"; } else if ($download == 'CSV') { exit; } - } else { if (!$download) { $table->print_html(); diff --git a/mod/quiz/report/reportlib.php b/mod/quiz/report/reportlib.php index 0ae7109b8f..ca0f9a14ed 100644 --- a/mod/quiz/report/reportlib.php +++ b/mod/quiz/report/reportlib.php @@ -1,5 +1,10 @@ prefix}quiz_attempts WHERE u.id = userid ORDER BY $qmorderby LIMIT 1)=qa.id"; + } else { + $qmsubselect = ''; + } + return $qmsubselect; +} ?> \ No newline at end of file -- 2.39.5