public function update_users_grade($userids) { $grades = array(); foreach ($userids as $userid) { $grades[$userid] = new stdClass(); $grades[$userid]->userid = $userid; $grades[$userid]->rawgrade = att_calc_user_grade_fraction($this->get_user_grade($userid), $this->get_user_max_grade($userid)) * $this->grade; } return grade_update('mod/attendance', $this->course->id, 'mod', 'attendance', $this->id, 0, $grades); }
/** * Deletes an assignment instance * * @param $id */ function assignment_delete_instance($id) { global $CFG, $DB; if (!($assignment = $DB->get_record('assignment', array('id' => $id)))) { return false; } $result = true; // Now get rid of all files $fs = get_file_storage(); if ($cm = get_coursemodule_from_instance('assignment', $assignment->id)) { $context = context_module::instance($cm->id); $fs->delete_area_files($context->id); } if (!$DB->delete_records('assignment_submissions', array('assignment' => $assignment->id))) { $result = false; } if (!$DB->delete_records('event', array('modulename' => 'assignment', 'instance' => $assignment->id))) { $result = false; } if (!$DB->delete_records('assignment', array('id' => $assignment->id))) { $result = false; } grade_update('mod/assignment', $assignment->course, 'mod', 'assignment', $assignment->id, 0, NULL, array('deleted' => 1)); return $result; }
/** * Tests the event details. */ public function test_event() { global $CFG; require_once "{$CFG->libdir}/gradelib.php"; $this->resetAfterTest(); $course = $this->getDataGenerator()->create_course(); $user = $this->getDataGenerator()->create_user(); $quiz = $this->getDataGenerator()->create_module('quiz', array('course' => $course->id)); // Create a grade item for the quiz. $grade = array(); $grade['userid'] = $user->id; $grade['rawgrade'] = 50; grade_update('mod/quiz', $course->id, 'mod', 'quiz', $quiz->id, 0, $grade); // Get the grade item and override it. $gradeitem = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => 'quiz', 'iteminstance' => $quiz->id, 'courseid' => $course->id)); $gradeitem->update_final_grade($user->id, 10, 'gradebook'); // Get the grade_grade object. $gradegrade = new grade_grade(array('userid' => $user->id, 'itemid' => $gradeitem->id), true); $gradegrade->grade_item = $gradeitem; // Trigger the event. $sink = $this->redirectEvents(); course_delete_module($quiz->cmid); $events = $sink->get_events(); $event = reset($events); $sink->close(); // Check the event details are correct. $grade = $event->get_grade(); $this->assertInstanceOf('grade_grade', $grade); $this->assertInstanceOf('\\core\\event\\grade_deleted', $event); $this->assertEquals(context_course::instance($course->id), $event->get_context()); $this->assertSame($event->objecttable, 'grade_grades'); $this->assertEquals($event->objectid, $gradegrade->id); $this->assertEquals($event->other['itemid'], $gradeitem->id); $this->assertTrue($event->other['overridden']); $this->assertEquals(10, $event->other['finalgrade']); $this->assertEventContextNotUsed($event); $this->assertEquals($gradegrade->id, $grade->id); }
/** * A Standard Moodle function that moodle executes at the time the cron runs */ function turnitintool_cron() { global $CFG; @(include_once $CFG->dirroot . "/lib/gradelib.php"); if (function_exists('grade_update')) { // Get assignment that needs updating. if ($turnitintool = turnitintool_get_record('turnitintool', "needs_updating", 1, "", "", "", "", '*')) { $cm = get_coursemodule_from_instance("turnitintool", $turnitintool->id, $turnitintool->course); $users = turnitintool_get_records('turnitintool_submissions', 'turnitintoolid', $turnitintool->id); //Loop through every submission for this assignment and update the grades. foreach ($users as $user) { //Create a user ID object to be passed in. $userid = new stdClass(); $userid->id = $user->userid; $grades = turnitintool_buildgrades($turnitintool, $userid); $params['idnumber'] = $cm->idnumber; grade_update('mod/turnitintool', $turnitintool->course, 'mod', 'turnitintool', $turnitintool->id, 0, $grades, $params); } } } }
/** * Force full update of module grades in central gradebook - works for both legacy and converted activities. * @param object $modinstance object with extra cmidnumber and modname property * @return boolean success */ function grade_update_mod_grades($modinstance, $userid = 0) { global $CFG; $fullmod = $CFG->dirroot . '/mod/' . $modinstance->modname; if (!file_exists($fullmod . '/lib.php')) { debugging('missing lib.php file in module'); return false; } include_once $fullmod . '/lib.php'; // does it use legacy grading? $gradefunc = $modinstance->modname . '_grades'; $updategradesfunc = $modinstance->modname . '_update_grades'; $updateitemfunc = $modinstance->modname . '_grade_item_update'; if (function_exists($gradefunc)) { // legacy module - not yet converted if ($oldgrades = $gradefunc($modinstance->id)) { $grademax = $oldgrades->maxgrade; $scaleid = NULL; if (!is_numeric($grademax)) { // scale name is provided as a string, try to find it if (!($scale = get_record('scale', 'name', $grademax))) { debugging('Incorrect scale name! name:' . $grademax); return false; } $scaleid = $scale->id; } if (!($grade_item = grade_get_legacy_grade_item($modinstance, $grademax, $scaleid))) { debugging('Can not get/create legacy grade item!'); return false; } $grades = array(); foreach ($oldgrades->grades as $uid => $usergrade) { if ($userid and $uid != $userid) { continue; } $grade = new object(); $grade->userid = $uid; if ($usergrade == '-') { // no grade $grade->rawgrade = null; } else { if ($scaleid) { // scale in use, words used $gradescale = explode(",", $scale->scale); $grade->rawgrade = array_search($usergrade, $gradescale) + 1; } else { // good old numeric value $grade->rawgrade = $usergrade; } } $grades[] = $grade; } grade_update('legacygrab', $grade_item->courseid, $grade_item->itemtype, $grade_item->itemmodule, $grade_item->iteminstance, $grade_item->itemnumber, $grades); } } else { if (function_exists($updategradesfunc) and function_exists($updateitemfunc)) { //new grading supported, force updating of grades $updateitemfunc($modinstance); $updategradesfunc($modinstance, $userid); } else { // mudule does not support grading?? } } return true; }
/** * Delete grade item for given quiz * * @param object $quiz object * @return object quiz */ function quiz_grade_item_delete($quiz) { global $CFG; require_once $CFG->libdir . '/gradelib.php'; return grade_update('mod/quiz', $quiz->course, 'mod', 'quiz', $quiz->id, 0, NULL, array('deleted' => 1)); }
function hotpot_fix_grades($print = true, $usehotpotname = 1) { // if hotpot name and grade are different ... // $usehotpotname=0: set hotpot name equal to grade name // $usehotpotname=1: set grade name equal to hotpot name global $CFG, $db; require_once $CFG->dirroot . '/lib/gradelib.php'; if (!($module = get_record('modules', 'name', 'hotpot'))) { if ($print) { print_error('error_nohotpot', 'hotpot'); } else { debugging(get_string('error_nohotpot', 'hotpot'), DEBUG_DEVELOPER); } } if (!($hotpots = get_records('hotpot'))) { $hotpots = array(); } if (!($gradeitems = get_records_select('grade_items', "itemtype='mod' AND itemmodule='hotpot'"))) { $gradeitems = array(); } $success = '<font color="green">OK</font>' . "\n"; $failure = '<font color="red">FAILED</font>' . "\n"; $not = '<font color="red">NOT</font>' . "\n"; $new = get_string('newvalue', 'hotpot'); $old = get_string('oldvalue', 'hotpot'); $hotpots_no_grade = array(); // hotpots without a grade item $hotpots_no_weighting = array(); // hotpots with zero grade limit/weighting $gradeitems_wrong_name = array(); // grade items that have a different name from their hotpot $gradeitems_no_hotpot = array(); // grade items without a hotpot $gradeitems_no_idnumber = array(); // grade items without an idnumber (= course_modules id) foreach (array_keys($gradeitems) as $id) { $hotpotid = $gradeitems[$id]->iteminstance; if (array_key_exists($hotpotid, $hotpots)) { $hotpots[$hotpotid]->gradeitem =& $gradeitems[$id]; if (empty($gradeitems[$id]->idnumber)) { $gradeitems_no_idnumber[$id] =& $gradeitems[$id]; } if ($gradeitems[$id]->itemname != $hotpots[$hotpotid]->name) { $gradeitems_wrong_name[$id] =& $gradeitems[$id]; } } else { $gradeitems_no_hotpot[$id] =& $gradeitems[$id]; } } foreach ($hotpots as $id => $hotpot) { if ($hotpot->grade == 0) { // no grade item required, because grade is always 0 // transfer this hotpot to "no_weighting" array $hotpots_no_weighting[$id] =& $hotpots[$id]; if (isset($hotpot->gradeitem)) { // grade item not required $gradeitemid = $hotpot->gradeitem->id; $gradeitems_no_hotpot[$gradeitemid] =& $gradeitems[$gradeitemid]; unset($hotpots[$id]->gradeitem); } } else { if (empty($hotpot->gradeitem)) { // grade item required, but missing $hotpots_no_grade[$id] =& $hotpots[$id]; } } } $output = ''; $start_list = false; $count_idnumber_updated = 0; $count_idnumber_notupdated = 0; foreach ($gradeitems_no_idnumber as $id => $gradeitem) { $idnumber = get_field('course_modules', 'idnumber', 'module', $module->id, 'instance', $gradeitem->iteminstance); if (!$idnumber) { unset($gradeitems_no_idnumber[$id]); continue; } if (!$start_list) { $start_list = true; if ($print) { print '<ul>' . "\n"; } } if ($print) { $a = 'grade_item(id=' . $id . ').idnumber: ' . $new . '=' . $idnumber; print '<li>' . get_string('updatinga', '', $a) . ' ... '; } if (set_field('grade_items', 'idnumber', addslashes($idnumber), 'id', $id)) { $count_idnumber_updated++; if ($print) { print $success; } } else { $count_idnumber_notupdated++; if ($print) { print $failure; } } if ($print) { print '</li>' . "\n"; } } if ($start_list) { if ($print) { print '</ul>' . "\n"; } } $start_list = false; $count_name_updated = 0; $count_name_notupdated = 0; foreach ($gradeitems_wrong_name as $id => $gradeitem) { $gradename = $gradeitem->itemname; $hotpotid = $gradeitem->iteminstance; $hotpotname = $hotpots[$hotpotid]->name; if (!$start_list) { $start_list = true; if ($print) { print '<ul>' . "\n"; } } if ($usehotpotname) { if ($print) { $a = 'grade_item(id=' . $id . ').name: ' . $old . '=' . $gradename . ' ' . $new . '=' . $hotpotname; print '<li>' . get_string('updatinga', '', $a) . ' ... '; } $set_field = set_field('grade_items', 'itemname', addslashes($hotpotname), 'id', $id); } else { if ($print) { $a = 'hotpot(id=' . $hotpotid . ').name: ' . $old . '=' . $hotpotname . ' ' . $new . '=' . $gradename; print '<li>' . get_string('updatinga', '', $a) . ' ... '; } $set_field = set_field('hotpot', 'name', addslashes($gradename), 'id', $hotpotid); } if ($set_field) { $count_name_updated++; if ($print) { print $success; } } else { $count_name_notupdated++; if ($print) { print $failure; } } if ($print) { print '</li>' . "\n"; } } if ($start_list) { if ($print) { print '</ul>' . "\n"; } } $start_list = false; $count_deleted = 0; $count_notdeleted = 0; if ($ids = implode(',', array_keys($gradeitems_no_hotpot))) { $count = count($gradeitems_no_hotpot); if (!$start_list) { $start_list = true; if ($print) { print '<ul>' . "\n"; } } if ($print) { print '<li>deleting ' . $count . ' grade items with no hotpots ... '; } if (delete_records_select('grade_items', "id in ({$ids})")) { $count_deleted = $count; if ($print) { print $success; } } else { $count_notdeleted = $count; if ($print) { print $failure; } } if ($print) { print '</li>' . "\n"; } } if ($start_list) { if ($print) { print '</ul>' . "\n"; } } $start_list = false; $count_added = 0; $count_notadded = 0; foreach ($hotpots_no_grade as $hotpotid => $hotpot) { $params = array('itemname' => $hotpot->name); if ($coursemoduleid = get_field('course_modules', 'id', 'module', $module->id, 'instance', $hotpotid)) { $params['idnumber'] = $coursemoduleid; } if ($hotpot->grade > 0) { $params['gradetype'] = GRADE_TYPE_VALUE; $params['grademax'] = $hotpot->grade / 100; $params['grademin'] = 0; } else { // no grade item needed - shouldn't happen $params['gradetype'] = GRADE_TYPE_NONE; } if (!$start_list) { $start_list = true; if ($print) { print '<ul>' . "\n"; } } if ($print) { print '<li>adding grade item for hotpot (id=' . $hotpot->id . ' name=' . $hotpot->name . ') ... '; } if (grade_update('mod/hotpot', $hotpot->course, 'mod', 'hotpot', $hotpotid, 0, null, $params) == GRADE_UPDATE_OK) { $count_added++; if ($print) { print $success; } } else { $count_notadded++; if ($print) { print $failure; } } if ($print) { print '</li>' . "\n"; } } if ($start_list) { if ($print) { print '</ul>' . "\n"; } } if ($print) { print "<ul>\n"; print " <li>" . count($hotpots) . " HotPots were found</li>\n"; if ($count = count($hotpots_no_weighting)) { print " <li>{$count} hotpot(s) have zero grade limit</li>\n"; } print " <li>" . count($gradeitems) . " grade items were found</li>\n"; if ($count = count($gradeitems_no_idnumber)) { if ($count_idnumber_updated) { print " <li>{$count_idnumber_updated} / {$count} grade item idnumber(s) were successfully updated</li>\n"; } if ($count_idnumber_notupdated) { print " <li>{$count_idnumber_notupdated} / {$count} grade item idnumber(s) could {$not} be updated !!</li>\n"; } } if ($count = count($gradeitems_wrong_name)) { if ($count_name_updated) { print " <li>{$count_name_updated} / {$count} grade item name(s) were successfully updated</li>\n"; } if ($count_name_notupdated) { print " <li>{$count_name_notupdated} / {$count} grade item name(s) could {$not} be updated !!</li>\n"; } } if ($count = count($gradeitems_no_hotpot)) { if ($count_deleted) { print " <li>{$count_deleted} / {$count} grade item(s) were successfully deleted</li>\n"; } if ($count_notdeleted) { print " <li>{$count_notdeleted} / {$count} grade item(s) could {$not} be deleted !!</li>\n"; } } if ($count = count($hotpots_no_grade)) { if ($count_added) { print " <li>{$count_added} / {$count} grade item(s) were successfully added</li>\n"; } if ($count_notadded) { print " <li>{$count_notadded} / {$count} grade item(s) could {$not} be added !!</li>\n"; } } print "</ul>\n"; } }
/** * Delete the assignment, parts and associated event from Moodle (not from Turnitin) * * @global type $CFG * @global type $DB * @param int $id instanced id of the turnitin assignment * @return boolean */ public function delete_moodle_assignment($id) { global $CFG, $DB; $result = true; // Get the Moodle Turnitintool (Assignment) Object. if (!($turnitintooltwo = $DB->get_record("turnitintooltwo", array("id" => $id)))) { return false; } // Get Current Moodle Turnitin Tool parts and delete them. $parts = $this->get_parts($id); foreach ($parts as $part) { $this->delete_moodle_assignment_part($id, $part->id); turnitintooltwo_activitylog("Deleted assignment part - id (" . $part->id . " - " . $part->tiiassignid . ")", "REQUEST"); } // Delete events for this assignment / part. $dbselect = " modulename = ? AND instance = ? "; // Moodle pre 2.5 on SQL Server errors here as queries weren't allowed on ntext fields, the relevant fields // are nvarchar from 2.6 onwards so we have to cast the relevant fields in pre 2.5 SQL Server setups. if ($CFG->branch <= 25 && $CFG->dbtype == "sqlsrv") { $dbselect = " CAST(modulename AS nvarchar(max)) = ? AND instance = ? "; } $DB->delete_records_select('event', $dbselect, array('turnitintooltwo', $id)); if (!$DB->delete_records("turnitintooltwo", array("id" => $id))) { $result = false; } turnitintooltwo_activitylog("Deleted tool instance - id (" . $id . ")", "REQUEST"); // General Clean Up. if ($oldcourses = $DB->get_records("turnitintooltwo_courses")) { foreach ($oldcourses as $oldcourse) { // Delete the Turnitin Classes data if the Moodle courses no longer exists. if (!$DB->count_records("course", array("id" => $oldcourse->courseid)) > 0) { $DB->delete_records("turnitintooltwo_courses", array("courseid" => $oldcourse->courseid)); } // Delete the Turnitin Class data if no more turnitin assignments exist in it. if (!$DB->count_records("turnitintooltwo", array("course" => $oldcourse->courseid)) > 0) { $DB->delete_records("turnitintooltwo_courses", array("courseid" => $oldcourse->courseid, "course_type" => "TT")); } turnitintooltwo_activitylog("Old Moodle Course deleted - id (" . $oldcourse->courseid . " - " . $oldcourse->turnitin_cid . ")", "REQUEST"); } } // Define grade settings. @(include_once $CFG->libdir . "/gradelib.php"); $params = array('deleted' => 1); grade_update('mod/turnitintooltwo', $turnitintooltwo->course, 'mod', 'turnitintooltwo', $id, 0, null, $params); return $result; }
/** * Delete grade item for given assignment * * @param object $assignment object * @return object assignment */ function assignment_grade_item_delete($assignment) { global $CFG; require_once($CFG->libdir.'/gradelib.php'); if (!isset($assignment->courseid)) { $assignment->courseid = $assignment->course; } return grade_update('mod/assignment', $assignment->courseid, 'mod', 'assignment', $assignment->id, 0, NULL, array('deleted'=>1)); }
/** * Delete grade item for given lesson * * @param object $lesson object * @return object lesson */ function lesson_grade_item_delete($lesson) { global $CFG; require_once $CFG->libdir . '/gradelib.php'; return grade_update('mod/lesson', $lesson->course, 'mod', 'lesson', $lesson->id, 0, NULL, array('deleted' => 1)); }
/** * Create grade item for given assignment * * @param stdClass $assign record with extra cmidnumber * @param array $grades optional array/object of grade(s); 'reset' means reset grades in gradebook * @return int 0 if ok, error code otherwise */ function assign_grade_item_update($assign, $grades = NULL) { global $CFG; require_once $CFG->libdir . '/gradelib.php'; if (!isset($assign->courseid)) { $assign->courseid = $assign->course; } $params = array('itemname' => $assign->name, 'idnumber' => $assign->cmidnumber); if ($assign->grade > 0) { $params['gradetype'] = GRADE_TYPE_VALUE; $params['grademax'] = $assign->grade; $params['grademin'] = 0; } else { if ($assign->grade < 0) { $params['gradetype'] = GRADE_TYPE_SCALE; $params['scaleid'] = -$assign->grade; } else { $params['gradetype'] = GRADE_TYPE_TEXT; // allow text comments only } } if ($grades === 'reset') { $params['reset'] = true; $grades = NULL; } return grade_update('mod/assign', $assign->courseid, 'mod', 'assign', $assign->id, 0, $grades, $params); }
/** * Creates or updates grade items for the give workshop instance * * Needed by grade_update_mod_grades() in lib/gradelib.php. Also used by * {@link workshop_update_grades()}. * * @param stdClass $workshop instance object with extra cmidnumber property * @param stdClass $submissiongrades data for the first grade item * @param stdClass $assessmentgrades data for the second grade item * @return void */ function workshop_grade_item_update(stdclass $workshop, $submissiongrades=null, $assessmentgrades=null) { global $CFG; require_once($CFG->libdir.'/gradelib.php'); $a = new stdclass(); $a->workshopname = clean_param($workshop->name, PARAM_NOTAGS); $item = array(); $item['itemname'] = get_string('gradeitemsubmission', 'workshop', $a); $item['gradetype'] = GRADE_TYPE_VALUE; $item['grademax'] = $workshop->grade; $item['grademin'] = 0; grade_update('mod/workshop', $workshop->course, 'mod', 'workshop', $workshop->id, 0, $submissiongrades , $item); $item = array(); $item['itemname'] = get_string('gradeitemassessment', 'workshop', $a); $item['gradetype'] = GRADE_TYPE_VALUE; $item['grademax'] = $workshop->gradinggrade; $item['grademin'] = 0; grade_update('mod/workshop', $workshop->course, 'mod', 'workshop', $workshop->id, 1, $assessmentgrades, $item); }
/** * Deletes this lesson from the database */ public function delete() { global $CFG, $DB; require_once($CFG->libdir.'/gradelib.php'); require_once($CFG->dirroot.'/calendar/lib.php'); $DB->delete_records("lesson", array("id"=>$this->properties->id));; $DB->delete_records("lesson_pages", array("lessonid"=>$this->properties->id)); $DB->delete_records("lesson_answers", array("lessonid"=>$this->properties->id)); $DB->delete_records("lesson_attempts", array("lessonid"=>$this->properties->id)); $DB->delete_records("lesson_grades", array("lessonid"=>$this->properties->id)); $DB->delete_records("lesson_timer", array("lessonid"=>$this->properties->id)); $DB->delete_records("lesson_branch", array("lessonid"=>$this->properties->id)); $DB->delete_records("lesson_high_scores", array("lessonid"=>$this->properties->id)); if ($events = $DB->get_records('event', array("modulename"=>'lesson', "instance"=>$this->properties->id))) { foreach($events as $event) { $event = calendar_event::load($event); $event->delete(); } } grade_update('mod/lesson', $this->properties->course, 'mod', 'lesson', $this->properties->id, 0, NULL, array('deleted'=>1)); return true; }
public function generate_grades($course_users, $courses, $modules) { global $CFG, $DB, $USER; /** * ASSIGNMENT GRADES GENERATION */ if ($this->get('assignment_grades') && isset($modules['assignment'])) { $grades_count = 0; foreach ($course_users as $courseid => $userid_array) { foreach ($userid_array as $userid) { foreach ($modules['assignment'] as $assignment) { if (in_array($assignment->course, $courses)) { $maxgrade = $assignment->grade; $random_grade = rand(0, $maxgrade); $grade = new stdClass(); $grade->assignment = $assignment->id; $grade->userid = $userid; $grade->grade = $random_grade; $grade->rawgrade = $random_grade; $grade->teacher = $USER->id; $grade->submissioncomment = 'comment'; $DB->insert_record('assignment_submissions', $grade); grade_update('mod/assignment', $assignment->course, 'mod', 'assignment', $assignment->id, 0, $grade); $this->verbose("A grade ({$random_grade}) has been given to user {$userid} " . "for assignment {$assignment->id}"); $grades_count++; } } } } if ($grades_count > 0) { $this->verbose("{$grades_count} assignment grades have been generated.{$this->eolchar}"); } } /** * QUIZ GRADES GENERATION */ if ($this->get('quiz_grades') && isset($modules['quiz'])) { $grades_count = 0; foreach ($course_users as $userid => $courses) { foreach ($modules['quiz'] as $quiz) { if (in_array($quiz->course, $courses)) { $maxgrade = $quiz->grade; $random_grade = rand(0, $maxgrade); $grade = new stdClass(); $grade->quiz = $quiz->id; $grade->userid = $userid; $grade->grade = $random_grade; $grade->rawgrade = $random_grade; $DB->insert_record('quiz_grades', $grade); grade_update('mod/quiz', $courseid, 'mod', 'quiz', $quiz->id, 0, $grade); $this->verbose("A grade ({$random_grade}) has been given to user {$userid} for quiz {$quiz->id}"); $grades_count++; } } } if ($grades_count > 0 && !$this->get('quiet')) { echo "{$grades_count} quiz grades have been generated.{$this->eolchar}"; } } return null; }
/** * Delete grade item for given game * * @param object $game object * @return object game */ function game_grade_item_delete($game) { global $CFG; if (file_exists($CFG->libdir . '/gradelib.php')) { require_once $CFG->libdir . '/gradelib.php'; } else { return; } return grade_update('mod/game', $game->course, 'mod', 'game', $game->id, 0, NULL, array('deleted' => 1)); }
/** * Create grade item for given assignment. * * @param stdClass $assign record with extra cmidnumber * @param array $grades optional array/object of grade(s); 'reset' means reset grades in gradebook * @return int 0 if ok, error code otherwise */ function assign_grade_item_update($assign, $grades = null) { global $CFG; require_once $CFG->libdir . '/gradelib.php'; if (!isset($assign->courseid)) { $assign->courseid = $assign->course; } $params = array('itemname' => $assign->name, 'idnumber' => $assign->cmidnumber); // Check if feedback plugin for gradebook is enabled, if yes then // gradetype = GRADE_TYPE_TEXT else GRADE_TYPE_NONE. $gradefeedbackenabled = false; if (isset($assign->gradefeedbackenabled)) { $gradefeedbackenabled = $assign->gradefeedbackenabled; } else { if ($assign->grade == 0) { // Grade feedback is needed only when grade == 0. require_once $CFG->dirroot . '/mod/assign/locallib.php'; $mod = get_coursemodule_from_instance('assign', $assign->id, $assign->courseid); $cm = context_module::instance($mod->id); $assignment = new assign($cm, null, null); $gradefeedbackenabled = $assignment->is_gradebook_feedback_enabled(); } } if ($assign->grade > 0) { $params['gradetype'] = GRADE_TYPE_VALUE; $params['grademax'] = $assign->grade; $params['grademin'] = 0; } else { if ($assign->grade < 0) { $params['gradetype'] = GRADE_TYPE_SCALE; $params['scaleid'] = -$assign->grade; } else { if ($gradefeedbackenabled) { // $assign->grade == 0 and feedback enabled. $params['gradetype'] = GRADE_TYPE_TEXT; } else { // $assign->grade == 0 and no feedback enabled. $params['gradetype'] = GRADE_TYPE_NONE; } } } if ($grades === 'reset') { $params['reset'] = true; $grades = null; } return grade_update('mod/assign', $assign->courseid, 'mod', 'assign', $assign->id, 0, $grades, $params); }
/** * Delete grade item for given facetoface * * @param object $facetoface object * @return object facetoface */ function facetoface_grade_item_delete($facetoface) { $retcode = grade_update('mod/facetoface', $facetoface->course, 'mod', 'facetoface', $facetoface->id, 0, NULL, array('deleted' => 1)); return ($retcode === GRADE_UPDATE_OK); }
/** * Delete grade item for given attendance * * @param object $attendance object * @return object attendance */ function attendance_grade_item_delete($attendance) { global $CFG; require_once $CFG->libdir . '/gradelib.php'; if (!isset($attendance->courseid)) { $attendance->courseid = $attendance->course; } return grade_update('mod/attendance', $attendance->courseid, 'mod', 'attendance', $attendance->id, 0, null, array('deleted' => 1)); }
/** * Delete grade item for given data * * @global object * @param object $data object * @return object grade_item */ function data_grade_item_delete($data) { global $CFG; require_once($CFG->libdir.'/gradelib.php'); return grade_update('mod/data', $data->course, 'mod', 'data', $data->id, 0, NULL, array('deleted'=>1)); }
/** * Delete all grades from the gradebook for this assignment * * @return bool */ private function delete_grades() { global $CFG; return grade_update('mod/assign', $this->get_course()->id, 'mod', 'assign', $this->get_instance()->id, 0, NULL, array('deleted'=>1)) == GRADE_UPDATE_OK; }
/** * Deletes this lesson from the database */ public function delete() { global $CFG, $DB; require_once $CFG->libdir . '/gradelib.php'; require_once $CFG->dirroot . '/calendar/lib.php'; $cm = get_coursemodule_from_instance('lesson', $this->properties->id, $this->properties->course); $context = context_module::instance($cm->id); $DB->delete_records("lesson", array("id" => $this->properties->id)); $DB->delete_records("lesson_pages", array("lessonid" => $this->properties->id)); $DB->delete_records("lesson_answers", array("lessonid" => $this->properties->id)); $DB->delete_records("lesson_attempts", array("lessonid" => $this->properties->id)); $DB->delete_records("lesson_grades", array("lessonid" => $this->properties->id)); $DB->delete_records("lesson_timer", array("lessonid" => $this->properties->id)); $DB->delete_records("lesson_branch", array("lessonid" => $this->properties->id)); $DB->delete_records("lesson_high_scores", array("lessonid" => $this->properties->id)); if ($events = $DB->get_records('event', array("modulename" => 'lesson', "instance" => $this->properties->id))) { foreach ($events as $event) { $event = calendar_event::load($event); $event->delete(); } } // Delete files associated with this module. $fs = get_file_storage(); $fs->delete_area_files($context->id); grade_update('mod/lesson', $this->properties->course, 'mod', 'lesson', $this->properties->id, 0, null, array('deleted' => 1)); return true; }
/** * Delete all grades from the gradebook for this assignment. * * @return bool */ protected function delete_grades() { global $CFG; $result = grade_update('mod/assign', $this->get_course()->id, 'mod', 'assign', $this->get_instance()->id, 0, null, array('deleted' => 1)); return $result == GRADE_UPDATE_OK; }
/** * Delete grade item for given glossary * * @global object * @param object $glossary object */ function glossary_grade_item_delete($glossary) { global $CFG; require_once($CFG->libdir.'/gradelib.php'); return grade_update('mod/glossary', $glossary->course, 'mod', 'glossary', $glossary->id, 0, NULL, array('deleted'=>1)); }
/** * Delete grade item for given forum * * @category grade * @param stdClass $forum Forum object * @return grade_item */ function forum_grade_item_delete($forum) { global $CFG; require_once($CFG->libdir.'/gradelib.php'); return grade_update('mod/forum', $forum->course, 'mod', 'forum', $forum->id, 0, NULL, array('deleted'=>1)); }
/** * Delete grade item for given basiclti * * @category grade * @param object $basiclti object * @return object basiclti */ function lti_grade_item_delete($basiclti) { global $CFG; require_once $CFG->libdir . '/gradelib.php'; return grade_update('mod/lti', $basiclti->course, 'mod', 'lti', $basiclti->id, 0, null, array('deleted' => 1)); }
function local_att_update_all_users_grades($attid, $semesterinfo, $context, $classinfo, $att) { $grades = array(); $userids = array_keys($att->get_class_users($context, 'local/attendance:canbelisted', 0, 'u.id')); $statuses = local_att_get_statuses($attid); $gradebook_maxgrade = local_att_get_gradebook_maxgrade($attid); foreach ($userids as $userid) { $grade = new stdClass; $grade->userid = $userid; $userstatusesstat = local_att_get_user_statuses_stat($attid, $semesterinfo->startdate, $userid, $classinfo); $usertakensesscount = local_att_get_user_taken_sessions_count($attid, $semesterinfo->startdate, $userid, $classinfo); $usergrade = local_att_get_user_grade($userstatusesstat, $statuses); $usermaxgrade = local_att_get_user_max_grade($usertakensesscount, $statuses); $grade->rawgrade = local_att_calc_user_grade_fraction($usergrade, $usermaxgrade) * $gradebook_maxgrade; $grades[$userid] = $grade; } return grade_update('local/attendance', $attid, 'local', 'attendance', $attid, 0, $grades); }
function checklist_grade_item_update($checklist, $grades = null) { global $CFG; if (!function_exists('grade_update')) { //workaround for buggy PHP versions require_once $CFG->libdir . '/gradelib.php'; } if (!isset($checklist->courseid)) { $checklist->courseid = $checklist->course; } $params = array('itemname' => $checklist->name); $params['gradetype'] = GRADE_TYPE_VALUE; $params['grademax'] = $checklist->maxgrade; $params['grademin'] = 0; if ($grades === 'reset') { $params['reset'] = true; $grades = null; } return grade_update('mod/checklist', $checklist->courseid, 'mod', 'checklist', $checklist->id, 0, $grades, $params); }
/** * Update content grades in the gradebook * * Needed by {@link grade_update_mod_grades()}. * * @param stdClass $content instance object with extra cmidnumber and modname property * @param int $userid update grade of specific user only, 0 means all participants */ function content_update_grades(stdClass $content, $userid = 0) { global $CFG, $DB; require_once $CFG->libdir . '/gradelib.php'; // Populate array of grade objects indexed by userid. $grades = array(); grade_update('mod/content', $content->course, 'mod', 'content', $content->id, 0, $grades); }
/** * Create grade item for given questionnaire * * @param object $questionnaire object with extra cmidnumber * @param mixed optional array/object of grade(s); 'reset' means reset grades in gradebook * @return int 0 if ok, error code otherwise */ function questionnaire_grade_item_update($questionnaire, $grades = null) { global $CFG; if (!function_exists('grade_update')) { // Workaround for buggy PHP versions. require_once $CFG->libdir . '/gradelib.php'; } if (!isset($questionnaire->courseid)) { $questionnaire->courseid = $questionnaire->course; } if ($questionnaire->cmidnumber != '') { $params = array('itemname' => $questionnaire->name, 'idnumber' => $questionnaire->cmidnumber); } else { $params = array('itemname' => $questionnaire->name); } if ($questionnaire->grade > 0) { $params['gradetype'] = GRADE_TYPE_VALUE; $params['grademax'] = $questionnaire->grade; $params['grademin'] = 0; } else { if ($questionnaire->grade < 0) { $params['gradetype'] = GRADE_TYPE_SCALE; $params['scaleid'] = -$questionnaire->grade; } else { if ($questionnaire->grade == 0) { // No Grade..be sure to delete the grade item if it exists. $grades = null; $params = array('deleted' => 1); } else { $params = null; // Allow text comments only. } } } if ($grades === 'reset') { $params['reset'] = true; $grades = null; } return grade_update('mod/questionnaire', $questionnaire->courseid, 'mod', 'questionnaire', $questionnaire->id, 0, $grades, $params); }
/** * Delete grade item for given scorm * * @param object $scorm object * @return object grade_item */ function scorm_grade_item_delete($scorm) { global $CFG; require_once $CFG->libdir . '/gradelib.php'; return grade_update('mod/scorm', $scorm->course, 'mod', 'scorm', $scorm->id, 0, NULL, array('deleted' => 1)); }