Esempio n. 1
0
function attforblock_update_instance($attforblock)
{
    /// Given an object containing all the necessary data,
    /// (defined by the form in mod.html) this function
    /// will update an existing instance with new data.
    global $DB;
    $attforblock->timemodified = time();
    $attforblock->id = $attforblock->instance;
    if (!$DB->update_record('attforblock', $attforblock)) {
        return false;
    }
    attforblock_grade_item_update($attforblock);
    return true;
}
/**
 * Update grades by firing grade_updated event
 *
 * @param object $attforblock null means all attforblocks
 * @param int $userid specific user only, 0 mean all
 */
function attforblock_update_grades($attforblock = null, $userid = 0, $nullifnone = true)
{
    global $CFG;
    if (!function_exists('grade_update')) {
        //workaround for buggy PHP versions
        require_once $CFG->libdir . '/gradelib.php';
    }
    if ($attforblock != null) {
        if ($grades = attforblock_get_user_grades($attforblock, $userid)) {
            foreach ($grades as $k => $v) {
                if ($v->rawgrade == -1) {
                    $grades[$k]->rawgrade = null;
                }
            }
            attforblock_grade_item_update($attforblock, $grades);
        } else {
            attforblock_grade_item_update($attforblock);
        }
    } else {
        $sql = "SELECT a.*, cm.idnumber as cmidnumber, a.course as courseid\n                  FROM {$CFG->prefix}attforblock a, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m\n                 WHERE m.name='attforblock' AND m.id=cm.module AND cm.instance=a.id";
        if ($rs = get_recordset_sql($sql)) {
            while ($attforblock = rs_fetch_next_record($rs)) {
                //                if ($attforblock->grade != 0) {
                attforblock_update_grades($attforblock);
                //                } else {
                //                    attforblock_grade_item_update($attforblock);
                //                }
            }
            rs_close($rs);
        }
    }
}