Example #1
0
/**
 * Update grades by firing grade_updated event
 *
 * @param object $glossary null means all glossaries (with extra cmidnumber property)
 * @param int $userid specific user only, 0 mean all
 */
function glossary_update_grades($glossary = null, $userid = 0, $nullifnone = true)
{
    global $CFG;
    require_once $CFG->libdir . '/gradelib.php';
    if ($glossary != null) {
        if ($grades = glossary_get_user_grades($glossary, $userid)) {
            glossary_grade_item_update($glossary, $grades);
        } else {
            if ($userid and $nullifnone) {
                $grade = new object();
                $grade->userid = $userid;
                $grade->rawgrade = NULL;
                glossary_grade_item_update($glossary, $grade);
            } else {
                glossary_grade_item_update($glossary);
            }
        }
    } else {
        $sql = "SELECT g.*, cm.idnumber as cmidnumber\n                  FROM {$CFG->prefix}glossary g, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m\n                 WHERE m.name='glossary' AND m.id=cm.module AND cm.instance=g.id";
        if ($rs = get_recordset_sql($sql)) {
            while ($glossary = rs_fetch_next_record($rs)) {
                if ($glossary->assessed) {
                    glossary_update_grades($glossary, 0, false);
                } else {
                    glossary_grade_item_update($glossary);
                }
            }
            rs_close($rs);
        }
    }
}
Example #2
0
/**
 * Update activity grades
 *
 * @global object
 * @global object
 * @param object $glossary null means all glossaries (with extra cmidnumber property)
 * @param int $userid specific user only, 0 means all
 */
function glossary_update_grades($glossary=null, $userid=0, $nullifnone=true) {
    global $CFG, $DB;
    require_once($CFG->libdir.'/gradelib.php');

    if (!$glossary->assessed) {
        glossary_grade_item_update($glossary);

    } else if ($grades = glossary_get_user_grades($glossary, $userid)) {
        glossary_grade_item_update($glossary, $grades);

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

    } else {
        glossary_grade_item_update($glossary);
    }
}
Example #3
0
function glossary_grades($glossaryid)
{
    /// Must return an array of grades for a given instance of this module,
    /// indexed by user.  It also returns a maximum allowed grade.
    if (!($glossary = get_record("glossary", "id", $glossaryid))) {
        return false;
    }
    if (!$glossary->assessed) {
        return false;
    }
    $scalemenu = make_grades_menu($glossary->scale);
    $currentuser = 0;
    $ratingsuser = array();
    if ($ratings = glossary_get_user_grades($glossaryid)) {
        foreach ($ratings as $rating) {
            // Ordered by user
            if ($currentuser and $rating->userid != $currentuser) {
                if (!empty($ratingsuser)) {
                    if ($glossary->scale < 0) {
                        $return->grades[$currentuser] = glossary_get_ratings_mean(0, $scalemenu, $ratingsuser);
                        $return->grades[$currentuser] .= "<br />" . glossary_get_ratings_summary(0, $scalemenu, $ratingsuser);
                    } else {
                        $total = 0;
                        $count = 0;
                        foreach ($ratingsuser as $ra) {
                            $total += $ra;
                            $count++;
                        }
                        $return->grades[$currentuser] = (string) format_float($total / $count, 2);
                        if (count($ratingsuser) > 1) {
                            $return->grades[$currentuser] .= " (" . count($ratingsuser) . ")";
                        }
                    }
                } else {
                    $return->grades[$currentuser] = "";
                }
                $ratingsuser = array();
            }
            $ratingsuser[] = $rating->rating;
            $currentuser = $rating->userid;
        }
        if (!empty($ratingsuser)) {
            if ($glossary->scale < 0) {
                $return->grades[$currentuser] = glossary_get_ratings_mean(0, $scalemenu, $ratingsuser);
                $return->grades[$currentuser] .= "<br />" . glossary_get_ratings_summary(0, $scalemenu, $ratingsuser);
            } else {
                $total = 0;
                $count = 0;
                foreach ($ratingsuser as $ra) {
                    $total += $ra;
                    $count++;
                }
                $return->grades[$currentuser] = (string) format_float((double) $total / (double) $count, 2);
                if (count($ratingsuser) > 1) {
                    $return->grades[$currentuser] .= " (" . count($ratingsuser) . ")";
                }
            }
        } else {
            $return->grades[$currentuser] = "";
        }
    } else {
        $return->grades = array();
    }
    if ($glossary->scale < 0) {
        $return->maxgrade = "";
    } else {
        $return->maxgrade = $glossary->scale;
    }
    return $return;
}