adding another column to the gradebook..

adding another column to the gradebook..

by Miki Alliel -
Number of replies: 17
Picture of Translators

I was surprised that there is no way to set any or other column in the results table in a quiz and also in the grade book. We see there are only Private name, Family Name and other quiz data but we do need for example idnumber otherwise how can we distinguish between two users with the same name and family name. it's really weird.

maybe I miss something, anyway..we need to add a new column the idnumber (of a student) to the quiz results table and to the gradebook. when we will see it, it will help us to export to Excel file which is really important to us to work other  applications that we have for example the grading applications of our collage and so on..

hope there is a code explanation where and how to do it? alternatively will it be exist in the next versions of Moodle 1.9 or 2? 

p.s - we run 1.8.2.

I really appreciate any help.

Thanks

In reply to Miki Alliel

Re: adding another column to the gradebook..

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
This is kind-of a known problem. It would be nice to come up with a proper solution one day, but for now you just have to tweak the code. For example with the quiz results report /mod/quiz/report/overview/report.php

In the SQL around line 310 you need to add the bit in bold:
 // Construct the SQL
 $select = 'SELECT '.sql_concat('u.id', '\'#\'', $db->IfNull('qa.attempt', '0')).' AS uniqueid, '.
 'qa.uniqueid as attemptuniqueid, qa.id AS attempt, u.id AS userid, u.idnumber, u.firstname, u.lastname, u.picture, '.
 'qa.sumgrades, qa.timefinish, qa.timestart, qa.timefinish - qa.timestart AS duration ';
Then later where it creates the table, you need to output the idnumber, so line 443, add:
 $userlink = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$attempt->userid.'&amp;course='.$course->id.'">'.fullname($attempt).' ('.$attempt->idnumber.')'.'</a>';

and line 455:

 $row = array(fullname($attempt).' ('.$attempt->idnumber.')',

That simply puts the idnumber in brackets after the name. If you actually want to add it as a separate, sortable column, that is only slightly harder. I'll let you work that out on your own.

Most tables in Moodle are produced in a similar way, so once you have done one, it is quite easy to do more.
In reply to Tim Hunt

תשובה ל: Re: adding another column to the gradebook..

by Miki Alliel -
Picture of Translators

Hey thanks for replying

Well we do actually want to add it as a separate, sortable column in this result table so we can get this field separated from the private name and family name.

for us it is important so when we export it to Excel file it helps us with other applications.

also without that how can you distinguish between two users with the same private and family name. what do you do then?

I really hope you can let me know how do I add this separate column to be idnumber in this results table.

thanks!

In reply to Miki Alliel

Re: תשובה ל: Re: adding another column to the gradebook..

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
What level of PHP ability do you have?

Anyway, I would suggest making the changes I suggest above, just as a practice to make sure it works, before trying the more complicated changes.
In reply to Tim Hunt

תשובה ל: Re: תשובה ל: Re: adding another column to the gradebook..

by Miki Alliel -
Picture of Translators

Yes I did try the 1st post that you describes and it worked.

But again this is not what we need, we do need as I said - this separate column , I do know php -at least the basic. if you would point me and let me know how to do it I'll get along.

Thanks really appreciate the help.. hope you can help.

In reply to Miki Alliel

Re: תשובה ל: Re: תשובה ל: Re: adding another column to the gradebook..

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
You will see that the code is building up a big object/array called $table. First it sets up the column headings, and some options like how they are aligned. Then it adds the data one row at a time - each row is an array.

To add a new column, you need to change the bit where it adds the header, and the bit where it adds the data to each row.

Annoyingly, there are often several different branches of an if-statement to modify, because it does slightly different things when exporting to a file and displaying on-screen.
In reply to Tim Hunt

תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: adding another column to the gradebook..

by Miki Alliel -
Picture of Translators

Hi

you said:

"To add a new column, you need to change the bit where it adds the header, and the bit where it adds the data to each row.
"

Can you be more spesific about where is it in the code? lines? is it the same file?

Which one is it if not?

thanks

In reply to Miki Alliel

Re: adding another column to the gradebook..

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
If I had the time, I would have been, but sorry, there is just too much else on my todo list.

Just try it. It is not that hard.
In reply to Miki Alliel

Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: adding another column to the gradebook..

by Jit San Chia -

Hi,

yes it's the same file.

for the header bit, look around line 110 where it says "$tablecolumns = array..."

add 'idnumber' to the end of the array

then the next line "$tableheaders = array..."

add get_string('idnumber') to the end of the array

for the row bit, look around line 445 where it says "if (!download) {$row = array..."

add $attempt->idnumber to the end of that array

That should be all for displaying that extra column on-screen. You may wish to change the position of the column accordingly once you understand how it works.

For the downloads, there are 3 options, so you need to add 3 get_string('idnumber') to the end of 3 $headers (one for ODS, one for Excel, one for CSV, they are at around line 208, 260 and 288 respectively)

Then look around line 456 "} else { $row = array..."

add $attempt->idnumber to the end of the array

Hope that helps

In reply to Jit San Chia

תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: adding another column to the gradebook..

by Miki Alliel -
Picture of Translators

hii

I rtied to do it

I'm stack where you said

"

for the row bit, look around line 445 where it says "if (!download) {$row = array..."

add $attempt->idnumber to the end of that array"

I see there in the code :

 $row = array(
                                '<input type="checkbox" name="attemptid[]" value="'.$attempt->attempt.'" />',
                                $picture,
                                $userlink,
                                empty($attempt->attempt) ? '-' : '<a href="review.php?q='.$quiz->id.'&amp;attempt='.$attempt->attempt.'">'.userdate($attempt->timestart, $strtimeformat).'</a>',
                                empty($attempt->timefinish) ? '-' : '<a href="review.php?q='.$quiz->id.'&amp;attempt='.$attempt->attempt.'">'.userdate($attempt->timefinish, $strtimeformat).'</a>',
                                empty($attempt->attempt) ? '-' : (empty($attempt->timefinish) ? get_string('unfinished', 'quiz') : format_time($attempt->duration)).'</a>',

where do I put it exactly? does it have to be inside the empty function

please let me know how to do it

thanks

In reply to Miki Alliel

Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: adding another column to the gradebook..

by Jit San Chia -

Hi,

The comma(,) at the end of the chunk of code you copied indicates that you haven't come to the end of the array yet. What's after that line? Try to read line by line down from there until you see the line that contains only ");" (without quotes) That's the end of the array. Put $attempt->idnumber just before that close bracket.

In reply to Jit San Chia

תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: adding another column to the gradebook..

by Miki Alliel -
Picture of Translators

I tried it  and figured out how

Unfortunately when I go to the grade attempts table I get white screen

In reply to Miki Alliel

Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: adding another column to the gradebook..

by Jit San Chia -
that's probably caused by syntax error in your php. did you add a comma to the previously last item in the array before you put $attempt->idnumber ?

In reply to Jit San Chia

תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: adding another column to the gradebook..

by Miki Alliel -
Picture of Translators

this is the code after editing it as you told me:

"

      } else {
                        $row = array(fullname($attempt),
                                empty($attempt->attempt) ? '-' : userdate($attempt->timestart, $strtimeformat),
                                empty($attempt->timefinish) ? '-' : userdate($attempt->timefinish, $strtimeformat),
                                empty($attempt->attempt) ? '-' : (empty($attempt->timefinish) ? get_string('unfinished', 'quiz') : format_time($attempt->duration),$attempt->idnumber)
                        );
                    }

"

It's not working I get the  a white screen.

In reply to Miki Alliel

Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: adding another column to the gradebook..

by Jit San Chia -
try removing the close bracket immediately after $attempt->idnumber
In reply to Jit San Chia

תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: adding another column to the gradebook..

by Miki Alliel -
Picture of Translators

Jit & Tim thanks a lot for your help

now it is working and also within the Excel file

One thing still left which I had asked in other topic and didn't get a solution.

when I'm downloading the Excel file for the outcomes of the quiz I get Gibberish as you see in the picture here

and when I'm switching to English Package the file seems to be OK .

I need the same outcome of file when I'm in the Hebrew Package which is the default one.

otherwise every teacher would change it to English pack and will go all the way to the quiz just to download this Excel file.

Does some one know why do we get it like that when we are in the Hebrew package:

Attachment ExcelFileHebMoodleGibrish.JPG
In reply to Miki Alliel

תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: adding another column to the gradebook..

by Miki Alliel -
Picture of Translators

this pic is after we download the Excel file from the English package

which is fine

Attachment Excel_english_fine.JPG
In reply to Tim Hunt

Re: adding "attemps" column to the grades - view - user report

by Buddy King -

Hi!

Is there a way to add "attempts" column, like the one on the quiz page, in the grades user report.  I am using moodle 1.9.5. Please, help.

Thank you.

Buddy