Custom user profile fields in Grader Report

Custom user profile fields in Grader Report

napisao/la Cyril Teo -
Broj odgovora: 10
I have a custom user profile field called CLASS, which basically states the class of the student. I added this extra field in USERS > ACCOUNTS > USER PROFILE FIELDS.

I need this additional field to be shown in the Grader Report to show which class the student is from. Without this, the teacher will have a difficult time associating the student to the classes that they are from. (Because we have different teachers for different classes).

How do I do this? Any help is much appreciated! Thanks!
U odgovoru na Cyril Teo

Re: Custom user profile fields in Grader Report

napisao/la Anthony Borrow -
Slika Core developers Slika Plugin developers Slika Testers
Cyril - Can you send me a screenshot or a description of exactly where you would like this field to be displayed? A screenshot will give me the URL that you are looking at as well as help me to write a patch for you that you can apply to include the custom user profile field 'Class' in the report. Peace - Anthony
U odgovoru na Anthony Borrow

Re: Custom user profile fields in Grader Report

napisao/la Paul Ganderton -
Anthony,

I assume that Cyril is asking for an addition to the standard Moodle? In this case might I ask for this also? I use year-groups for Moodle but this can be up to 7 classes. It would be helpful to find out who is where. Thanks.
U odgovoru na Paul Ganderton

Re: Custom user profile fields in Grader Report

napisao/la Anthony Borrow -
Slika Core developers Slika Plugin developers Slika Testers
Paul - I am happy to give you and Cyril a hand; however, I am a very visual person and want to make sure that we are talking about the same thing. Would it be possible for either of you to provide a screenshot (one that shows the URL) of the page you want edited and where you would like the class information to appear? You may have different ideas about where you want the information displayed. Peace - Anthony
U odgovoru na Anthony Borrow

Re: Custom user profile fields in Grader Report

napisao/la phil walley -

Hi Cyril, Anthony and Paul - I've been working on this myself, but I have minimal PHP skills, so it is a long and difficult task for me.

Users on my Moodle have a GroupID attached to them which is a custom profile field and I need this displayed in the gradebook. This I have managed to do, but I really need to be able to sort by GroupID as well (in the same way that I can sort by Firstname or Surname).

Anthony, I have attached a screenshot to help you visualize. Sorry it couldn't be bigger I only just got this in due to the upload limit of 100KB. The GroupID is displayed next to the users name in black (eg UK - Sales 2). It seems to me that Paul and Cyril are looking for the same thing. I will keep working on this and if I find a solution I will let you guys know, but any help would be appreciated.

Thanks

U odgovoru na Anthony Borrow

Re: Custom user profile fields in Grader Report

napisao/la Cyril Teo -
Hi Anthony,

Attached is the visual of what I'm trying to achieve. Basically, our students has an additional field called "CLASS". For example, if they are in Year 8, then we have two classes from Year 8, which is Y8A and Y8B. This additional field was created in the USERS>ACCOUNTS>USER PROFILE FIELDS.

I need the class details to also appear in the grader report as shown in the attachment. (Screenshot was edited with Photoshop to include that CLASS field). The field should also be sortable.

Is this possible?

Any help will be GREATLY appreciated. Teachers of the different classes has difficulty differentiating their students without that class field in the report.

Regards,
Cyril
Prilog MOODLE_Grader_Report_2.jpg
U odgovoru na Cyril Teo

Re: Custom user profile fields in Grader Report

napisao/la phil walley -

I think I'm close, however, my SQL and/or PHP skills are letting me down. Maybe one of you guys has more ability in this area. BTW I will refer to some files, so you should know that I am using Moodle 1.9.2 (in case the path names differ)

Cyril, I originally wanted exactly what you have in your diagram. After a little research I settled for the following.

1. I don't create a new column (when I got into the php files I realised that would be very difficult). Instead I simply display my custom field next to the student name.

2. I decided that a sort on Firstname is not really useful/needed, so I intend to replace this with a sort on my custom field. Again this way I don't really add any code or mess with the table too much. I simply tweak what is already there.

To achieve the first part I did the following. In the file grade/report/grader/lib.php I edited some code:

BEGIN CODE

$user_pic = '<div class="userpic">' . print_user_picture($user, $this->courseid, NULL, 0, true) . '</div>';

}

//change 1

//displays grouID next to name in Gradebook

$groupID = "SELECT data FROM mdl_user_info_data WHERE userid='$user->id'";

$groupIDget = mysql_query($groupID);

$groupIDshow = mysql_fetch_object($groupIDget);

//End change 1 (except for <span></span> a few lines below to show $groupIDshow in table

$studentshtml .= '<tr class="r'.$this->rowcount++ . $row_classes[$this->rowcount % 2] . '">'

.'<th class="header c'.$columncount++.' user" scope="row" onclick="set_row(this.parentNode.rowIndex);">'.$user_pic

.'<a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.$this->course->id.'">'

.fullname($user).'</a><span style="font-size:smaller;margin-left:5px;">'.$groupIDshow->id.'</span></th>';

END CODE

If you open the file, you can then control+f and search for the first line of the code above. I only have 1 custom field, so if you have more than 1 you will need to find out the field name in the database and replace 'data' above with that name.

Right, now the tricky bit that I can't quite get to work. In this same file there is a function called load_users(). Again control+f and search for this. From my understanding we need to alter 2 things in this function. Firstly, we need to change the SQL statement so that we include the custom field. This should be something like:

SELECT data FROM mdl_user_info_data

Then we need to change the switch statement. This bit means that if you click on the column header 'FirstName' it will sort by that whatever is in the statement. At the moment you can see it sorts by u.firstname then by u.lastname. So if we can get all the SQL correct and include 'data' from the mdl_user_info_data table, then I would have thought that we could just change this to sort data instead of u.firstname. You'll also have to change the case name 'firstname' to 'yourCustomFieldName'

If we can get all this done, then the final touch is to change a couple of lang strings so that the column header doesn't read 'Firstname / Lastname'. This bit is easy. Find the function get_headerhtml() and replace

$strfirstname = $this->get_lang_string('firstname');
$strlastname = $this->get_lang_string('lastname');

with...

$strfirstname = $this->get_lang_string('lastname');
$strlastname = 'yourCustomFieldName';

 Like I said, my SQL and PHP skills mean I can't seem to quite get this. In principle it works, I have managed for instance to display userid numbers and sort by those. And I can display the custom field data, but I can't get it to sort :  (

I hope this helps someone enough that they could complete the job. I'll keep trying and let you know if I get there.

Good luck

Phil

U odgovoru na phil walley

Re: Custom user profile fields in Grader Report

napisao/la Cyril Teo -
Phil,

Did you manage to get change 1 to work actually?
U odgovoru na Cyril Teo

Re: Custom user profile fields in Grader Report

napisao/la phil walley -

Hi Cyril,

I finally got this to work today. There are a number of small changes that need to be carried out to achieve this, so instead of writing them all here now, I'll give you a screenshot and explanation. If this fits yours or anyone else's requirements, then let me know and I'll post the steps to get this.

In the screenshot, I've removed the user picture to save space, then within the user firstname/lastname field I've added 2 pieces of data (GroupID and Region). The gradebook is now sortable by firstname, lastname, GroupID and Region.

Prilog gradebook.PNG
U odgovoru na phil walley

Re: Custom user profile fields in Grader Report

napisao/la Jose Alonso Rodriguez Tapia -
Hi Phil

I'm very interested in your solution. I've tried to do something like you did (add a custom user field to the gradebook) but I could not.

May you post the steps to get your gradebook?

Thanks a lot
U odgovoru na Jose Alonso Rodriguez Tapia

Re: Custom user profile fields in Grader Report

napisao/la phil walley -

Hey Jose,

Unfortunately, my work role has changed a little. So having solved this problem a month or two back, I was then told that we will no longer be using Moodle. So I haven't looked at this for a while now.

From memory, the important bit is that in order to be able to sort by a particular field, that field must belong to the mdl_user table in your db. I used PhpMyAdmin and was able to copy across fields from other tables. I think the table that stores custom field data is called mdl_user_info_data.

The rest was mostly cosmetic ie. adding 'GroupID' heading to the Gradebook table etc. My only experience of PHP was with moodle, so I always tried to copy code from the original files rather than create my own.

I probably won't check here again since I won't be using Moodle much anymore, but I know how frustating it can be when no one helps you out, so if you need more help contact me at philip.walley@sophos.com

Good luck