本文整理汇总了PHP中grade_update函数的典型用法代码示例。如果您正苦于以下问题:PHP grade_update函数的具体用法?PHP grade_update怎么用?PHP grade_update使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了grade_update函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update_users_grade
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);
}
示例2: assignment_delete_instance
/**
* 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;
}
示例3: test_event
/**
* 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);
}
示例4: turnitintool_cron
/**
* 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);
}
}
}
}
示例5: grade_update_mod_grades
/**
* 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;
}
示例6: quiz_grade_item_delete
/**
* 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));
}
示例7: hotpot_fix_grades
//.........这里部分代码省略.........
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";
}
}
示例8: delete_moodle_assignment
/**
* 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;
}
开发者ID:sk-unikent,项目名称:moodle-mod_turnitintooltwo-1,代码行数:54,代码来源:turnitintooltwo_assignment.class.php
示例9: assignment_grade_item_delete
/**
* 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));
}
示例10: assign_grade_item_update
/**
* 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);
}
示例11: workshop_grade_item_update
/**
* 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);
}
示例12: delete
/**
* 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;
}
示例13: generate_grades
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;
}
示例14: game_grade_item_delete
/**
* 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));
}
示例15: assign_grade_item_update
/**
* 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);
}