Having multiple grade on certificate

Having multiple grade on certificate

by Ahmad Azizan Idris -
Number of replies: 2

Hello,

On a usual situation with certificate, selecting one quiz from print grade drop-down menu would be fine if I'm concern with only 1 grade. 

However, I was wondering, if I'm about to include the Offline Assignment grade together with Online Quiz grade as one grade, how can I accomplish that ?

I tried customizing the lib.php and mod_form.php to add another form field so that I can select another grade to be included, but I guess I just do it wrongly.

Could anyone give me a hint about this?

Average of ratings: -
In reply to Ahmad Azizan Idris

Re: Having multiple grade on certificate

by Mark Nelson -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Hi Ahmad,

Adding another entry in the form will not work as the database only has one field to save the grade. In order to save multiple grades you would have to add another grade field to the certificate table to store it, then edit the type file to print this as well. This is going to require some extra coding in your mod/certificate/type/<thetypeyouareusing>.php file. There is currently a function called certificate_get_mod_grade that returns the grade for a given module, you could use this to retrieve the grade of the added module.

Regards,

Mark

In reply to Mark Nelson

Re: Having multiple grade on certificate

by Ahmad Azizan Idris -

Hi Mark,

Thanks for the heads up!

From your instruction, I've been able to get the 2nd grade into the certificate.

This is just a rough reference for myself and others whom have same motives of having 2 grades for further manipulation.

First I add new fields on table mod_certificate;

ALTER TABLE mod_certificate ADD printgrade2 bigint(10) AFTER printgrade;
ALTER TABLE mod_certificate ADD gradefmt2 bigint(10) AFTER gradefmt;

and set printgrade2 and gradefmt2 default: 0 and Null: NO

Second I modify mod_form.php to allow selection of new grade;

$gradeoptions2 = certificate_get_grade_options() + $modules;
$mform->addElement('select', 'printgrade2', get_string('printgrade', 'certificate'),$gradeoptions2);
$mform->setDefault('printgrade2', 0);
$mform->addHelpButton('printgrade2', 'printgrade2', 'certificate');

$gradeformatoptions2 = array( 1 => get_string('gradepercent', 'certificate'), 2 => get_string('gradepoints', 'certificate'),
3 => get_string('gradeletter', 'certificate'));
$mform->addElement('select', 'gradefmt2', get_string('gradefmt', 'certificate'), $gradeformatoptions2);
$mform->setDefault('gradefmt2', 0);
$mform->addHelpButton('gradefmt2', 'gradefmt2', 'certificate');

Third I modify lib.php and copy function certificate_get_grade() to certificate_get_grade2() as below;

function certificate_get_grade2($certificate, $course, $userid = null) {
global $USER, $DB;

if (empty($userid)) {
$userid = $USER->id;
}

if ($certificate->printgrade2 > 0) {
if ($certificate->printgrade2 == 1) {
if ($course_item = grade_item::fetch_course_item($course->id)) {
// String used
$strcoursegrade = get_string('coursegrade', 'certificate');

$grade = new grade_grade(array('itemid' => $course_item->id, 'userid' => $userid));
$course_item->gradetype = GRADE_TYPE_VALUE;
$coursegrade = new stdClass;
$coursegrade->points = grade_format_gradevalue($grade->finalgrade, $course_item, true, GRADE_DISPLAY_TYPE_REAL, $decimals = 2);
$coursegrade->percentage = grade_format_gradevalue($grade->finalgrade, $course_item, true, GRADE_DISPLAY_TYPE_PERCENTAGE, $decimals = 2);
$coursegrade->letter = grade_format_gradevalue($grade->finalgrade, $course_item, true, GRADE_DISPLAY_TYPE_LETTER, $decimals = 0);

if ($certificate->gradefmt2 == 1) {
$grade = $strcoursegrade . ': ' . $coursegrade->percentage;
} else if ($certificate->gradefmt2 == 2) {
$grade = $strcoursegrade . ': ' . $coursegrade->points;
} else if ($certificate->gradefmt2 == 3) {
$grade = $strcoursegrade . ': ' . $coursegrade->letter;
}

return $grade;
}
} else { // Print the mod grade
if ($modinfo = certificate_get_mod_grade($course, $certificate->printgrade2, $userid)) {
// String used
$strgrade = get_string('grade', 'certificate');
if ($certificate->gradefmt2 == 1) {
$grade = $modinfo->name . ' ' . $strgrade . ': ' . $modinfo->percentage;
//$grade = $modinfo->name;
} else if ($certificate->gradefmt2 == 2) {
$grade = $modinfo->name . ' ' . $strgrade . ': ' . $modinfo->points;
} else if ($certificate->gradefmt2 == 3) {
$grade = $modinfo->name . ' ' . $strgrade . ': ' . $modinfo->letter;

}

return $grade;
}
}
}

return '';
}

Last, I modify certificate.php in folder type/ to show the 2nd grade;

certificate_print_text($pdf, $x, $y + 112, 'C', 'freeserif', '', 10, certificate_get_grade2($certificate, $course));

 

Further coding is required in certificate.php depending on your objectives of having 2 grades on 1 certificate.