/**
 * Prepare to print an activity grade.
 *
 * @deprecated since certificate version 2012052501
 * @param stdClass $course
 * @param int $moduleid
 * @return mixed
 */
function certificate_print_mod_grade($course, $moduleid)
{
    debugging('certificate_print_mod_grade is deprecated, please use certificate_get_mod_grade instead. Ideally
               you should be using certificate_get_grade in your certificate type which will either get the course
               or module grade depending on your certificate settings.', DEBUG_DEVELOPER);
    global $USER;
    return certificate_get_mod_grade($course, $moduleid, $USER->id);
}
Ejemplo n.º 2
0
/**
 * Returns the grade to display for the certificate.
 *
 * @param stdClass $certificate
 * @param stdClass $course
 * @param int $userid
 * @param bool $valueonly if true return only the points, %age, or letter with no prefix
 * @return string the grade result
 */
function certificate_get_grade($certificate, $course, $userid = null, $valueonly = false)
{
    global $USER;
    if (empty($userid)) {
        $userid = $USER->id;
    }
    if ($certificate->printgrade > 0) {
        if ($certificate->printgrade == 1) {
            if ($course_item = grade_item::fetch_course_item($course->id)) {
                // Check we want to add a prefix to the grade.
                $strprefix = '';
                if (!$valueonly) {
                    $strprefix = 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->gradefmt == 1) {
                    $grade = $strprefix . $coursegrade->percentage;
                } else {
                    if ($certificate->gradefmt == 2) {
                        $grade = $strprefix . $coursegrade->points;
                    } else {
                        if ($certificate->gradefmt == 3) {
                            $grade = $strprefix . $coursegrade->letter;
                        }
                    }
                }
                return $grade;
            }
        } else {
            // Print the mod grade
            if ($modinfo = certificate_get_mod_grade($course, $certificate->printgrade, $userid)) {
                // Check we want to add a prefix to the grade.
                $strprefix = '';
                if (!$valueonly) {
                    $strprefix = $modinfo->name . ' ' . get_string('grade', 'certificate') . ': ';
                }
                if ($certificate->gradefmt == 1) {
                    $grade = $strprefix . $modinfo->percentage;
                } else {
                    if ($certificate->gradefmt == 2) {
                        $grade = $strprefix . $modinfo->points;
                    } else {
                        if ($certificate->gradefmt == 3) {
                            $grade = $strprefix . $modinfo->letter;
                        }
                    }
                }
                return $grade;
            }
        }
    } else {
        if ($certificate->printgrade < 0) {
            // Must be a category id.
            if ($category_item = grade_item::fetch(array('itemtype' => 'category', 'iteminstance' => -$certificate->printgrade))) {
                $category_item->gradetype = GRADE_TYPE_VALUE;
                $grade = new grade_grade(array('itemid' => $category_item->id, 'userid' => $userid));
                $category_grade = new stdClass();
                $category_grade->points = grade_format_gradevalue($grade->finalgrade, $category_item, true, GRADE_DISPLAY_TYPE_REAL, $decimals = 2);
                $category_grade->percentage = grade_format_gradevalue($grade->finalgrade, $category_item, true, GRADE_DISPLAY_TYPE_PERCENTAGE, $decimals = 2);
                $category_grade->letter = grade_format_gradevalue($grade->finalgrade, $category_item, true, GRADE_DISPLAY_TYPE_LETTER, $decimals = 0);
                if ($certificate->gradefmt == 1) {
                    $formattedgrade = $category_grade->percentage;
                } else {
                    if ($certificate->gradefmt == 2) {
                        $formattedgrade = $category_grade->points;
                    } else {
                        if ($certificate->gradefmt == 3) {
                            $formattedgrade = $category_grade->letter;
                        }
                    }
                }
                return $formattedgrade;
            }
        }
    }
    return '';
}
Ejemplo n.º 3
0
/**
 * Returns the grade to display for the certificate.
 *
 * @param stdClass $certificate
 * @param stdClass $course
 * @param int $userid
 * @return string the grade result
 */
function certificate_get_grade($certificate, $course, $userid = null)
{
    global $USER, $DB;
    if (empty($userid)) {
        $userid = $USER->id;
    }
    if ($certificate->printgrade > 0) {
        if ($certificate->printgrade == 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->gradefmt == 1) {
                    $grade = $strcoursegrade . ':  ' . $coursegrade->percentage;
                } else {
                    if ($certificate->gradefmt == 2) {
                        $grade = $strcoursegrade . ':  ' . $coursegrade->points;
                    } else {
                        if ($certificate->gradefmt == 3) {
                            $grade = $strcoursegrade . ':  ' . $coursegrade->letter;
                        }
                    }
                }
                return $grade;
            }
        } else {
            // Print the mod grade
            if ($modinfo = certificate_get_mod_grade($course, $certificate->printgrade, $userid)) {
                // String used
                $strgrade = get_string('grade', 'certificate');
                if ($certificate->gradefmt == 1) {
                    $grade = $modinfo->name . ' ' . $strgrade . ': ' . $modinfo->percentage;
                } else {
                    if ($certificate->gradefmt == 2) {
                        $grade = $modinfo->name . ' ' . $strgrade . ': ' . $modinfo->points;
                    } else {
                        if ($certificate->gradefmt == 3) {
                            $grade = $modinfo->name . ' ' . $strgrade . ': ' . $modinfo->letter;
                        }
                    }
                }
                return $grade;
            }
        }
    }
    return '';
}