Ejemplo n.º 1
0
 public function test_grade_get_gradable_activities()
 {
     $this->resetAfterTest(true);
     $course = $this->getDataGenerator()->create_course();
     $data1 = $this->getDataGenerator()->create_module('data', array('assessed' => 1, 'scale' => 100, 'course' => $course->id));
     $data2 = $this->getDataGenerator()->create_module('data', array('assessed' => 0, 'course' => $course->id));
     $forum1 = $this->getDataGenerator()->create_module('forum', array('assessed' => 1, 'scale' => 100, 'course' => $course->id));
     $forum2 = $this->getDataGenerator()->create_module('forum', array('assessed' => 0, 'course' => $course->id));
     $cms = grade_get_gradable_activities($course->id);
     $this->assertEquals(2, count($cms));
     $this->assertTrue(isset($cms[$data1->cmid]));
     $this->assertTrue(isset($cms[$forum1->cmid]));
     $cms = grade_get_gradable_activities($course->id, 'forum');
     $this->assertEquals(1, count($cms));
     $this->assertTrue(isset($cms[$forum1->cmid]));
 }
Ejemplo n.º 2
0
/**
 * Retrieves an array with grade information including grade obtained by a user for a LO in Moodle, maximum grade for that LO and min grade.  Returns null if the module is not gradable
 * or if the user has not been graded.
 * @author elever
 * @param cm_info $coursemodule_info : Moodle object with information of a module in a course
 * @param int $userid : moodle identifier of the user
 * @return array $grade_info | null
 */
function block_intuitel_get_grade_info(\cm_info $coursemodule_info, $userid)
{
    global $DB, $CFG;
    require_once $CFG->dirroot . '/lib/gradelib.php';
    require_once $CFG->dirroot . '/grade/querylib.php';
    // first check if the LO is gradable
    $gradable = false;
    $gradable_cms = grade_get_gradable_activities($coursemodule_info->course, $coursemodule_info->modname);
    foreach ($gradable_cms as $gradable_cm) {
        if ($gradable_cm->id == $coursemodule_info->id) {
            $gradable = true;
        }
    }
    // Second, check if the user has been graded
    if ($gradable) {
        if (grade_is_user_graded_in_activity($coursemodule_info, $userid)) {
            $grade_complete_info = \grade_get_grades($coursemodule_info->course, 'mod', $coursemodule_info->modname, $coursemodule_info->instance, $userid);
            $grade = array();
            $grade['grade'] = $grade_complete_info->items[0]->grades[$userid]->grade;
            $grade['grademax'] = $grade_complete_info->items[0]->grademax;
            $grade['grademin'] = $grade_complete_info->items[0]->grademin;
        } else {
            //user not graded yet
            $grade = null;
        }
    } else {
        $grade = null;
    }
    return $grade;
}
Ejemplo n.º 3
0
/**
 * Returns an array of activities (defined as $cm objects) which are gradeable from gradebook, outcomes are ignored.
 *
 * @param int $courseid If provided then restrict to one course.
 * @param string $modulename If defined (could be 'forum', 'assignment' etc) then only that type are returned.
 * @return array $cm objects
 */
function grade_get_gradable_activities($courseid, $modulename = '')
{
    global $CFG, $DB;
    if (empty($modulename)) {
        if (!($modules = $DB->get_records('modules', array('visible' => '1')))) {
            return false;
        }
        $result = array();
        foreach ($modules as $module) {
            if ($cms = grade_get_gradable_activities($courseid, $module->name)) {
                $result = $result + $cms;
            }
        }
        if (empty($result)) {
            return false;
        } else {
            return $result;
        }
    }
    $params = array($courseid, $modulename, GRADE_TYPE_NONE, $modulename);
    $sql = "SELECT cm.*, m.name, md.name as modname\n              FROM {grade_items} gi, {course_modules} cm, {modules} md, {$modulename} m\n             WHERE gi.courseid = ? AND\n                   gi.itemtype = 'mod' AND\n                   gi.itemmodule = ? AND\n                   gi.itemnumber = 0 AND\n                   gi.gradetype != ? AND\n                   gi.iteminstance = cm.instance AND\n                   cm.instance = m.id AND\n                   md.name = ? AND\n                   md.id = cm.module";
    return $DB->get_records_sql($sql, $params);
}
Ejemplo n.º 4
0
/**
 * Returns an array of activities (defined as $cm objects) which are gradeable from gradebook, outcomes are ignored.
 *
 * @param int $courseid If provided then restrict to one course.
 * @param string $modulename If defined (could be 'forum', 'assignment' etc) then only that type are returned.
 * @return array $cm objects
 */
function grade_get_gradable_activities($courseid, $modulename = '')
{
    global $CFG;
    if (empty($modulename)) {
        if (!($modules = get_records('modules', 'visible', '1'))) {
            return false;
        }
        $result = array();
        foreach ($modules as $module) {
            if ($cms = grade_get_gradable_activities($courseid, $module->name)) {
                $result = $result + $cms;
            }
        }
        if (empty($result)) {
            return false;
        } else {
            return $result;
        }
    }
    $sql = "SELECT cm.*, m.name, md.name as modname\n              FROM {$CFG->prefix}grade_items gi, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules md, {$CFG->prefix}{$modulename} m\n             WHERE gi.courseid = {$courseid} AND\n                   gi.itemtype = 'mod' AND\n                   gi.itemmodule = '{$modulename}' AND\n                   gi.itemnumber = 0 AND\n                   gi.gradetype != " . GRADE_TYPE_NONE . " AND\n                   gi.iteminstance = cm.instance AND\n                   cm.instance = m.id AND\n                   md.name = '{$modulename}' AND\n                   md.id = cm.module";
    return get_records_sql($sql);
}