Пример #1
0
/**
 * Update activity grades
 *
 * @global object
 * @global object
 * @param object $data
 * @param int $userid specific user only, 0 means all
 * @param bool $nullifnone
 */
function data_update_grades($data, $userid=0, $nullifnone=true) {
    global $CFG, $DB;
    require_once($CFG->libdir.'/gradelib.php');

    if (!$data->assessed) {
        data_grade_item_update($data);

    } else if ($grades = data_get_user_grades($data, $userid)) {
        data_grade_item_update($data, $grades);

    } else if ($userid and $nullifnone) {
        $grade = new stdClass();
        $grade->userid   = $userid;
        $grade->rawgrade = NULL;
        data_grade_item_update($data, $grade);

    } else {
        data_grade_item_update($data);
    }
}
Пример #2
0
/**
 * Update grades by firing grade_updated event
 *
 * @param object $data null means all databases
 * @param int $userid specific user only, 0 mean all
 */
function data_update_grades($data = null, $userid = 0, $nullifnone = true)
{
    global $CFG;
    if (!function_exists('grade_update')) {
        //workaround for buggy PHP versions
        require_once $CFG->libdir . '/gradelib.php';
    }
    if ($data != null) {
        if ($grades = data_get_user_grades($data, $userid)) {
            data_grade_item_update($data, $grades);
        } else {
            if ($userid and $nullifnone) {
                $grade = new object();
                $grade->userid = $userid;
                $grade->rawgrade = NULL;
                data_grade_item_update($data, $grade);
            } else {
                data_grade_item_update($data);
            }
        }
    } else {
        $sql = "SELECT d.*, cm.idnumber as cmidnumber\n                  FROM {$CFG->prefix}data d, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m\n                 WHERE m.name='data' AND m.id=cm.module AND cm.instance=d.id";
        if ($rs = get_recordset_sql($sql)) {
            while ($data = rs_fetch_next_record($rs)) {
                if ($data->assessed) {
                    data_update_grades($data, 0, false);
                } else {
                    data_grade_item_update($data);
                }
            }
            rs_close($rs);
        }
    }
}