bozoh / moodle-mod_simplecertificate

It's NOT RECOMMENDED to install version below 2.2.6 (MOODLE_31), due a security issues See more in README
17 stars 44 forks source link

Error when viewing certificate with "Print grade" setting set to "Course grade" #228

Closed logan-reynolds closed 4 years ago

logan-reynolds commented 5 years ago

Describe the bug On Totara 12 when using latest M3.3-compliant release 2.2.8 version 2018080400 of mod_certificate: The following error is encountered when Print grade is set to Course grade if no course grade exists (i.e. the course total grade has not been set yet.) Noting this error goes away if the mod_simplecertificate instance is switched back to it's default value of "No grade", so this appears to be happening because arithmetic-related operation get_decimals() is being called assuming a numeric value exists when it doesn't. I believe the fix would be to check the value is set to some numeric value instead of null, and take some alternate action if the value is null (assuming that would equate to 0 if no course grade has been calculated yet...): `` Exception - Call to a member function get_decimals() on null Debug info: Error code: generalexceptionmessage Stack trace:

line 735 of /mod/simplecertificate/locallib.php: Error thrown
line 1378 of /mod/simplecertificate/locallib.php: call to simplecertificate->get_grade()
line 1010 of /mod/simplecertificate/locallib.php: call to simplecertificate->get_certificate_text()
line 1100 of /mod/simplecertificate/locallib.php: call to simplecertificate->create_pdf()
line 1210 of /mod/simplecertificate/locallib.php: call to simplecertificate->save_pdf()
line 1282 of /mod/simplecertificate/locallib.php: call to simplecertificate->get_issue_file()
line 1870 of /mod/simplecertificate/locallib.php: call to simplecertificate->output_pdf()
line 106 of /mod/simplecertificate/view.php: call to simplecertificate->view_default()

Output buffer:
Notice: Undefined variable: courseitem in /var/www/html/TOTARA_120_STABLE/mod/simplecertificate/locallib.php on line 735
``

Moodle Version(s) Totara 12

To Reproduce

Expected behavior Certificate should display

Screenshots simplecertificate_view_error_when_Printgrade_coursegrade

cristiansead commented 4 years ago

Hi Logan,

I solved by changing the $course_item variable in the rows 730, 731 anda 732 by $courseitem

case self::COURSE_GRADE: //Course grade -- if ($course_item = grade_item::fetch_course_item($this->get_course()->id)) { -- $grade = new grade_grade(array('itemid' => $course_item->id, 'userid' => $userid)); -- $course_item->gradetype = GRADE_TYPE_VALUE; ++ if ($courseitem = grade_item::fetch_course_item($this->get_course()->id)) { ++ $grade = new grade_grade(array('itemid' => $courseitem->id, 'userid' => $userid)); ++ $courseitem->gradetype = GRADE_TYPE_VALUE; $coursegrade = new stdClass();

                $decimals = $courseitem->get_decimals();
                // String used.
                $coursegrade->points = grade_format_gradevalue($grade->finalgrade, $courseitem, true, GRADE_DISPLAY_TYPE_REAL, $decimals = 2);
                $coursegrade->percentage = grade_format_gradevalue($grade->finalgrade, $courseitem, true, GRADE_DISPLAY_TYPE_PERCENTAGE, $decimals = 2);
                $coursegrade->letter = grade_format_gradevalue($grade->finalgrade, $courseitem, true,                                                           GRADE_DISPLAY_TYPE_LETTER, $decimals = 0);
            }
        break;
bozoh commented 4 years ago

Sorry, i can't reproduce this error in moodle3.9dev