Mentee Block Customisation- link to grader report

Mentee Block Customisation- link to grader report

by Kyle Egan -
Number of replies: 8

Hi,

I just wanted to share a little customisation I made to the mentee block so it is easier for a parent / mentor to view the grader report for particular users. This is an Admin hack to the PHP. It works on my moodle 2.03 and 2.1 not sure on other versions. 

The customisation creates a link to the individuals grader report next to the persons name in the grader block.

In the .php file:
Create this variable in the get_content() function

$id = $_GET['id'];

Then add the following code.

$this->content->text .= '<li><a href="'.$CFG->wwwroot.'/user/view.php?id='.$usercontext->instanceid.'&amp;course='.SITEID.'">'.fullname($usercontext).'</a><a href="http://yoursite/moodle/course/user.php?user='.$usercontext->instanceid.'&id='.$id.'&mode=grade"> | Report</a></li>';

That's it, the only down fall I can see is that it will create a small security risk because the person with the 'parent / mentor' role if they know the id of another user can simply change the id in the URL bar. But this is an existing floor due to the parent having the permission viewallusers.

Hope this helps someone else.

Average of ratings: Useful (2)
In reply to Kyle Egan

Re: Mentee Block Customisation- link to grader report

by jen ol -
Thank you! This is a great idea! Exactly what I'm looking for.
But when I add this I'm getting an error (version 2.1.1+)

You are trying to use an invalid course ID: ({$a})

More information about this error
Stack trace:

line 429 of /lib/setuplib.php: moodle_exception thrown
line 46 of /course/user.php: call to print_error()

Could you help me with this?
In reply to jen ol

Re: Mentee Block Customisation- link to grader report

by Nathan Robbins -

Here is a fix that checks whether the course ID exists. Just replace the old line of code with these lines:

if(!empty($id)){
$this->content->text .= '<li><a href="'.$CFG->wwwroot.'/user/view.php?id='.$usercontext->instanceid.'&amp;course='.SITEID.'">'.fullname($usercontext).'</a><a href="'.$CFG->wwwroot.'/course/user.php?user='.$usercontext->instanceid.'&id='.$id.'&mode=grade"> | Report</a></li>';
} else {
$this->content->text .= '<li><a href="'.$CFG->wwwroot.'/user/view.php?id='.$usercontext->instanceid.'&amp;course='.SITEID.'">'.fullname($usercontext).'</a></li>';
}

This way, the mentees block only shows the report link if it is valid to do so.

HTH,

Isaac

In reply to Nathan Robbins

Re: Mentee Block Customisation- link to grader report

by jen ol -
Thank you Isaac , I have already find a way by changing link to the empty grader report and adding code that shows in the grader report all courses that student enrolled.

Here is code that shows courses, maybe someone find it useful:

if ($mycourses = enrol_get_users_courses($user->id, 'visible DESC,sortorder ASC', null, false, 21)) {
$courselisting = '';
foreach ($mycourses as $mycourse) {
if ($mycourse->category) {
if ($mycourse->id != $course->id){
$class = '';
if ($mycourse->visible == 0) {
// get_my_courses will filter courses $USER cannot see
// if we get one with visible 0 it just means it's hidden
// ... but not from $USER
$class = 'class="dimmed"';
}
$courselisting .= "wwwroot}/course/user.php?id={$mycourse->id}&user={$user->id}&mode=grade\" $class >"
. format_string($mycourse->fullname) . "
, ";
}
else {
$courselisting .= format_string($mycourse->fullname) . "   , ";
}
}
}
echo rtrim($courselisting,', ');
}
In reply to jen ol

Re: Mentee Block Customisation- link to grader report

by Nathan Robbins -

Where are you adding this code? This is something I am working on doing myself. (I am still learning PHP, so I am a little slow... smile )

Thanks,

Isaac

In reply to jen ol

Re: Mentee Block Customisation- link to grader report

by Kyle Egan -

Hi Jen,

I am also intrested where you put this code are you replacing the link to the report to something like this:

<a href="'.$courselisting.'"> | Report</a>

It would be great to see the whole piece.

Thanks Issac also for the If statement, I only have the mentee block in courses but I did think if I ever wanted to put it else where I would need the if courseID exists.

In reply to Kyle Egan

Re: Mentee Block Customisation- link to grader report

by jen ol -
Hi Isaac and Kyle,

This is link to empty grade report of your student.
yourmoodle/mentees/block_mentees.php
< ahref="http://yourmoodle/course/user.php?user='.$usercontext-"> | Grade Report< /a>

This code shows all courses that student enrolled, mentor can easy switch courses and see grade report
yourmoodle/course/user.php
find in file user.php switch ($mode) {
case "grade":
then insert code
if ($mycourses = enrol_get_users_courses($user->id, 'visible DESC,sortorder ASC', null, false, 21)) {
$courselisting = '';
foreach ($mycourses as $mycourse) {
if ($mycourse->category) {
if ($mycourse->id != $course->id){
$class = '';
if ($mycourse->visible == 0) {
// get_my_courses will filter courses $USER cannot see
// if we get one with visible 0 it just means it's hidden
// ... but not from $USER
$class = 'class="dimmed"';
}
$courselisting .= "wwwroot}/course/user.php?id={$mycourse->id}&user={$user->id}&mode=grade\" $class >"
. format_string($mycourse->fullname) . "
, ";
}
else {
$courselisting .= format_string($mycourse->fullname) . "   , ";
}
}
}
echo rtrim($courselisting,', ');
}

In reply to jen ol

Re: Mentee Block Customisation- link to grader report

by Nathan Robbins -

Hi Jen,

Thanks for the clarification. I am getting several issues when I attempt to implement this code. I am thinking that the code might have gotten messed up during copy/paste.

The link format caused some errors, and seems unable to work without a valid ID. I solved this by going back to the original report link format.

When I test the new code for the report, I get this result:

my user reports error

I have played with several variations of the code, but haven't found a solution yet. I can get it to output a valid hyperlink, but it only list the one course. If I access the report from that course, it lists the course name without the link. Any help would be greatly appreciated.

Thanks,
Isaac

In reply to Nathan Robbins

Re: Mentee Block Customisation- link to grader report

by Nathan Robbins -

I found a solution. I made some changes so that the links would work:

$courselisting .= "<a href=\"{$CFG->wwwroot}/course/user.php?id={$mycourse->id}&user={$user->id}&mode=grade\">"
. format_string($mycourse->fullname) . "</a>, ";

Is this close to what was intended? My PHP-fu is weak.

Thanks,
Isaac