本文整理汇总了PHP中grade_update_mod_grades函数的典型用法代码示例。如果您正苦于以下问题:PHP grade_update_mod_grades函数的具体用法?PHP grade_update_mod_grades怎么用?PHP grade_update_mod_grades使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了grade_update_mod_grades函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_grade_update_mod_grades
public function test_grade_update_mod_grades()
{
$this->resetAfterTest(true);
// Create a course and instance of mod_assignment.
$course = $this->getDataGenerator()->create_course();
$assigndata['course'] = $course->id;
$assigndata['name'] = 'lightwork assignment';
$modinstance = self::getDataGenerator()->create_module('assignment', $assigndata);
// grade_update_mod_grades() requires 2 additional properties, cmidnumber and modname.
$cm = get_coursemodule_from_instance('assignment', $modinstance->id, 0, false, MUST_EXIST);
$modinstance->cmidnumber = $cm->id;
$modinstance->modname = 'assignment';
$this->assertTrue(grade_update_mod_grades($modinstance));
}
示例2: test_grade_update_mod_grades
public function test_grade_update_mod_grades()
{
$this->resetAfterTest(true);
// Create a broken module instance.
$modinstance = new stdClass();
$modinstance->modname = 'doesntexist';
$this->assertFalse(grade_update_mod_grades($modinstance));
// A debug message should have been generated.
$this->assertDebuggingCalled();
// Create a course and instance of mod_assign.
$course = $this->getDataGenerator()->create_course();
$assigndata['course'] = $course->id;
$assigndata['name'] = 'lightwork assignment';
$modinstance = self::getDataGenerator()->create_module('assign', $assigndata);
// Function grade_update_mod_grades() requires 2 additional properties, cmidnumber and modname.
$cm = get_coursemodule_from_instance('assign', $modinstance->id, 0, false, MUST_EXIST);
$modinstance->cmidnumber = $cm->id;
$modinstance->modname = 'assign';
$this->assertTrue(grade_update_mod_grades($modinstance));
}
示例3: clean_param
} else {
$module->name = clean_param($title, PARAM_CLEANHTML);
}
if (!empty($module->name)) {
$DB->update_record($cm->modname, $module);
$cm->name = $module->name;
\core\event\course_module_updated::create_from_cm($cm, $modcontext)->trigger();
rebuild_course_cache($cm->course);
} else {
$module->name = $cm->name;
}
// Attempt to update the grade item if relevant
$grademodule = $DB->get_record($cm->modname, array('id' => $cm->instance));
$grademodule->cmidnumber = $cm->idnumber;
$grademodule->modname = $cm->modname;
grade_update_mod_grades($grademodule);
// We need to return strings after they've been through filters for multilang
$stringoptions = new stdClass();
$stringoptions->context = $coursecontext;
echo json_encode(array('instancename' => html_entity_decode(format_string($module->name, true, $stringoptions))));
break;
}
break;
case 'course':
switch ($field) {
case 'marker':
require_capability('moodle/course:setcurrentsection', $coursecontext);
course_set_marker($course->id, $value);
break;
}
break;
示例4: grade_grab_legacy_grades
/**
* For backwards compatibility with old third-party modules, this function can
* be used to import all grades from activities with legacy grading.
* @param int $courseid or null if all courses
*/
function grade_grab_legacy_grades($courseid = null)
{
global $CFG;
if (!($mods = get_list_of_plugins('mod'))) {
error('No modules installed!');
}
if ($courseid) {
$course_sql = " AND cm.course={$courseid}";
} else {
$course_sql = "";
}
foreach ($mods as $mod) {
if ($mod == 'NEWMODULE') {
// Someone has unzipped the template, ignore it
continue;
}
if (!($module = get_record('modules', 'name', $mod))) {
//not installed
continue;
}
if (!$module->visible) {
//disabled module
continue;
}
$fullmod = $CFG->dirroot . '/mod/' . $mod;
// include the module lib once
if (file_exists($fullmod . '/lib.php')) {
include_once $fullmod . '/lib.php';
// look for modname_grades() function - old gradebook pulling function
// if present sync the grades with new grading system
$gradefunc = $mod . '_grades';
if (function_exists($gradefunc)) {
// get all instance of the activity
$sql = "SELECT a.*, cm.idnumber as cmidnumber, m.name as modname\n FROM {$CFG->prefix}{$mod} a, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m\n WHERE m.name='{$mod}' AND m.id=cm.module AND cm.instance=a.id {$course_sql}";
if ($modinstances = get_records_sql($sql)) {
foreach ($modinstances as $modinstance) {
grade_update_mod_grades($modinstance);
}
}
}
}
}
}
示例5: grade_grab_course_grades
/**
* Refetches grade data from course activities
*
* @param int $courseid The course ID
* @param string $modname Limit the grade fetch to a single module type. For example 'forum'
* @param int $userid limit the grade fetch to a single user
*/
function grade_grab_course_grades($courseid, $modname = null, $userid = 0)
{
global $CFG, $DB;
if ($modname) {
$sql = "SELECT a.*, cm.idnumber as cmidnumber, m.name as modname\n FROM {" . $modname . "} a, {course_modules} cm, {modules} m\n WHERE m.name=:modname AND m.visible=1 AND m.id=cm.module AND cm.instance=a.id AND cm.course=:courseid";
$params = array('modname' => $modname, 'courseid' => $courseid);
if ($modinstances = $DB->get_records_sql($sql, $params)) {
foreach ($modinstances as $modinstance) {
grade_update_mod_grades($modinstance, $userid);
}
}
return;
}
if (!($mods = get_plugin_list('mod'))) {
print_error('nomodules', 'debug');
}
foreach ($mods as $mod => $fullmod) {
if ($mod == 'NEWMODULE') {
// Someone has unzipped the template, ignore it
continue;
}
// include the module lib once
if (file_exists($fullmod . '/lib.php')) {
// get all instance of the activity
$sql = "SELECT a.*, cm.idnumber as cmidnumber, m.name as modname\n FROM {" . $mod . "} a, {course_modules} cm, {modules} m\n WHERE m.name=:mod AND m.visible=1 AND m.id=cm.module AND cm.instance=a.id AND cm.course=:courseid";
$params = array('mod' => $mod, 'courseid' => $courseid);
if ($modinstances = $DB->get_records_sql($sql, $params)) {
foreach ($modinstances as $modinstance) {
grade_update_mod_grades($modinstance, $userid);
}
}
}
}
}
示例6: set_coursemodule_name
/**
* Changes the course module name
*
* @param int $id course module id
* @param string $name new value for a name
* @return bool whether a change was made
*/
function set_coursemodule_name($id, $name)
{
global $CFG, $DB;
require_once $CFG->libdir . '/gradelib.php';
$cm = get_coursemodule_from_id('', $id, 0, false, MUST_EXIST);
$module = new \stdClass();
$module->id = $cm->instance;
// Escape strings as they would be by mform.
if (!empty($CFG->formatstringstriptags)) {
$module->name = clean_param($name, PARAM_TEXT);
} else {
$module->name = clean_param($name, PARAM_CLEANHTML);
}
if ($module->name === $cm->name || strval($module->name) === '') {
return false;
}
if (\core_text::strlen($module->name) > 255) {
throw new \moodle_exception('maximumchars', 'moodle', '', 255);
}
$module->timemodified = time();
$DB->update_record($cm->modname, $module);
$cm->name = $module->name;
\core\event\course_module_updated::create_from_cm($cm)->trigger();
rebuild_course_cache($cm->course, true);
// Attempt to update the grade item if relevant.
$grademodule = $DB->get_record($cm->modname, array('id' => $cm->instance));
$grademodule->cmidnumber = $cm->idnumber;
$grademodule->modname = $cm->modname;
grade_update_mod_grades($grademodule);
return true;
}
示例7: refresh_grades
/**
* Refetch grades from modules, plugins.
* @param int $userid optional, one user only
*/
function refresh_grades($userid = 0)
{
if ($this->itemtype == 'mod') {
if ($this->is_outcome_item()) {
//nothing to do
return;
}
if (!($activity = get_record($this->itemmodule, 'id', $this->iteminstance))) {
debugging("Can not find {$this->itemmodule} activity with id {$this->iteminstance}");
return;
}
if (!($cm = get_coursemodule_from_instance($this->itemmodule, $activity->id, $this->courseid))) {
debugging('Can not find course module');
return;
}
$activity->modname = $this->itemmodule;
$activity->cmidnumber = $cm->idnumber;
grade_update_mod_grades($activity);
}
}
示例8: refresh_grades
/**
* Refetch grades from modules, plugins.
*
* @param int $userid optional, limit the refetch to a single user
* @return bool Returns true on success or if there is nothing to do
*/
public function refresh_grades($userid = 0)
{
global $DB;
if ($this->itemtype == 'mod') {
if ($this->is_outcome_item()) {
//nothing to do
return true;
}
if (!($activity = $DB->get_record($this->itemmodule, array('id' => $this->iteminstance)))) {
debugging("Can not find {$this->itemmodule} activity with id {$this->iteminstance}");
return false;
}
if (!($cm = get_coursemodule_from_instance($this->itemmodule, $activity->id, $this->courseid))) {
debugging('Can not find course module');
return false;
}
$activity->modname = $this->itemmodule;
$activity->cmidnumber = $cm->idnumber;
return grade_update_mod_grades($activity, $userid);
}
return true;
}
示例9: mod_stopwatch_update_grades
function mod_stopwatch_update_grades($cm, $stopwatch, $durationarray, $gradearray)
{
global $DB, $CFG;
require_once $CFG->libdir . '/gradelib.php';
$currentgrades = mod_stopwatch_get_all_users($cm, $stopwatch);
$newgrades = array();
foreach ($currentgrades as $userid => $record) {
if ($record->id) {
$params = array('id' => $record->id);
} else {
$params = array('userid' => $userid, 'courseid' => $cm->course, 'stopwatchid' => $stopwatch->id);
}
$now = time();
$updateobj = array();
if (array_key_exists($userid, $durationarray)) {
if (empty($durationarray[$userid])) {
if (!empty($record->duration)) {
$updateobj['duration'] = 0;
}
} else {
$duration = mod_stopwatch_string_to_duration($durationarray[$userid]);
if ($record->duration != $duration) {
$updateobj['duration'] = $duration;
}
}
}
if ($stopwatch->grade && array_key_exists($userid, $gradearray)) {
$grade = empty($gradearray[$userid]) ? null : (double) $gradearray[$userid];
$existinggrade = !strlen($record->grade) ? null : (double) $record->grade;
if ($existinggrade !== $grade) {
$updateobj['grade'] = $grade;
$updateobj['timegraded'] = $now;
$newgrades[$userid] = array('userid' => $userid, 'rawgrade' => $grade);
}
}
if (empty($updateobj)) {
continue;
}
$updateobj += $params;
$updateobj['timemodified'] = $now;
if (!empty($updateobj['id'])) {
$DB->update_record('stopwatch_user', $updateobj);
} else {
$updateobj['timecreated'] = $now;
$DB->insert_record('stopwatch_user', $updateobj);
}
}
if ($newgrades) {
// Attempt to update the grade item if relevant
$grademodule = fullclone($stopwatch);
$grademodule->cmidnumber = $cm->idnumber;
$grademodule->modname = $cm->modname;
grade_update_mod_grades($grademodule);
}
}
示例10: grade_grab_course_grades
/**
* Refetches data from all course activities
* @param int $courseid
* @param string $modname
* @return success
*/
function grade_grab_course_grades($courseid, $modname = null)
{
global $CFG;
if ($modname) {
$sql = "SELECT a.*, cm.idnumber as cmidnumber, m.name as modname\n FROM {$CFG->prefix}{$modname} a, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m\n WHERE m.name='{$modname}' AND m.visible=1 AND m.id=cm.module AND cm.instance=a.id AND cm.course={$courseid}";
if ($modinstances = get_records_sql($sql)) {
foreach ($modinstances as $modinstance) {
grade_update_mod_grades($modinstance);
}
}
return;
}
if (!($mods = get_list_of_plugins('mod'))) {
error('No modules installed!');
}
foreach ($mods as $mod) {
if ($mod == 'NEWMODULE') {
// Someone has unzipped the template, ignore it
continue;
}
$fullmod = $CFG->dirroot . '/mod/' . $mod;
// include the module lib once
if (file_exists($fullmod . '/lib.php')) {
// get all instance of the activity
$sql = "SELECT a.*, cm.idnumber as cmidnumber, m.name as modname\n FROM {$CFG->prefix}{$mod} a, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m\n WHERE m.name='{$mod}' AND m.visible=1 AND m.id=cm.module AND cm.instance=a.id AND cm.course={$courseid}";
if ($modinstances = get_records_sql($sql)) {
foreach ($modinstances as $modinstance) {
grade_update_mod_grades($modinstance);
}
}
}
}
}
示例11: restore_execute
//.........这里部分代码省略.........
//Now, with backup files prior to version 2005041100,
//convert all the wiki texts in the course to markdown
if ($status && $restore->backup_version < 2005041100) {
if (!defined('RESTORE_SILENTLY')) {
echo "<li>" . get_string("convertingwikitomarkdown");
}
if (!($status = restore_convert_wiki2markdown($restore))) {
if (!defined('RESTORE_SILENTLY')) {
notify("Could not convert wiki texts to markdown!");
} else {
$errorstr = "Could not convert wiki texts to markdown!";
return false;
}
}
if (!defined('RESTORE_SILENTLY')) {
echo '</li>';
}
}
// for moodle versions before 1.9, those grades need to be converted to use the new gradebook
// this code needs to execute *after* the course_modules are sorted out
if ($status && $restore->backup_version < 2007090500) {
if (!defined('RESTORE_SILENTLY')) {
echo "<li>" . get_string("migratinggrades");
}
// we need need to worry about mods that are restored
// the others in the course are not relevent
if (!empty($restore->mods)) {
require_once $CFG->dirroot . '/lib/gradelib.php';
foreach ($restore->mods as $mod => $modtype) {
if (!empty($modtype->instances)) {
foreach ($modtype->instances as $modinstance) {
$sql = "SELECT a.*, cm.idnumber as cmidnumber, m.name as modname\n FROM {$CFG->prefix}{$mod} a, \n {$CFG->prefix}course_modules cm, \n {$CFG->prefix}modules m\n WHERE m.name='{$mod}' \n AND m.id=cm.module \n AND cm.instance=a.id \n AND cm.id= {$modinstance->restored_as_course_module}";
if ($module = get_record_sql($sql)) {
grade_update_mod_grades($module);
}
}
}
}
}
if (!defined('RESTORE_SILENTLY')) {
echo '</li>';
}
}
/*******************************************************************************
************* Restore of Roles and Capabilities happens here ******************
*******************************************************************************/
// try to restore roles even when restore is going to fail - teachers might have
// at least some role assigned - this is not correct though
$status = restore_create_roles($restore, $xml_file) && $status;
$status = restore_roles_settings($restore, $xml_file) && $status;
//Now if all is OK, update:
// - course modinfo field
// - categories table
// - add user as teacher
if ($status) {
if (!defined('RESTORE_SILENTLY')) {
echo "<li>" . get_string("checkingcourse");
}
//modinfo field
rebuild_course_cache($restore->course_id);
//categories table
$course = get_record("course", "id", $restore->course_id);
fix_course_sortorder();
// Check if the user has course update capability in the newly restored course
// there is no need to load his capabilities again, because restore_roles_settings
// would have loaded it anyway, if there is any assignments.
示例12: updateGrades
/**
* Update all of the target user's grades.
* @param int $toid User id
*/
private function updateGrades($toid, $fromid)
{
global $DB, $CFG;
require_once $CFG->libdir . '/gradelib.php';
$sql = "SELECT iteminstance, itemmodule, courseid\n FROM {grade_grades} gg\n INNER JOIN {grade_items} gi on gg.itemid = gi.id\n WHERE itemtype = 'mod' AND (gg.userid = :toid OR gg.userid = :fromid)";
$iteminstances = $DB->get_records_sql($sql, array('toid' => $toid, 'fromid' => $fromid));
foreach ($iteminstances as $iteminstance) {
if (!($activity = $DB->get_record($iteminstance->itemmodule, array('id' => $iteminstance->iteminstance)))) {
throw new \Exception("Can not find {$iteminstance->itemmodule} activity with id {$iteminstance->iteminstance}");
}
if (!($cm = get_coursemodule_from_instance($iteminstance->itemmodule, $activity->id, $iteminstance->courseid))) {
throw new \Exception('Can not find course module');
}
$activity->modname = $iteminstance->itemmodule;
$activity->cmidnumber = $cm->idnumber;
grade_update_mod_grades($activity, $toid);
}
}