Quiz

Custom fields for Quiz Report

 
 
Picture of Alison Wright
Custom fields for Quiz Report
 

Hi

Does anyone know how to output extra data into the Quiz reports (both onscreen and in Excel format) ?   I need the reports to output the users IDNumber as well as the date they successfully passed and completed the quiz.

I don't have any experience of PHP code - so this is proving rather difficult. Can anyone help me, please?

TIA

Ali

 
Average of ratings: -
Picture of Toshihiro KITA
Re: Custom fields for Quiz Report
 
Hello,
How about this quick hack as indicated below?

Attached is report.php to be replaced with your
mod/quiz/report/overview/report.php .
I hope this will work for you.

# I tested this with 1.5.3+.
# Exporting to an xls file does not seem to work, but I do not know why...


--- mod/quiz/report/overview/report.php.orig    2005-11-26 12:51:25.000000000 +0900
+++ mod/quiz/report/overview/report.php    2005-11-26 12:07:39.000000000 +0900
@@ -100,8 +100,8 @@
         }
 
     /// Define table columns
-        $tablecolumns = array('checkbox', 'picture', 'fullname', 'timestart', 'duration');
-        $tableheaders = array(NULL, '', get_string('fullname'), get_string('startedon', 'quiz'), get_string('attemptduration', 'quiz'));
+        $tablecolumns = array('checkbox', 'idnumber', 'picture', 'fullname', 'timestart', 'duration', 'timeend'); // t-kita 2005-11-26
+        $tableheaders = array(NULL, 'ID', '', get_string('fullname'), get_string('startedon', 'quiz'), get_string('attemptduration', 'quiz'), 'Ended on'); // t-kita 2005-11-26
 
         if ($quiz->grade) {
             $tablecolumns[] = 'sumgrades';
@@ -198,7 +198,7 @@
             $formatg->set_align('center');
             // Here starts workshhet headers
 
-            $headers = array(get_string('fullname'), get_string('startedon', 'quiz'), get_string('attemptduration', 'quiz'));
+            $headers = array('ID', get_string('fullname'), get_string('startedon', 'quiz'), get_string('attemptduration', 'quiz'), 'Ended on');  // t-kita 2005-11-26
 
             if ($quiz->grade) {
                 $headers[] = get_string('grade', 'quiz').'/'.$quiz->grade;
@@ -223,7 +223,7 @@
             header("Cache-Control: must-revalidate,post-check=0,pre-check=0");
             header("Pragma: public");
 
-            $headers = get_string('fullname')."\t".get_string('startedon', 'quiz')."\t".get_string('attemptduration', 'quiz');
+            $headers = 'ID'."\t".get_string('fullname')."\t".get_string('startedon', 'quiz')."\t".get_string('attemptduration', 'quiz')."\t".'Ended on'; // t-kita 2005-11-26
 
             if ($quiz->grade) {
                 $headers .= "\t".get_string('grade', 'quiz')."/".$quiz->grade;
@@ -355,22 +355,29 @@
                     $userlink = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$attempt->userid.'&amp;course='.$course->id.'">'.fullname($attempt).'</a>';
                 //}
                 if (!$download) {
+                    // t-kita 2005-11-26  some items added
                     $row = array(
                               '<input type="checkbox" name="attemptid[]" value="'.$attempt->attempt.'" />',
+                              $attempt->userid,
                               $picture,
                               $userlink,
                               empty($attempt->attempt) ? '-' : '<a href="review.php?q='.$quiz->id.'&amp;attempt='.$attempt->attempt.'">'.userdate($attempt->timestart, $strtimeformat).'</a>',
                               empty($attempt->attempt) ? '-' :
                                (empty($attempt->timefinish) ? get_string('unfinished', 'quiz') :
-                                format_time($attempt->duration))
+                                format_time($attempt->duration)),
+                              (empty($attempt->timefinish) ? get_string('unfinished', 'quiz') :
+                               userdate($attempt->timefinish, $strtimeformat))
                            );
                 }
                 else {
-                    $row = array(fullname($attempt),
+                    // t-kita 2005-11-26  some items added
+                    $row = array( $attempt->userid, fullname($attempt),
                                empty($attempt->attempt) ? '-' : userdate($attempt->timestart, $strtimeformat),
                                empty($attempt->attempt) ? '-' :
                                (empty($attempt->timefinish) ? get_string('unfinished', 'quiz') :
-                               format_time($attempt->duration))
+                               format_time($attempt->duration)),
+                              (empty($attempt->timefinish) ? get_string('unfinished', 'quiz') :
+                               userdate($attempt->timefinish, $strtimeformat))
                            );
                 }
 

 
Average of ratings: -
Picture of Alison Wright
Re: Custom fields for Quiz Report
 

Thanks ever so much.

All works great - thank you big grin

 
Average of ratings: -
Picture of Vishal Upadhayay
Re: Custom fields for Quiz Report
 

What this report.php file do??

How it will b helpfull in generating custom quiz report??

 
Average of ratings: -
Picture of Toshihiro KITA
Re: Custom fields for Quiz Report
 
The patch above is not good for the current version of Moodle 1.9.

The attached report.php is for Moodle 1.9.14 .
It displays additional columns of 'city'  and 'country' of each user on the quiz report.

# BTW, idnumber column is now available if you just set the configuration so, without any patch.


--- report.php.orig 2012-01-23 20:07:33.000000000 +0900
+++ report.php 2012-01-23 20:26:23.000000000 +0900
@@ -191,6 +191,12 @@
                $headers[]= get_string('idnumber');
            }

+            $columns[]= 'city';
+            $headers[]= get_string('city');
+
+            $columns[]= 'country';
+            $headers[]= get_string('country');
+
            $columns[]= 'timestart';
            $headers[]= get_string('startedon', 'quiz');

@@ -236,6 +242,8 @@
                $table->column_suppress('picture');
                $table->column_suppress('fullname');
                $table->column_suppress('idnumber');
+ //                $table->column_suppress('city');
+ //                $table->column_suppress('country');

                $table->no_sorting('feedbacktext');

@@ -358,6 +366,8 @@
                    u.picture,
                    u.imagealt,
                    u.email,
+                    u.city,
+                    u.country,
                    qa.sumgrades,
                    qa.timefinish,
                    qa.timestart,
@@ -497,6 +507,8 @@
                    if (in_array('idnumber', $columns)) {
                        $row[] = $attempt->idnumber;
                    }
+                    $row[] = $attempt->city;
+                    $row[] = $attempt->country;

                    // Timing columns.
                    if ($attempt->attempt) {
 
Average of ratings: -
Picture of Toshihiro KITA
Re: Custom fields for Quiz Report
 
i got a question by a direct message:

I saw your quick hack here https://moodle.org/mod/forum/discuss.php?d=35127
about adding custom fields to quiz reports.
May I humbly ask you to update it for 2.3 version which I am using atm, as well
as explaining to me how to show custom field (the one I have created for each
student, namely "License number" short name "License" created under "User
profile fields"). Or at least point me where to search for that.
Any help would be much appreciated
 
Average of ratings: -
Picture of Toshihiro KITA
Re: Custom fields for Quiz Report
 
... and my answer is:

For Moodle 2.3 it is straightforward to include some of the user profile fields within Gradebook, Quiz Report, etc.
You can select which to be included by 'Show user identity' setting (as the image attached below) at the page of
Site administration ► Users ► Permissions ► User policies

So my suggestion is to use one of the unused fileds (such as Institution) for 'License number'.
it is easy (no code hacking is needed) and permanent also for upgraded versions of Moodle.

# For Moodle 2.5, it is possible include custom fields within the gradebook export file by specifying at
# 'Grade export custom profile fields' on the page of
# Site administration ► Grades ► General settings

 
Average of ratings:Useful (1)
Picture of Slobodan Gogic
Re: Custom fields for Quiz Report
 

Since I am the one who has asked for this update, I would like to thank Mr. Toshihiro for reply.

Also I would like to post MySQL update query in case you have lots of students to be updated. In our case we had to update about 500 database entries.

We updated Insitution field

Anyway query for that would be

UPDATE mdl_user x SET x.institution = (SELECT data FROM mdl_user_info_data y WHERE y.userid = x.id AND fieldid = 1)

 

Thanks for help

 
Average of ratings: -