Putting a student's group name on Certificates

Putting a student's group name on Certificates

by Gareth Davies -
Number of replies: 5
I'm trying trying to adapt a certificate so that I can display the Group name on an individual's certificate where the Name of the Course would normally appear. The idea is to have one course with multiple certificates, and I use an enrolment key to assign students to an appropriately named group that I want to appear on the certificate.

The certificate needs to be landscape so I'm adapting type/landscape/certificate.php at line 109:

cert_printtext(170, 330, 'C', 'Helvetica', '', 20, utf8_decode($classname));

I'm thinking it should be a matter of simply replacing the variable $classname with the appropriate group name variable? But I'm obviously getting it wrong. I've tried $groupname (which is used in index.php of the certificate module) and $group->name

Help with getting this right would be greatly appreciated!

Gareth


Average of ratings: -
In reply to Gareth Davies

Re: Putting a student's group name on Certificates

by Raymond Fürst -
$groupname is generally a good idea here. But this variable has to be filled correctly.

All data that is printed onto the certificate is either static or comes from the database record for the issued certificate. Hence all the $certrecord->studentname etc. statements in type/landscape/certificate.php

Try adding the following line to type/landscape/certificate.php:

$currentgroup = get_current_group($course);

Then replacing $classname with $groupname in cert_printtext(...); might work


In reply to Raymond Fürst

Re: Putting a student's group name on Certificates

by Gareth Davies -
OK, I've inserted the following in near the top of type/landscape/certificate.php (lines 25 and 26):

//Find current group
$currentgroup = get_current_group($course);

and then edited the line 109 to:

cert_printtext(170, 330, 'C', 'Helvetica', '', 20, utf8_decode($groupname));

This just breaks the view.php page (completely blank when attempting to load)

I turned debugging on and the view page comes up with:

Catchable fatal error: Object of class stdClass could not be converted to string in /Applications/MAMP/htdocs/moodle/lib/grouplib.php on line 133
In reply to Gareth Davies

Re: Putting a student's group name on Certificates

by Raymond Fürst -
I'm not sure how to code it right. This is more difficult than I thought. It seems there is a type mismatch error here.

$groupname must be a string so it can be printed using cert_printtext(...)

get_current_group(...) does not deliver the name as a string, but something else. It's either the group as an object or the group-id of that group.

If it is an object, then the following might work:

$currentgroup=get_current_group($course);
$groupname=$currentgroup->name;
...
cert_printtext(170 ... , utf8_decode($groupname));
In reply to Raymond Fürst

Re: Putting a student's group name on Certificates

by Gareth Davies -
That failed I'm afraid ... but I have got it working!

The answer is to insert (following my line numbers above - 25- 28):

//Find current group
$currentgroup = get_current_group($course->id);
$group = get_record('groups', 'id', $currentgroup);
$groupname=$group->name;

and then in the print section ...

cert_printtext(170, 330, 'C', 'Helvetica', '', 20, utf8_decode($groupname));

Am now going to test it with a few user accounts in different groups to ensure it all works properly.
In reply to Gareth Davies

Tárgy: Re: Putting a student's group name on Certificates

by Nagy Vitéz -
Hi, This works great, but I have students who are in more than one group at a time. How can I put all the groupnames on the certificate (maybe separated by commas)? Thanks, Vitéz