Exemplo n.º 1
0
/**
 * Fetches grade_item info and grades from the referenced course
 *
 * Returned structure is
 *  object(
 *      ->grades = array[userid] of object(->userid ->rawgrade ->feedback ->feedbackformat)
 *      ->grademax
 *      ->grademin
 *      ->itemname
 *      ...
 *  )
 *
 * @access public
 * @param int $subcourseid ID of subcourse instance
 * @param int $refcourseid ID of referenced course
 * @param bool|\boolan $gradeitemonly If true, fetch only grade item info without grades
 * @return object Object containing grades array and gradeitem info
 */
function subcourse_fetch_refgrades($subcourseid, $refcourseid, $gradeitemonly = false)
{
    global $CFG;
    $fetchedfields = subcourse_get_fetched_item_fields();
    if (!function_exists('grade_update')) {
        //workaround for buggy PHP versions
        require_once $CFG->libdir . '/gradelib.php';
    }
    $return = new stdClass();
    $return->grades = array();
    if (empty($refcourseid)) {
        return false;
    }
    $refgradeitem = grade_item::fetch_course_item($refcourseid);
    // get grade_item info
    foreach ($fetchedfields as $property) {
        if (!empty($refgradeitem->{$property})) {
            $return->{$property} = $refgradeitem->{$property};
        } else {
            $return->{$property} = null;
        }
    }
    // if the remote grade_item is non-global scale, do not fetch grades - they can't be used
    if ($refgradeitem->gradetype == GRADE_TYPE_SCALE && !subcourse_is_global_scale($refgradeitem->scaleid)) {
        $gradeitemonly = true;
        $return->localremotescale = true;
    }
    if (!$gradeitemonly) {
        // get grades
        $cm = get_coursemodule_from_instance("subcourse", $subcourseid);
        $context = get_context_instance(CONTEXT_MODULE, $cm->id);
        $users = get_users_by_capability($context, 'mod/subcourse:begraded', 'u.id,u.lastname', 'u.lastname', '', '', '', '', false, true);
        foreach ($users as $user) {
            $grade = new grade_grade(array('itemid' => $refgradeitem->id, 'userid' => $user->id));
            $grade->grade_item =& $refgradeitem;
            $return->grades[$user->id]->userid = $user->id;
            $return->grades[$user->id]->rawgrade = $grade->finalgrade;
            $return->grades[$user->id]->feedback = $grade->feedback;
            $return->grades[$user->id]->feedbackformat = $grade->feedbackformat;
        }
    }
    return $return;
}
Exemplo n.º 2
0
/**
 * Fetches grade_item info and grades from the referenced course
 *
 * Returned structure is
 *  object(
 *      ->grades = array[userid] of object(->userid ->rawgrade ->feedback ->feedbackformat)
 *      ->grademax
 *      ->grademin
 *      ->itemname
 *      ...
 *  )
 *
 * @access public
 * @param int $subcourseid ID of subcourse instance
 * @param int $refcourseid ID of referenced course
 * @param bool $gradeitemonly If true, fetch only grade item info without grades
 * @return stdClass containing grades array and gradeitem info
 */
function subcourse_fetch_refgrades($subcourseid, $refcourseid, $gradeitemonly = false)
{
    if (empty($refcourseid)) {
        throw new coding_exception('Empty referenced course id');
    }
    $fetchedfields = subcourse_get_fetched_item_fields();
    $return = new stdClass();
    $return->grades = array();
    $refgradeitem = grade_item::fetch_course_item($refcourseid);
    // get grade_item info
    foreach ($fetchedfields as $property) {
        if (!empty($refgradeitem->{$property})) {
            $return->{$property} = $refgradeitem->{$property};
        } else {
            $return->{$property} = null;
        }
    }
    // if the remote grade_item is non-global scale, do not fetch grades - they can't be used
    if ($refgradeitem->gradetype == GRADE_TYPE_SCALE && !subcourse_is_global_scale($refgradeitem->scaleid)) {
        $gradeitemonly = true;
        debugging(get_string('errlocalremotescale', 'subcourse'));
        $return->localremotescale = true;
    }
    if (!$gradeitemonly) {
        // get grades
        $cm = get_coursemodule_from_instance("subcourse", $subcourseid);
        $context = context_module::instance($cm->id);
        $users = get_users_by_capability($context, 'mod/subcourse:begraded', 'u.id,u.lastname', 'u.lastname', '', '', '', '', false, true);
        foreach ($users as $user) {
            $grade = new grade_grade(array('itemid' => $refgradeitem->id, 'userid' => $user->id));
            $grade->grade_item =& $refgradeitem;
            $return->grades[$user->id] = new stdClass();
            $return->grades[$user->id]->userid = $user->id;
            $return->grades[$user->id]->rawgrade = $grade->finalgrade;
            $return->grades[$user->id]->feedback = $grade->feedback;
            $return->grades[$user->id]->feedbackformat = $grade->feedbackformat;
        }
    }
    return $return;
}