Esempio n. 1
0
/**
 * Delete a message from the NanoGong database.
 **/
function nanogong_delete_message($nanogong, $messageid, &$error)
{
    global $CFG, $USER;
    if (!isstudent($nanogong->course) && !isteacheredit($nanogong->course)) {
        $error = get_string("notincourse", "nanogong");
        return false;
    }
    if ($nanogong_message = get_record("nanogong_message", "id", $messageid)) {
        if (isstudent($nanogong->course) && $nanogong_message->locked) {
            $error = get_string("lockerror", "nanogong");
            return false;
        }
        $soundfile = $CFG->dataroot . $nanogong_message->path;
        if (file_exists($soundfile)) {
            @unlink($soundfile);
        }
        if (substr($CFG->release, 0, 3) == "1.9") {
            return delete_records("nanogong_message", "id", $nanogong_message->id) && nanogong_update_grades($nanogong, $nanogong_message->userid);
        }
        return delete_records("nanogong_message", "id", $nanogong_message->id);
    }
    return false;
}
Esempio n. 2
0
/**
 * Update grades in central gradebook
 *
 * @param object $nanogong null means all nanogongs
 * @param int $userid specific user only, 0 mean all
 */
function nanogong_update_grades($nanogong = null, $userid = 0, $nullifnone = true)
{
    global $CFG;
    if (!function_exists('grade_update')) {
        //workaround for buggy PHP versions
        require_once $CFG->libdir . '/gradelib.php';
    }
    if ($nanogong != null) {
        if ($grades = nanogong_get_user_grades($nanogong, $userid)) {
            nanogong_grade_item_update($nanogong, $grades);
        } else {
            if ($userid and $nullifnone) {
                $grade = new object();
                $grade->userid = $userid;
                $grade->rawgrade = NULL;
                nanogong_grade_item_update($nanogong, $grade);
            } else {
                nanogong_grade_item_update($nanogong);
            }
        }
    } else {
        $sql = "SELECT a.*, cm.idnumber as cmidnumber, a.course as courseid\n                  FROM {$CFG->prefix}nanogong a, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m\n                 WHERE m.name='nanogong' AND m.id=cm.module AND cm.instance=a.id";
        if ($rs = get_recordset_sql($sql)) {
            while ($nanogong = rs_fetch_next_record($rs)) {
                if ($nanogong->maxscore != 0) {
                    nanogong_update_grades($nanogong, 0, false);
                } else {
                    nanogong_grade_item_update($nanogong);
                }
            }
            rs_close($rs);
        }
    }
    return true;
}