Exemplo n.º 1
0
/**
 * Returns the grade to display for the iomadcertificate.
 *
 * @param stdClass $iomadcertificate
 * @param stdClass $course
 * @param int $userid
 * @return string the grade result
 */
function iomadcertificate_get_grade($iomadcertificate, $course, $userid = null)
{
    global $USER, $DB;
    if (empty($userid)) {
        $userid = $USER->id;
    }
    if ($iomadcertificate->printgrade > 0) {
        if ($iomadcertificate->printgrade == 1) {
            if ($course_item = grade_item::fetch_course_item($course->id)) {
                // String used
                $strcoursegrade = get_string('coursegrade', 'iomadcertificate');
                $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 ($iomadcertificate->gradefmt == 1) {
                    $grade = $strcoursegrade . ':  ' . $coursegrade->percentage;
                } else {
                    if ($iomadcertificate->gradefmt == 2) {
                        $grade = $strcoursegrade . ':  ' . $coursegrade->points;
                    } else {
                        if ($iomadcertificate->gradefmt == 3) {
                            $grade = $strcoursegrade . ':  ' . $coursegrade->letter;
                        }
                    }
                }
                return $grade;
            }
        } else {
            // Print the mod grade
            if ($modinfo = iomadcertificate_get_mod_grade($course, $iomadcertificate->printgrade, $userid)) {
                // String used
                $strgrade = get_string('grade', 'iomadcertificate');
                if ($iomadcertificate->gradefmt == 1) {
                    $grade = $modinfo->name . ' ' . $strgrade . ': ' . $modinfo->percentage;
                } else {
                    if ($iomadcertificate->gradefmt == 2) {
                        $grade = $modinfo->name . ' ' . $strgrade . ': ' . $modinfo->points;
                    } else {
                        if ($iomadcertificate->gradefmt == 3) {
                            $grade = $modinfo->name . ' ' . $strgrade . ': ' . $modinfo->letter;
                        }
                    }
                }
                return $grade;
            }
        }
    } else {
        if ($iomadcertificate->printgrade < 0) {
            // Must be a category id.
            if ($category_item = grade_item::fetch(array('itemtype' => 'category', 'iteminstance' => -$iomadcertificate->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 ($iomadcertificate->gradefmt == 1) {
                    $formattedgrade = $category_grade->percentage;
                } else {
                    if ($iomadcertificate->gradefmt == 2) {
                        $formattedgrade = $category_grade->points;
                    } else {
                        if ($iomadcertificate->gradefmt == 3) {
                            $formattedgrade = $category_grade->letter;
                        }
                    }
                }
                return $formattedgrade;
            }
        }
    }
    return '';
}
Exemplo n.º 2
0
/**
 * Prepare to print an activity grade.
 *
 * @deprecated since iomadcertificate version 2012052501
 * @param stdClass $course
 * @param int $moduleid
 * @return mixed
 */
function iomadcertificate_print_mod_grade($course, $moduleid)
{
    debugging('iomadcertificate_print_mod_grade is deprecated, please use iomadcertificate_get_mod_grade instead. Ideally
               you should be using iomadcertificate_get_grade in your iomadcertificate type which will either get the course
               or module grade depending on your iomadcertificate settings.', DEBUG_DEVELOPER);
    global $USER;
    return iomadcertificate_get_mod_grade($course, $moduleid, $USER->id);
}