2007-04-23 09:00:32 +00:00
|
|
|
<?php // $Id$
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// NOTICE OF COPYRIGHT //
|
|
|
|
// //
|
|
|
|
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
2007-09-14 08:54:46 +00:00
|
|
|
// http://moodle.org //
|
2007-04-23 09:00:32 +00:00
|
|
|
// //
|
2007-09-14 08:54:46 +00:00
|
|
|
// Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
|
2007-04-23 09:00:32 +00:00
|
|
|
// //
|
|
|
|
// This program is free software; you can redistribute it and/or modify //
|
|
|
|
// it under the terms of the GNU General Public License as published by //
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or //
|
|
|
|
// (at your option) any later version. //
|
|
|
|
// //
|
|
|
|
// This program is distributed in the hope that it will be useful, //
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
|
|
|
// GNU General Public License for more details: //
|
|
|
|
// //
|
|
|
|
// http://www.gnu.org/copyleft/gpl.html //
|
|
|
|
// //
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
2008-01-09 18:19:42 +00:00
|
|
|
* Library of functions for gradebook - both public and internal
|
2007-04-23 09:00:32 +00:00
|
|
|
*
|
|
|
|
* @author Moodle HQ developers
|
|
|
|
* @version $Id$
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
|
|
|
* @package moodlecore
|
|
|
|
*/
|
|
|
|
|
2007-09-14 08:54:46 +00:00
|
|
|
require_once($CFG->libdir . '/grade/constants.php');
|
2007-07-13 07:05:04 +00:00
|
|
|
|
2007-04-27 07:28:41 +00:00
|
|
|
require_once($CFG->libdir . '/grade/grade_category.php');
|
|
|
|
require_once($CFG->libdir . '/grade/grade_item.php');
|
2007-07-19 08:15:19 +00:00
|
|
|
require_once($CFG->libdir . '/grade/grade_grade.php');
|
2007-05-01 05:45:54 +00:00
|
|
|
require_once($CFG->libdir . '/grade/grade_scale.php');
|
2007-05-03 08:51:48 +00:00
|
|
|
require_once($CFG->libdir . '/grade/grade_outcome.php');
|
2007-04-26 08:29:30 +00:00
|
|
|
|
2008-01-09 18:19:42 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
///// Start of public API for communication with modules/blocks /////
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
2007-06-05 22:58:37 +00:00
|
|
|
|
2007-06-07 08:34:04 +00:00
|
|
|
/**
|
|
|
|
* Submit new or update grade; update/create grade_item definition. Grade must have userid specified,
|
2007-06-20 23:06:29 +00:00
|
|
|
* rawgrade and feedback with format are optional. rawgrade NULL means 'Not graded', missing property
|
2007-06-07 08:34:04 +00:00
|
|
|
* or key means do not change existing.
|
2007-06-09 14:16:20 +00:00
|
|
|
*
|
2007-06-07 08:34:04 +00:00
|
|
|
* Only following grade item properties can be changed 'itemname', 'idnumber', 'gradetype', 'grademax',
|
2007-11-28 09:43:47 +00:00
|
|
|
* 'grademin', 'scaleid', 'multfactor', 'plusfactor', 'deleted' and 'hidden'. 'reset' means delete all current grades including locked ones.
|
2007-06-09 14:16:20 +00:00
|
|
|
*
|
2007-09-22 20:21:44 +00:00
|
|
|
* Manual, course or category items can not be updated by this function.
|
2008-01-09 18:19:42 +00:00
|
|
|
* @public
|
2007-08-31 22:42:05 +00:00
|
|
|
* @param string $source source of the grade such as 'mod/assignment'
|
2007-06-07 08:34:04 +00:00
|
|
|
* @param int $courseid id of course
|
2007-07-31 22:56:29 +00:00
|
|
|
* @param string $itemtype type of grade item - mod, block
|
2007-06-07 08:34:04 +00:00
|
|
|
* @param string $itemmodule more specific then $itemtype - assignment, forum, etc.; maybe NULL for some item types
|
|
|
|
* @param int $iteminstance instance it of graded subject
|
|
|
|
* @param int $itemnumber most probably 0, modules can use other numbers when having more than one grades for each user
|
2007-08-10 20:59:25 +00:00
|
|
|
* @param mixed $grades grade (object, array) or several grades (arrays of arrays or objects), NULL if updating grade_item definition only
|
2007-06-07 08:34:04 +00:00
|
|
|
* @param mixed $itemdetails object or array describing the grading item, NULL if no change
|
|
|
|
*/
|
2007-06-06 23:04:24 +00:00
|
|
|
function grade_update($source, $courseid, $itemtype, $itemmodule, $iteminstance, $itemnumber, $grades=NULL, $itemdetails=NULL) {
|
2007-07-06 12:49:28 +00:00
|
|
|
global $USER;
|
2007-06-05 22:58:37 +00:00
|
|
|
|
2007-06-07 08:34:04 +00:00
|
|
|
// only following grade_item properties can be changed in this function
|
2007-10-04 22:57:14 +00:00
|
|
|
$allowed = array('itemname', 'idnumber', 'gradetype', 'grademax', 'grademin', 'scaleid', 'multfactor', 'plusfactor', 'deleted', 'hidden');
|
2007-06-05 22:58:37 +00:00
|
|
|
|
2007-06-25 07:56:25 +00:00
|
|
|
// grade item identification
|
|
|
|
$params = compact('courseid', 'itemtype', 'itemmodule', 'iteminstance', 'itemnumber');
|
|
|
|
|
2007-06-05 22:58:37 +00:00
|
|
|
if (is_null($courseid) or is_null($itemtype)) {
|
|
|
|
debugging('Missing courseid or itemtype');
|
|
|
|
return GRADE_UPDATE_FAILED;
|
|
|
|
}
|
|
|
|
|
2007-06-25 07:56:25 +00:00
|
|
|
if (!$grade_items = grade_item::fetch_all($params)) {
|
2007-06-05 22:58:37 +00:00
|
|
|
// create a new one
|
|
|
|
$grade_item = false;
|
|
|
|
|
|
|
|
} else if (count($grade_items) == 1){
|
|
|
|
$grade_item = reset($grade_items);
|
|
|
|
unset($grade_items); //release memory
|
|
|
|
|
|
|
|
} else {
|
2007-06-10 20:34:07 +00:00
|
|
|
debugging('Found more than one grade item');
|
2007-06-05 22:58:37 +00:00
|
|
|
return GRADE_UPDATE_MULTIPLE;
|
|
|
|
}
|
|
|
|
|
2007-07-06 12:49:28 +00:00
|
|
|
if (!empty($itemdetails['deleted'])) {
|
|
|
|
if ($grade_item) {
|
|
|
|
if ($grade_item->delete($source)) {
|
|
|
|
return GRADE_UPDATE_OK;
|
|
|
|
} else {
|
|
|
|
return GRADE_UPDATE_FAILED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return GRADE_UPDATE_OK;
|
|
|
|
}
|
|
|
|
|
2007-06-05 22:58:37 +00:00
|
|
|
/// Create or update the grade_item if needed
|
2007-09-14 19:32:50 +00:00
|
|
|
|
2007-06-05 22:58:37 +00:00
|
|
|
if (!$grade_item) {
|
|
|
|
if ($itemdetails) {
|
|
|
|
$itemdetails = (array)$itemdetails;
|
2007-06-22 18:33:32 +00:00
|
|
|
|
2007-06-23 16:51:09 +00:00
|
|
|
// grademin and grademax ignored when scale specified
|
2007-06-22 18:33:32 +00:00
|
|
|
if (array_key_exists('scaleid', $itemdetails)) {
|
|
|
|
if ($itemdetails['scaleid']) {
|
|
|
|
unset($itemdetails['grademin']);
|
|
|
|
unset($itemdetails['grademax']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-05 22:58:37 +00:00
|
|
|
foreach ($itemdetails as $k=>$v) {
|
|
|
|
if (!in_array($k, $allowed)) {
|
|
|
|
// ignore it
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ($k == 'gradetype' and $v == GRADE_TYPE_NONE) {
|
|
|
|
// no grade item needed!
|
|
|
|
return GRADE_UPDATE_OK;
|
|
|
|
}
|
|
|
|
$params[$k] = $v;
|
|
|
|
}
|
|
|
|
}
|
2007-06-12 20:19:38 +00:00
|
|
|
$grade_item = new grade_item($params);
|
|
|
|
$grade_item->insert();
|
2007-06-05 22:58:37 +00:00
|
|
|
|
|
|
|
} else {
|
2007-06-22 08:57:39 +00:00
|
|
|
if ($grade_item->is_locked()) {
|
2007-09-17 17:39:35 +00:00
|
|
|
$message = get_string('gradeitemislocked', 'grades', $grade_item->itemname);
|
|
|
|
notice($message);
|
|
|
|
return GRADE_UPDATE_ITEM_LOCKED;
|
2007-06-05 22:58:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($itemdetails) {
|
|
|
|
$itemdetails = (array)$itemdetails;
|
|
|
|
$update = false;
|
|
|
|
foreach ($itemdetails as $k=>$v) {
|
|
|
|
if (!in_array($k, $allowed)) {
|
|
|
|
// ignore it
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ($grade_item->{$k} != $v) {
|
|
|
|
$grade_item->{$k} = $v;
|
|
|
|
$update = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($update) {
|
|
|
|
$grade_item->update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-28 09:43:47 +00:00
|
|
|
/// reset grades if requested
|
|
|
|
if (!empty($itemdetails['reset'])) {
|
|
|
|
$grade_item->delete_all_grades('reset');
|
|
|
|
return GRADE_UPDATE_OK;
|
|
|
|
}
|
|
|
|
|
2007-06-05 22:58:37 +00:00
|
|
|
/// Some extra checks
|
|
|
|
// do we use grading?
|
|
|
|
if ($grade_item->gradetype == GRADE_TYPE_NONE) {
|
|
|
|
return GRADE_UPDATE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// no grade submitted
|
2007-06-06 23:04:24 +00:00
|
|
|
if (empty($grades)) {
|
2007-06-05 22:58:37 +00:00
|
|
|
return GRADE_UPDATE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Finally start processing of grades
|
2007-06-06 23:04:24 +00:00
|
|
|
if (is_object($grades)) {
|
|
|
|
$grades = array($grades);
|
2007-06-05 22:58:37 +00:00
|
|
|
} else {
|
2007-06-06 23:04:24 +00:00
|
|
|
if (array_key_exists('userid', $grades)) {
|
|
|
|
$grades = array($grades);
|
2007-06-05 22:58:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-09 14:16:20 +00:00
|
|
|
$failed = false;
|
2007-06-05 22:58:37 +00:00
|
|
|
foreach ($grades as $grade) {
|
|
|
|
$grade = (array)$grade;
|
|
|
|
if (empty($grade['userid'])) {
|
2007-06-09 14:16:20 +00:00
|
|
|
$failed = true;
|
|
|
|
debugging('Invalid userid in grade submitted');
|
|
|
|
continue;
|
2007-06-20 23:06:29 +00:00
|
|
|
} else {
|
|
|
|
$userid = $grade['userid'];
|
2007-06-05 22:58:37 +00:00
|
|
|
}
|
|
|
|
|
2007-06-22 08:57:39 +00:00
|
|
|
$rawgrade = false;
|
2007-06-20 23:06:29 +00:00
|
|
|
$feedback = false;
|
|
|
|
$feedbackformat = FORMAT_MOODLE;
|
2007-11-01 08:25:05 +00:00
|
|
|
$usermodified = $USER->id;
|
|
|
|
$datesubmitted = null;
|
|
|
|
$dategraded = null;
|
2007-06-23 16:51:09 +00:00
|
|
|
|
2007-06-20 23:06:29 +00:00
|
|
|
if (array_key_exists('rawgrade', $grade)) {
|
|
|
|
$rawgrade = $grade['rawgrade'];
|
|
|
|
}
|
2007-06-05 22:58:37 +00:00
|
|
|
|
2007-06-09 14:16:20 +00:00
|
|
|
if (array_key_exists('feedback', $grade)) {
|
2007-06-20 23:06:29 +00:00
|
|
|
$feedback = $grade['feedback'];
|
2007-06-05 22:58:37 +00:00
|
|
|
}
|
|
|
|
|
2007-06-20 23:06:29 +00:00
|
|
|
if (array_key_exists('feedbackformat', $grade)) {
|
|
|
|
$feedbackformat = $grade['feedbackformat'];
|
2007-06-05 22:58:37 +00:00
|
|
|
}
|
|
|
|
|
2007-07-06 12:49:28 +00:00
|
|
|
if (array_key_exists('usermodified', $grade)) {
|
|
|
|
$usermodified = $grade['usermodified'];
|
2007-11-01 08:25:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (array_key_exists('datesubmitted', $grade)) {
|
|
|
|
$datesubmitted = $grade['datesubmitted'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (array_key_exists('dategraded', $grade)) {
|
|
|
|
$dategraded = $grade['dategraded'];
|
2007-07-06 12:49:28 +00:00
|
|
|
}
|
|
|
|
|
2007-06-20 23:06:29 +00:00
|
|
|
// update or insert the grade
|
2007-11-01 08:25:05 +00:00
|
|
|
if (!$grade_item->update_raw_grade($userid, $rawgrade, $source, $feedback, $feedbackformat, $usermodified, $dategraded, $datesubmitted)) {
|
2007-06-09 14:16:20 +00:00
|
|
|
$failed = true;
|
|
|
|
}
|
2007-06-05 22:58:37 +00:00
|
|
|
}
|
|
|
|
|
2007-06-09 14:16:20 +00:00
|
|
|
if (!$failed) {
|
|
|
|
return GRADE_UPDATE_OK;
|
|
|
|
} else {
|
|
|
|
return GRADE_UPDATE_FAILED;
|
|
|
|
}
|
2007-06-05 22:58:37 +00:00
|
|
|
}
|
|
|
|
|
2007-07-31 22:56:29 +00:00
|
|
|
/**
|
|
|
|
* Updates outcomes of user
|
2007-09-22 20:21:44 +00:00
|
|
|
* Manual outcomes can not be updated.
|
2008-01-09 18:19:42 +00:00
|
|
|
* @public
|
2007-09-22 20:21:44 +00:00
|
|
|
* @param string $source source of the grade such as 'mod/assignment'
|
2007-07-31 22:56:29 +00:00
|
|
|
* @param int $courseid id of course
|
|
|
|
* @param string $itemtype 'mod', 'block'
|
|
|
|
* @param string $itemmodule 'forum, 'quiz', etc.
|
|
|
|
* @param int $iteminstance id of the item module
|
|
|
|
* @param int $userid ID of the graded user
|
2007-09-22 20:21:44 +00:00
|
|
|
* @param array $data array itemnumber=>outcomegrade
|
2007-07-31 22:56:29 +00:00
|
|
|
*/
|
|
|
|
function grade_update_outcomes($source, $courseid, $itemtype, $itemmodule, $iteminstance, $userid, $data) {
|
|
|
|
if ($items = grade_item::fetch_all(array('itemtype'=>$itemtype, 'itemmodule'=>$itemmodule, 'iteminstance'=>$iteminstance, 'courseid'=>$courseid))) {
|
|
|
|
foreach ($items as $item) {
|
|
|
|
if (!array_key_exists($item->itemnumber, $data)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$grade = $data[$item->itemnumber] < 1 ? null : $data[$item->itemnumber];
|
|
|
|
$item->update_final_grade($userid, $grade, $source);
|
2007-08-01 21:48:10 +00:00
|
|
|
}
|
2007-07-31 22:56:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-15 19:24:10 +00:00
|
|
|
/**
|
2007-09-22 20:21:44 +00:00
|
|
|
* Returns grading information for given activity - optionally with users grades
|
|
|
|
* Manual, course or category items can not be queried.
|
2008-01-09 18:19:42 +00:00
|
|
|
* @public
|
2007-09-15 19:24:10 +00:00
|
|
|
* @param int $courseid id of course
|
|
|
|
* @param string $itemtype 'mod', 'block'
|
|
|
|
* @param string $itemmodule 'forum, 'quiz', etc.
|
|
|
|
* @param int $iteminstance id of the item module
|
2008-01-09 18:19:42 +00:00
|
|
|
* @param int $userid_or_ids optional id of the graded user or array of ids; if userid not used, returns only information about grade_item
|
2007-09-15 19:24:10 +00:00
|
|
|
* @return array of grade information objects (scaleid, name, grade and locked status, etc.) indexed with itemnumbers
|
|
|
|
*/
|
2008-01-09 18:19:42 +00:00
|
|
|
function grade_get_grades($courseid, $itemtype, $itemmodule, $iteminstance, $userid_or_ids=null) {
|
2007-09-23 15:51:21 +00:00
|
|
|
global $CFG;
|
|
|
|
|
2007-09-22 20:21:44 +00:00
|
|
|
$return = new object();
|
|
|
|
$return->items = array();
|
|
|
|
$return->outcomes = array();
|
2007-09-15 19:24:10 +00:00
|
|
|
|
2007-09-22 20:21:44 +00:00
|
|
|
$course_item = grade_item::fetch_course_item($courseid);
|
|
|
|
$needsupdate = array();
|
|
|
|
if ($course_item->needsupdate) {
|
|
|
|
$result = grade_regrade_final_grades($courseid);
|
|
|
|
if ($result !== true) {
|
|
|
|
$needsupdate = array_keys($result);
|
|
|
|
}
|
|
|
|
}
|
2007-09-15 19:24:10 +00:00
|
|
|
|
2007-09-22 20:21:44 +00:00
|
|
|
if ($grade_items = grade_item::fetch_all(array('itemtype'=>$itemtype, 'itemmodule'=>$itemmodule, 'iteminstance'=>$iteminstance, 'courseid'=>$courseid))) {
|
|
|
|
foreach ($grade_items as $grade_item) {
|
2007-09-23 15:51:21 +00:00
|
|
|
$decimalpoints = null;
|
|
|
|
|
2007-09-22 20:21:44 +00:00
|
|
|
if (empty($grade_item->outcomeid)) {
|
|
|
|
// prepare information about grade item
|
|
|
|
$item = new object();
|
|
|
|
$item->itemnumber = $grade_item->itemnumber;
|
|
|
|
$item->scaleid = $grade_item->scaleid;
|
|
|
|
$item->name = $grade_item->get_name();
|
|
|
|
$item->grademin = $grade_item->grademin;
|
|
|
|
$item->grademax = $grade_item->grademax;
|
|
|
|
$item->gradepass = $grade_item->gradepass;
|
|
|
|
$item->locked = $grade_item->is_locked();
|
|
|
|
$item->hidden = $grade_item->is_hidden();
|
|
|
|
$item->grades = array();
|
|
|
|
|
|
|
|
switch ($grade_item->gradetype) {
|
|
|
|
case GRADE_TYPE_NONE:
|
|
|
|
continue;
|
2007-09-15 19:24:10 +00:00
|
|
|
|
|
|
|
case GRADE_TYPE_VALUE:
|
2007-09-22 20:21:44 +00:00
|
|
|
$item->scaleid = 0;
|
2007-09-15 19:24:10 +00:00
|
|
|
break;
|
|
|
|
|
2007-09-22 20:21:44 +00:00
|
|
|
case GRADE_TYPE_TEXT:
|
|
|
|
$item->scaleid = 0;
|
|
|
|
$item->grademin = 0;
|
|
|
|
$item->grademax = 0;
|
|
|
|
$item->gradepass = 0;
|
2007-09-15 19:24:10 +00:00
|
|
|
break;
|
2007-09-22 20:21:44 +00:00
|
|
|
}
|
2007-09-15 19:24:10 +00:00
|
|
|
|
2007-09-22 20:21:44 +00:00
|
|
|
if (empty($userid_or_ids)) {
|
|
|
|
$userids = array();
|
|
|
|
|
|
|
|
} else if (is_array($userid_or_ids)) {
|
|
|
|
$userids = $userid_or_ids;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$userids = array($userid_or_ids);
|
2007-09-15 19:24:10 +00:00
|
|
|
}
|
|
|
|
|
2007-09-22 20:21:44 +00:00
|
|
|
if ($userids) {
|
|
|
|
$grade_grades = grade_grade::fetch_users_grades($grade_item, $userids, true);
|
|
|
|
foreach ($userids as $userid) {
|
|
|
|
$grade_grades[$userid]->grade_item =& $grade_item;
|
|
|
|
|
|
|
|
$grade = new object();
|
|
|
|
$grade->grade = $grade_grades[$userid]->finalgrade;
|
|
|
|
$grade->locked = $grade_grades[$userid]->is_locked();
|
|
|
|
$grade->hidden = $grade_grades[$userid]->is_hidden();
|
|
|
|
$grade->overridden = $grade_grades[$userid]->overridden;
|
|
|
|
$grade->feedback = $grade_grades[$userid]->feedback;
|
|
|
|
$grade->feedbackformat = $grade_grades[$userid]->feedbackformat;
|
2007-09-23 15:51:21 +00:00
|
|
|
$grade->usermodified = $grade_grades[$userid]->usermodified;
|
2007-11-01 08:25:05 +00:00
|
|
|
$grade->datesubmitted = $grade_grades[$userid]->get_datesubmitted();
|
|
|
|
$grade->dategraded = $grade_grades[$userid]->get_dategraded();
|
2007-09-22 20:21:44 +00:00
|
|
|
|
|
|
|
// create text representation of grade
|
|
|
|
if (in_array($grade_item->id, $needsupdate)) {
|
2008-01-21 07:19:19 +00:00
|
|
|
$grade->grade = false;
|
|
|
|
$grade->str_grade = get_string('error');
|
|
|
|
$grade->str_long_grade = $grade->str_grade;
|
2007-09-22 20:21:44 +00:00
|
|
|
|
|
|
|
} else if (is_null($grade->grade)) {
|
2008-01-21 07:19:19 +00:00
|
|
|
$grade->str_grade = '-';
|
|
|
|
$grade->str_long_grade = $grade->str_grade;
|
2007-09-22 20:21:44 +00:00
|
|
|
|
|
|
|
} else {
|
2007-09-28 07:55:51 +00:00
|
|
|
$grade->str_grade = grade_format_gradevalue($grade->grade, $grade_item);
|
2008-01-21 07:19:19 +00:00
|
|
|
if ($grade_item->gradetype == GRADE_TYPE_SCALE or $grade_item->get_displaytype() != GRADE_DISPLAY_TYPE_REAL) {
|
|
|
|
$grade->str_long_grade = $grade->str_grade;
|
|
|
|
} else {
|
|
|
|
$a = new object();
|
|
|
|
$a->grade = $grade->str_grade;
|
|
|
|
$a->max = grade_format_gradevalue($grade_item->grademax, $grade_item);
|
|
|
|
$grade->str_long_grade = get_string('gradelong', 'grades', $a);
|
|
|
|
}
|
2007-09-22 20:21:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// create html representation of feedback
|
|
|
|
if (is_null($grade->feedback)) {
|
|
|
|
$grade->str_feedback = '';
|
|
|
|
} else {
|
|
|
|
$grade->str_feedback = format_text($grade->feedback, $grade->feedbackformat);
|
|
|
|
}
|
|
|
|
|
|
|
|
$item->grades[$userid] = $grade;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$return->items[$grade_item->itemnumber] = $item;
|
|
|
|
|
2007-09-15 19:24:10 +00:00
|
|
|
} else {
|
2007-09-22 20:21:44 +00:00
|
|
|
if (!$grade_outcome = grade_outcome::fetch(array('id'=>$grade_item->outcomeid))) {
|
|
|
|
debugging('Incorect outcomeid found');
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// outcome info
|
|
|
|
$outcome = new object();
|
|
|
|
$outcome->itemnumber = $grade_item->itemnumber;
|
|
|
|
$outcome->scaleid = $grade_outcome->scaleid;
|
|
|
|
$outcome->name = $grade_outcome->get_name();
|
|
|
|
$outcome->locked = $grade_item->is_locked();
|
|
|
|
$outcome->hidden = $grade_item->is_hidden();
|
|
|
|
|
|
|
|
if (empty($userid_or_ids)) {
|
|
|
|
$userids = array();
|
|
|
|
} else if (is_array($userid_or_ids)) {
|
|
|
|
$userids = $userid_or_ids;
|
|
|
|
} else {
|
|
|
|
$userids = array($userid_or_ids);
|
|
|
|
}
|
2007-09-15 19:24:10 +00:00
|
|
|
|
2007-09-22 20:21:44 +00:00
|
|
|
if ($userids) {
|
|
|
|
$grade_grades = grade_grade::fetch_users_grades($grade_item, $userids, true);
|
|
|
|
foreach ($userids as $userid) {
|
|
|
|
$grade_grades[$userid]->grade_item =& $grade_item;
|
|
|
|
|
|
|
|
$grade = new object();
|
|
|
|
$grade->grade = $grade_grades[$userid]->finalgrade;
|
|
|
|
$grade->locked = $grade_grades[$userid]->is_locked();
|
|
|
|
$grade->hidden = $grade_grades[$userid]->is_hidden();
|
|
|
|
$grade->feedback = $grade_grades[$userid]->feedback;
|
|
|
|
$grade->feedbackformat = $grade_grades[$userid]->feedbackformat;
|
2007-09-23 15:51:21 +00:00
|
|
|
$grade->usermodified = $grade_grades[$userid]->usermodified;
|
2007-09-22 20:21:44 +00:00
|
|
|
|
|
|
|
// create text representation of grade
|
|
|
|
if (in_array($grade_item->id, $needsupdate)) {
|
|
|
|
$grade->grade = false;
|
|
|
|
$grade->str_grade = get_string('error');
|
|
|
|
|
|
|
|
} else if (is_null($grade->grade)) {
|
|
|
|
$grade->grade = 0;
|
|
|
|
$grade->str_grade = get_string('nooutcome', 'grades');
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$grade->grade = (int)$grade->grade;
|
|
|
|
$scale = $grade_item->load_scale();
|
|
|
|
$grade->str_grade = format_string($scale->scale_items[(int)$grade->grade-1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// create html representation of feedback
|
|
|
|
if (is_null($grade->feedback)) {
|
|
|
|
$grade->str_feedback = '';
|
|
|
|
} else {
|
|
|
|
$grade->str_feedback = format_text($grade->feedback, $grade->feedbackformat);
|
|
|
|
}
|
|
|
|
|
|
|
|
$outcome->grades[$userid] = $grade;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$return->outcomes[$grade_item->itemnumber] = $outcome;
|
|
|
|
|
|
|
|
}
|
2007-09-15 19:24:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-22 20:21:44 +00:00
|
|
|
// sort results using itemnumbers
|
|
|
|
ksort($return->items, SORT_NUMERIC);
|
|
|
|
ksort($return->outcomes, SORT_NUMERIC);
|
|
|
|
|
|
|
|
return $return;
|
2007-09-15 19:24:10 +00:00
|
|
|
}
|
|
|
|
|
2008-01-09 18:19:42 +00:00
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
///// End of public API for communication with modules/blocks /////
|
|
|
|
///////////////////////////////////////////////////////////////////
|
2007-11-21 10:04:21 +00:00
|
|
|
|
|
|
|
|
2007-06-05 22:58:37 +00:00
|
|
|
|
2008-01-09 18:19:42 +00:00
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
///// Internal API: used by gradebook plugins and Moodle core /////
|
|
|
|
///////////////////////////////////////////////////////////////////
|
2007-10-08 23:09:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns course gradebook setting
|
|
|
|
* @param int $courseid
|
|
|
|
* @param string $name of setting, maybe null if reset only
|
|
|
|
* @param bool $resetcache force reset of internal static cache
|
|
|
|
* @return string value, NULL if no setting
|
|
|
|
*/
|
|
|
|
function grade_get_setting($courseid, $name, $default=null, $resetcache=false) {
|
|
|
|
static $cache = array();
|
|
|
|
|
|
|
|
if ($resetcache or !array_key_exists($courseid, $cache)) {
|
|
|
|
$cache[$courseid] = array();
|
|
|
|
|
|
|
|
} else if (is_null($name)) {
|
|
|
|
return null;
|
|
|
|
|
|
|
|
} else if (array_key_exists($name, $cache[$courseid])) {
|
|
|
|
return $cache[$courseid][$name];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$data = get_record('grade_settings', 'courseid', $courseid, 'name', addslashes($name))) {
|
|
|
|
$result = null;
|
|
|
|
} else {
|
|
|
|
$result = $data->value;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_null($result)) {
|
|
|
|
$result = $default;
|
|
|
|
}
|
|
|
|
|
|
|
|
$cache[$courseid][$name] = $result;
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2007-10-27 15:33:43 +00:00
|
|
|
/**
|
|
|
|
* Returns all course gradebook settings as object properties
|
|
|
|
* @param int $courseid
|
|
|
|
* @return object
|
|
|
|
*/
|
|
|
|
function grade_get_settings($courseid) {
|
|
|
|
$settings = new object();
|
|
|
|
$settings->id = $courseid;
|
|
|
|
|
|
|
|
if ($records = get_records('grade_settings', 'courseid', $courseid)) {
|
|
|
|
foreach ($records as $record) {
|
|
|
|
$settings->{$record->name} = $record->value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $settings;
|
|
|
|
}
|
|
|
|
|
2007-10-08 23:09:10 +00:00
|
|
|
/**
|
|
|
|
* Add/update course gradebook setting
|
|
|
|
* @param int $courseid
|
|
|
|
* @param string $name of setting
|
|
|
|
* @param string value, NULL means no setting==remove
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function grade_set_setting($courseid, $name, $value) {
|
|
|
|
if (is_null($value)) {
|
|
|
|
delete_records('grade_settings', 'courseid', $courseid, 'name', addslashes($name));
|
|
|
|
|
|
|
|
} else if (!$existing = get_record('grade_settings', 'courseid', $courseid, 'name', addslashes($name))) {
|
|
|
|
$data = new object();
|
|
|
|
$data->courseid = $courseid;
|
|
|
|
$data->name = addslashes($name);
|
|
|
|
$data->value = addslashes($value);
|
|
|
|
insert_record('grade_settings', $data);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$data = new object();
|
|
|
|
$data->id = $existing->id;
|
|
|
|
$data->value = addslashes($value);
|
|
|
|
update_record('grade_settings', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
grade_get_setting($courseid, null, null, true); // reset the cache
|
|
|
|
}
|
|
|
|
|
2007-09-28 07:55:51 +00:00
|
|
|
/**
|
|
|
|
* Returns string representation of grade value
|
|
|
|
* @param float $value grade value
|
|
|
|
* @param object $grade_item - by reference to prevent scale reloading
|
|
|
|
* @param bool $localized use localised decimal separator
|
2008-01-09 18:19:42 +00:00
|
|
|
* @param int $displaytype type of display - GRADE_DISPLAY_TYPE_REAL, GRADE_DISPLAY_TYPE_PERCENTAGE, GRADE_DISPLAY_TYPE_LETTER
|
2007-09-28 07:55:51 +00:00
|
|
|
* @param int $decimalplaces number of decimal places when displaying float values
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function grade_format_gradevalue($value, &$grade_item, $localized=true, $displaytype=null, $decimals=null) {
|
|
|
|
if ($grade_item->gradetype == GRADE_TYPE_NONE or $grade_item->gradetype == GRADE_TYPE_TEXT) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
// no grade yet?
|
|
|
|
if (is_null($value)) {
|
|
|
|
return '-';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($grade_item->gradetype != GRADE_TYPE_VALUE and $grade_item->gradetype != GRADE_TYPE_SCALE) {
|
|
|
|
//unknown type??
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_null($displaytype)) {
|
|
|
|
$displaytype = $grade_item->get_displaytype();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_null($decimals)) {
|
|
|
|
$decimals = $grade_item->get_decimals();
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ($displaytype) {
|
|
|
|
case GRADE_DISPLAY_TYPE_REAL:
|
|
|
|
if ($grade_item->gradetype == GRADE_TYPE_SCALE) {
|
2007-10-27 11:41:44 +00:00
|
|
|
if (!$scale = $grade_item->load_scale()) {
|
|
|
|
return get_string('error');
|
|
|
|
}
|
|
|
|
|
2007-09-28 07:55:51 +00:00
|
|
|
$value = (int)bounded_number($grade_item->grademin, $value, $grade_item->grademax);
|
|
|
|
return format_string($scale->scale_items[$value-1]);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
return format_float($value, $decimals, $localized);
|
|
|
|
}
|
|
|
|
|
|
|
|
case GRADE_DISPLAY_TYPE_PERCENTAGE:
|
|
|
|
$min = $grade_item->grademin;
|
|
|
|
$max = $grade_item->grademax;
|
|
|
|
if ($min == $max) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
$value = bounded_number($min, $value, $max);
|
|
|
|
$percentage = (($value-$min)*100)/($max-$min);
|
|
|
|
return format_float($percentage, $decimals, $localized).' %';
|
|
|
|
|
|
|
|
case GRADE_DISPLAY_TYPE_LETTER:
|
|
|
|
$context = get_context_instance(CONTEXT_COURSE, $grade_item->courseid);
|
|
|
|
if (!$letters = grade_get_letters($context)) {
|
|
|
|
return ''; // no letters??
|
|
|
|
}
|
|
|
|
|
|
|
|
$value = grade_grade::standardise_score($value, $grade_item->grademin, $grade_item->grademax, 0, 100);
|
|
|
|
$value = bounded_number(0, $value, 100); // just in case
|
|
|
|
foreach ($letters as $boundary => $letter) {
|
|
|
|
if ($value >= $boundary) {
|
|
|
|
return format_string($letter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return '-'; // no match? maybe '' would be more correct
|
|
|
|
|
|
|
|
default:
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|
2008-01-21 18:42:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns grade options for gradebook category menu
|
|
|
|
* @param int $courseid
|
|
|
|
* @param bool $includenew include option for new category (-1)
|
|
|
|
* @return array of grade categories in course
|
|
|
|
*/
|
|
|
|
function grade_get_categories_menu($courseid, $includenew=false) {
|
|
|
|
$result = array();
|
|
|
|
if (!$categories = grade_category::fetch_all(array('courseid'=>$courseid))) {
|
|
|
|
//make sure course category exists
|
2008-01-22 11:59:39 +00:00
|
|
|
if (!grade_category::fetch_course_category($courseid)) {
|
2008-01-21 18:42:03 +00:00
|
|
|
debugging('Can not create course grade category!');
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
$categories = grade_category::fetch_all(array('courseid'=>$courseid));
|
|
|
|
}
|
|
|
|
foreach ($categories as $key=>$category) {
|
|
|
|
if ($category->is_course_category()) {
|
|
|
|
$result[$category->id] = get_string('uncategorised', 'grades');
|
|
|
|
unset($categories[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($includenew) {
|
|
|
|
$result[-1] = get_string('newcategory', 'grades');
|
|
|
|
}
|
|
|
|
$cats = array();
|
|
|
|
foreach ($categories as $category) {
|
|
|
|
$cats[$category->id] = $category->get_name();
|
|
|
|
}
|
|
|
|
asort($cats, SORT_LOCALE_STRING);
|
|
|
|
|
|
|
|
return ($result+$cats);
|
|
|
|
}
|
2007-09-28 07:55:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns grade letters array used in context
|
|
|
|
* @param object $context object or null for defaults
|
|
|
|
* @return array of grade_boundary=>letter_string
|
|
|
|
*/
|
|
|
|
function grade_get_letters($context=null) {
|
|
|
|
if (empty($context)) {
|
2007-09-28 20:12:43 +00:00
|
|
|
//default grading letters
|
|
|
|
return array('93'=>'A', '90'=>'A-', '87'=>'B+', '83'=>'B', '80'=>'B-', '77'=>'C+', '73'=>'C', '70'=>'C-', '67'=>'D+', '60'=>'D', '0'=>'F');
|
2007-09-28 07:55:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static $cache = array();
|
|
|
|
|
|
|
|
if (array_key_exists($context->id, $cache)) {
|
|
|
|
return $cache[$context->id];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count($cache) > 100) {
|
|
|
|
$cache = array(); // cache size limit
|
|
|
|
}
|
|
|
|
|
|
|
|
$letters = array();
|
|
|
|
|
|
|
|
$contexts = get_parent_contexts($context);
|
|
|
|
array_unshift($contexts, $context->id);
|
|
|
|
|
|
|
|
foreach ($contexts as $ctxid) {
|
2007-09-28 20:12:43 +00:00
|
|
|
if ($records = get_records('grade_letters', 'contextid', $ctxid, 'lowerboundary DESC')) {
|
2007-09-28 07:55:51 +00:00
|
|
|
foreach ($records as $record) {
|
2007-09-28 20:12:43 +00:00
|
|
|
$letters[$record->lowerboundary] = $record->letter;
|
2007-09-28 07:55:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($letters)) {
|
|
|
|
$cache[$context->id] = $letters;
|
|
|
|
return $letters;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$letters = grade_get_letters(null);
|
|
|
|
$cache[$context->id] = $letters;
|
|
|
|
return $letters;
|
|
|
|
}
|
|
|
|
|
2007-08-02 10:38:18 +00:00
|
|
|
|
|
|
|
/**
|
2007-08-11 18:13:07 +00:00
|
|
|
* Verify new value of idnumber - checks for uniqueness of new idnumbers, old are kept intact
|
2007-08-02 10:38:18 +00:00
|
|
|
* @param string idnumber string (with magic quotes)
|
2008-01-14 22:46:03 +00:00
|
|
|
* @param int $courseid - id numbers are course unique only
|
2007-08-02 10:38:18 +00:00
|
|
|
* @param object $cm used for course module idnumbers and items attached to modules
|
|
|
|
* @param object $gradeitem is item idnumber
|
|
|
|
* @return boolean true means idnumber ok
|
|
|
|
*/
|
2008-01-14 22:46:03 +00:00
|
|
|
function grade_verify_idnumber($idnumber, $courseid, $grade_item=null, $cm=null) {
|
2007-08-02 10:38:18 +00:00
|
|
|
if ($idnumber == '') {
|
|
|
|
//we allow empty idnumbers
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// keep existing even when not unique
|
|
|
|
if ($cm and $cm->idnumber == $idnumber) {
|
|
|
|
return true;
|
|
|
|
} else if ($grade_item and $grade_item->idnumber == $idnumber) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-01-14 22:46:03 +00:00
|
|
|
if (get_records_select('course_modules', "course = $courseid AND idnumber='$idnumber'")) {
|
2007-08-02 10:38:18 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-01-14 22:46:03 +00:00
|
|
|
if (get_records_select('grade_items', "courseid = $courseid AND idnumber='$idnumber'")) {
|
2007-08-02 10:38:18 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Force final grade recalculation in all course items
|
|
|
|
* @param int $courseid
|
|
|
|
*/
|
2007-07-08 14:57:19 +00:00
|
|
|
function grade_force_full_regrading($courseid) {
|
|
|
|
set_field('grade_items', 'needsupdate', 1, 'courseid', $courseid);
|
|
|
|
}
|
2007-06-10 20:34:07 +00:00
|
|
|
|
2007-04-23 09:00:32 +00:00
|
|
|
/**
|
2007-06-20 23:06:29 +00:00
|
|
|
* Updates all final grades in course.
|
2007-04-30 04:49:25 +00:00
|
|
|
*
|
|
|
|
* @param int $courseid
|
2007-07-08 14:57:19 +00:00
|
|
|
* @param int $userid if specified, try to do a quick regrading of grades of this user only
|
|
|
|
* @param object $updated_item the item in which
|
|
|
|
* @return boolean true if ok, array of errors if problems found (item id is used as key)
|
2007-04-30 04:49:25 +00:00
|
|
|
*/
|
2007-07-10 18:08:24 +00:00
|
|
|
function grade_regrade_final_grades($courseid, $userid=null, $updated_item=null) {
|
2007-06-18 13:43:40 +00:00
|
|
|
|
2007-07-29 13:22:50 +00:00
|
|
|
$course_item = grade_item::fetch_course_item($courseid);
|
2007-07-28 09:23:32 +00:00
|
|
|
|
2007-07-08 14:57:19 +00:00
|
|
|
if ($userid) {
|
|
|
|
// one raw grade updated for one user
|
|
|
|
if (empty($updated_item)) {
|
|
|
|
error("updated_item_id can not be null!");
|
|
|
|
}
|
|
|
|
if ($course_item->needsupdate) {
|
|
|
|
$updated_item->force_regrading();
|
|
|
|
return 'Can not do fast regrading after updating of raw grades';
|
2007-04-30 04:49:25 +00:00
|
|
|
}
|
2007-06-23 16:51:09 +00:00
|
|
|
|
2007-07-08 14:57:19 +00:00
|
|
|
} else {
|
|
|
|
if (!$course_item->needsupdate) {
|
|
|
|
// nothing to do :-)
|
2007-06-18 13:43:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
2007-04-30 04:49:25 +00:00
|
|
|
}
|
|
|
|
|
2007-07-08 14:57:19 +00:00
|
|
|
$grade_items = grade_item::fetch_all(array('courseid'=>$courseid));
|
|
|
|
$depends_on = array();
|
|
|
|
|
|
|
|
// first mark all category and calculated items as needing regrading
|
2007-08-09 09:03:14 +00:00
|
|
|
// this is slower, but 100% accurate
|
2007-07-08 14:57:19 +00:00
|
|
|
foreach ($grade_items as $gid=>$gitem) {
|
2007-07-13 07:51:10 +00:00
|
|
|
if (!empty($updated_item) and $updated_item->id == $gid) {
|
2007-07-08 14:57:19 +00:00
|
|
|
$grade_items[$gid]->needsupdate = 1;
|
|
|
|
|
2007-07-21 10:09:57 +00:00
|
|
|
} else if ($gitem->is_course_item() or $gitem->is_category_item() or $gitem->is_calculated()) {
|
2007-07-08 14:57:19 +00:00
|
|
|
$grade_items[$gid]->needsupdate = 1;
|
|
|
|
}
|
2007-06-22 18:33:32 +00:00
|
|
|
|
2007-07-08 14:57:19 +00:00
|
|
|
// construct depends_on lookup array
|
|
|
|
$depends_on[$gid] = $grade_items[$gid]->depends_on();
|
|
|
|
}
|
2007-06-22 18:33:32 +00:00
|
|
|
|
2007-07-19 17:36:36 +00:00
|
|
|
$errors = array();
|
2007-06-18 13:43:40 +00:00
|
|
|
$finalids = array();
|
2007-07-19 17:36:36 +00:00
|
|
|
$gids = array_keys($grade_items);
|
2007-07-21 10:09:57 +00:00
|
|
|
$failed = 0;
|
2007-07-19 17:36:36 +00:00
|
|
|
|
|
|
|
while (count($finalids) < count($gids)) { // work until all grades are final or error found
|
|
|
|
$count = 0;
|
|
|
|
foreach ($gids as $gid) {
|
|
|
|
if (in_array($gid, $finalids)) {
|
|
|
|
continue; // already final
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$grade_items[$gid]->needsupdate) {
|
|
|
|
$finalids[] = $gid; // we can make it final - does not need update
|
2007-06-18 13:43:40 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$doupdate = true;
|
2007-07-08 14:57:19 +00:00
|
|
|
foreach ($depends_on[$gid] as $did) {
|
2007-06-18 13:43:40 +00:00
|
|
|
if (!in_array($did, $finalids)) {
|
|
|
|
$doupdate = false;
|
2007-07-19 17:36:36 +00:00
|
|
|
continue; // this item depends on something that is not yet in finals array
|
2007-06-18 13:43:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//oki - let's update, calculate or aggregate :-)
|
|
|
|
if ($doupdate) {
|
2007-07-19 17:36:36 +00:00
|
|
|
$result = $grade_items[$gid]->regrade_final_grades($userid);
|
2007-07-08 14:57:19 +00:00
|
|
|
|
|
|
|
if ($result === true) {
|
2007-07-19 17:36:36 +00:00
|
|
|
$grade_items[$gid]->regrading_finished();
|
2007-08-09 09:03:14 +00:00
|
|
|
$grade_items[$gid]->check_locktime(); // do the locktime item locking
|
2007-07-08 14:57:19 +00:00
|
|
|
$count++;
|
2007-06-18 13:43:40 +00:00
|
|
|
$finalids[] = $gid;
|
2007-08-09 09:03:14 +00:00
|
|
|
|
2007-07-08 14:57:19 +00:00
|
|
|
} else {
|
2007-07-19 17:36:36 +00:00
|
|
|
$grade_items[$gid]->force_regrading();
|
2007-07-08 14:57:19 +00:00
|
|
|
$errors[$gid] = $result;
|
2007-06-18 13:43:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($count == 0) {
|
2007-07-21 10:09:57 +00:00
|
|
|
$failed++;
|
|
|
|
} else {
|
|
|
|
$failed = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($failed > 1) {
|
2007-07-19 17:36:36 +00:00
|
|
|
foreach($gids as $gid) {
|
|
|
|
if (in_array($gid, $finalids)) {
|
|
|
|
continue; // this one is ok
|
|
|
|
}
|
|
|
|
$grade_items[$gid]->force_regrading();
|
|
|
|
$errors[$grade_items[$gid]->id] = 'Probably circular reference or broken calculation formula'; // TODO: localize
|
2007-06-18 13:43:40 +00:00
|
|
|
}
|
2007-07-19 17:36:36 +00:00
|
|
|
break; // oki, found error
|
2007-06-18 13:43:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count($errors) == 0) {
|
2007-08-09 09:03:14 +00:00
|
|
|
if (empty($userid)) {
|
|
|
|
// do the locktime locking of grades, but only when doing full regrading
|
2007-08-09 12:45:36 +00:00
|
|
|
grade_grade::check_locktime_all($gids);
|
2007-08-09 09:03:14 +00:00
|
|
|
}
|
2007-06-18 13:43:40 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return $errors;
|
|
|
|
}
|
2007-04-30 04:49:25 +00:00
|
|
|
}
|
2007-05-04 02:15:46 +00:00
|
|
|
|
2007-05-29 00:56:44 +00:00
|
|
|
/**
|
2007-06-12 10:33:52 +00:00
|
|
|
* For backwards compatibility with old third-party modules, this function can
|
|
|
|
* be used to import all grades from activities with legacy grading.
|
2007-11-28 09:43:47 +00:00
|
|
|
* @param int $courseid
|
2007-05-04 02:15:46 +00:00
|
|
|
*/
|
2007-11-28 09:43:47 +00:00
|
|
|
function grade_grab_legacy_grades($courseid) {
|
2007-06-20 23:06:29 +00:00
|
|
|
global $CFG;
|
2007-05-04 02:15:46 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2007-06-12 10:33:52 +00:00
|
|
|
$fullmod = $CFG->dirroot.'/mod/'.$mod;
|
2007-05-04 02:15:46 +00:00
|
|
|
|
|
|
|
// include the module lib once
|
|
|
|
if (file_exists($fullmod.'/lib.php')) {
|
|
|
|
include_once($fullmod.'/lib.php');
|
2007-05-29 00:56:44 +00:00
|
|
|
// look for modname_grades() function - old gradebook pulling function
|
|
|
|
// if present sync the grades with new grading system
|
2007-05-04 02:15:46 +00:00
|
|
|
$gradefunc = $mod.'_grades';
|
2007-05-29 00:56:44 +00:00
|
|
|
if (function_exists($gradefunc)) {
|
2007-11-28 09:43:47 +00:00
|
|
|
grade_grab_course_grades($courseid, $mod);
|
2007-05-04 02:15:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-20 23:06:29 +00:00
|
|
|
/**
|
2007-11-28 09:43:47 +00:00
|
|
|
* Refetches data from all course activities
|
|
|
|
* @param int $courseid
|
|
|
|
* @param string $modname
|
|
|
|
* @return success
|
2007-06-20 23:06:29 +00:00
|
|
|
*/
|
2007-11-28 09:43:47 +00:00
|
|
|
function grade_grab_course_grades($courseid, $modname=null) {
|
2007-06-20 23:06:29 +00:00
|
|
|
global $CFG;
|
|
|
|
|
2007-11-28 09:43:47 +00:00
|
|
|
if ($modname) {
|
|
|
|
$sql = "SELECT a.*, cm.idnumber as cmidnumber, m.name as modname
|
|
|
|
FROM {$CFG->prefix}$modname a, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2007-06-20 23:06:29 +00:00
|
|
|
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')) {
|
2007-11-28 09:43:47 +00:00
|
|
|
// get all instance of the activity
|
|
|
|
$sql = "SELECT a.*, cm.idnumber as cmidnumber, m.name as modname
|
|
|
|
FROM {$CFG->prefix}$mod a, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m
|
|
|
|
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);
|
|
|
|
}
|
2007-06-20 23:06:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-12 10:33:52 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2007-08-06 15:18:54 +00:00
|
|
|
function grade_update_mod_grades($modinstance, $userid=0) {
|
2007-06-12 10:33:52 +00:00
|
|
|
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)) {
|
2007-08-06 15:18:54 +00:00
|
|
|
|
|
|
|
// legacy module - not yet converted
|
2007-06-12 10:33:52 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2007-11-29 14:43:04 +00:00
|
|
|
if (!empty($oldgrades->grades)) {
|
|
|
|
$grades = array();
|
2007-06-12 10:33:52 +00:00
|
|
|
|
2007-11-29 14:43:04 +00:00
|
|
|
foreach ($oldgrades->grades as $uid=>$usergrade) {
|
|
|
|
if ($userid and $uid != $userid) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$grade = new object();
|
|
|
|
$grade->userid = $uid;
|
2007-06-12 10:33:52 +00:00
|
|
|
|
2007-11-29 14:43:04 +00:00
|
|
|
if ($usergrade == '-') {
|
|
|
|
// no grade
|
|
|
|
$grade->rawgrade = null;
|
2007-06-12 10:33:52 +00:00
|
|
|
|
2007-11-29 14:43:04 +00:00
|
|
|
} 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;
|
2007-06-12 10:33:52 +00:00
|
|
|
}
|
|
|
|
|
2007-11-29 14:43:04 +00:00
|
|
|
grade_update('legacygrab', $grade_item->courseid, $grade_item->itemtype, $grade_item->itemmodule,
|
|
|
|
$grade_item->iteminstance, $grade_item->itemnumber, $grades);
|
|
|
|
}
|
2007-06-12 10:33:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} else if (function_exists($updategradesfunc) and function_exists($updateitemfunc)) {
|
|
|
|
//new grading supported, force updating of grades
|
|
|
|
$updateitemfunc($modinstance);
|
2007-08-06 15:18:54 +00:00
|
|
|
$updategradesfunc($modinstance, $userid);
|
2007-06-12 10:33:52 +00:00
|
|
|
|
|
|
|
} else {
|
2007-08-06 15:18:54 +00:00
|
|
|
// mudule does not support grading??
|
2007-06-12 10:33:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2007-05-29 00:56:44 +00:00
|
|
|
|
|
|
|
/**
|
2007-06-12 10:33:52 +00:00
|
|
|
* Get and update/create grade item for legacy modules.
|
2007-05-29 00:56:44 +00:00
|
|
|
*/
|
|
|
|
function grade_get_legacy_grade_item($modinstance, $grademax, $scaleid) {
|
|
|
|
|
|
|
|
// does it already exist?
|
2007-07-22 21:43:47 +00:00
|
|
|
if ($grade_items = grade_item::fetch_all(array('courseid'=>$modinstance->course, 'itemtype'=>'mod', 'itemmodule'=>$modinstance->modname, 'iteminstance'=>$modinstance->id, 'itemnumber'=>0))) {
|
2007-05-29 00:56:44 +00:00
|
|
|
if (count($grade_items) > 1) {
|
2007-06-12 10:33:52 +00:00
|
|
|
debugging('Multiple legacy grade_items found.');
|
2007-05-29 00:56:44 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$grade_item = reset($grade_items);
|
|
|
|
|
2007-06-12 10:33:52 +00:00
|
|
|
if (is_null($grademax) and is_null($scaleid)) {
|
|
|
|
$grade_item->gradetype = GRADE_TYPE_NONE;
|
2007-05-29 00:56:44 +00:00
|
|
|
|
2007-06-12 10:33:52 +00:00
|
|
|
} else if ($scaleid) {
|
|
|
|
$grade_item->gradetype = GRADE_TYPE_SCALE;
|
|
|
|
$grade_item->scaleid = $scaleid;
|
2007-06-26 08:50:22 +00:00
|
|
|
$grade_item->grademin = 1;
|
2007-05-29 00:56:44 +00:00
|
|
|
|
2007-06-12 10:33:52 +00:00
|
|
|
} else {
|
2007-06-26 08:50:22 +00:00
|
|
|
$grade_item->gradetype = GRADE_TYPE_VALUE;
|
|
|
|
$grade_item->grademax = $grademax;
|
|
|
|
$grade_item->grademin = 0;
|
2007-05-29 00:56:44 +00:00
|
|
|
}
|
|
|
|
|
2007-06-12 10:33:52 +00:00
|
|
|
$grade_item->itemname = $modinstance->name;
|
|
|
|
$grade_item->idnumber = $modinstance->cmidnumber;
|
2007-05-29 00:56:44 +00:00
|
|
|
|
2007-06-12 10:33:52 +00:00
|
|
|
$grade_item->update();
|
2007-05-29 00:56:44 +00:00
|
|
|
|
|
|
|
return $grade_item;
|
|
|
|
}
|
2007-06-05 22:58:37 +00:00
|
|
|
|
2007-05-29 00:56:44 +00:00
|
|
|
// create new one
|
2007-06-12 10:33:52 +00:00
|
|
|
$params = array('courseid' =>$modinstance->course,
|
2007-05-29 00:56:44 +00:00
|
|
|
'itemtype' =>'mod',
|
|
|
|
'itemmodule' =>$modinstance->modname,
|
|
|
|
'iteminstance'=>$modinstance->id,
|
2007-06-12 10:33:52 +00:00
|
|
|
'itemnumber' =>0,
|
2007-05-29 00:56:44 +00:00
|
|
|
'itemname' =>$modinstance->name,
|
|
|
|
'idnumber' =>$modinstance->cmidnumber);
|
|
|
|
|
2007-06-12 10:33:52 +00:00
|
|
|
if (is_null($grademax) and is_null($scaleid)) {
|
|
|
|
$params['gradetype'] = GRADE_TYPE_NONE;
|
|
|
|
|
|
|
|
} else if ($scaleid) {
|
2007-06-05 22:58:37 +00:00
|
|
|
$params['gradetype'] = GRADE_TYPE_SCALE;
|
2007-05-29 00:56:44 +00:00
|
|
|
$params['scaleid'] = $scaleid;
|
2007-06-28 13:20:30 +00:00
|
|
|
$grade_item->grademin = 1;
|
2007-05-29 00:56:44 +00:00
|
|
|
} else {
|
2007-06-05 22:58:37 +00:00
|
|
|
$params['gradetype'] = GRADE_TYPE_VALUE;
|
2007-05-29 00:56:44 +00:00
|
|
|
$params['grademax'] = $grademax;
|
|
|
|
$params['grademin'] = 0;
|
|
|
|
}
|
|
|
|
|
2007-06-12 20:19:38 +00:00
|
|
|
$grade_item = new grade_item($params);
|
|
|
|
$grade_item->insert();
|
2007-05-29 00:56:44 +00:00
|
|
|
|
2007-06-12 20:19:38 +00:00
|
|
|
return $grade_item;
|
2007-05-29 00:56:44 +00:00
|
|
|
}
|
|
|
|
|
2007-10-09 16:07:15 +00:00
|
|
|
/**
|
|
|
|
* Remove grade letters for given context
|
|
|
|
* @param object $context
|
|
|
|
*/
|
|
|
|
function remove_grade_letters($context, $showfeedback) {
|
|
|
|
$strdeleted = get_string('deleted');
|
|
|
|
|
|
|
|
delete_records('grade_letters', 'contextid', $context->id);
|
|
|
|
if ($showfeedback) {
|
|
|
|
notify($strdeleted.' - '.get_string('letters', 'grades'));
|
|
|
|
}
|
|
|
|
}
|
2007-08-03 19:25:22 +00:00
|
|
|
/**
|
|
|
|
* Remove all grade related course data - history is kept
|
|
|
|
* @param int $courseid
|
2007-09-15 19:24:10 +00:00
|
|
|
* @param bool @showfeedback print feedback
|
2007-08-03 19:25:22 +00:00
|
|
|
*/
|
|
|
|
function remove_course_grades($courseid, $showfeedback) {
|
|
|
|
$strdeleted = get_string('deleted');
|
|
|
|
|
|
|
|
$course_category = grade_category::fetch_course_category($courseid);
|
|
|
|
$course_category->delete('coursedelete');
|
|
|
|
if ($showfeedback) {
|
|
|
|
notify($strdeleted.' - '.get_string('grades', 'grades').', '.get_string('items', 'grades').', '.get_string('categories', 'grades'));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($outcomes = grade_outcome::fetch_all(array('courseid'=>$courseid))) {
|
|
|
|
foreach ($outcomes as $outcome) {
|
|
|
|
$outcome->delete('coursedelete');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete_records('grade_outcomes_courses', 'courseid', $courseid);
|
|
|
|
if ($showfeedback) {
|
|
|
|
notify($strdeleted.' - '.get_string('outcomes', 'grades'));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($scales = grade_scale::fetch_all(array('courseid'=>$courseid))) {
|
|
|
|
foreach ($scales as $scale) {
|
|
|
|
$scale->delete('coursedelete');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($showfeedback) {
|
|
|
|
notify($strdeleted.' - '.get_string('scales'));
|
|
|
|
}
|
2007-10-09 16:07:15 +00:00
|
|
|
|
|
|
|
delete_records('grade_settings', 'courseid', $courseid);
|
|
|
|
if ($showfeedback) {
|
|
|
|
notify($strdeleted.' - '.get_string('settings', 'grades'));
|
|
|
|
}
|
2007-08-03 19:25:22 +00:00
|
|
|
}
|
2007-05-14 09:38:41 +00:00
|
|
|
|
2008-01-21 23:36:19 +00:00
|
|
|
/**
|
|
|
|
* Does gradebook cleanup when module uninstalled.
|
|
|
|
*/
|
|
|
|
function grade_uninstalled_module($modname) {
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
$sql = "SELECT *
|
|
|
|
FROM {$CFG->prefix}grade_items
|
|
|
|
WHERE itemtype='mod' AND itemmodule='$modname'";
|
|
|
|
|
|
|
|
// go all items for this module and delete them including the grades
|
|
|
|
if ($rs = get_recordset_sql($sql)) {
|
|
|
|
while ($item = rs_fetch_next_record($rs)) {
|
|
|
|
$grade_item = new grade_item($item, false);
|
|
|
|
$grade_item->delete('moduninstall');
|
|
|
|
}
|
|
|
|
rs_close($rs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-09 09:38:14 +00:00
|
|
|
/**
|
|
|
|
* Grading cron job
|
|
|
|
*/
|
|
|
|
function grade_cron() {
|
2007-08-09 10:07:47 +00:00
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
$now = time();
|
|
|
|
|
|
|
|
$sql = "SELECT i.*
|
|
|
|
FROM {$CFG->prefix}grade_items i
|
|
|
|
WHERE i.locked = 0 AND i.locktime > 0 AND i.locktime < $now AND EXISTS (
|
2007-08-09 11:10:13 +00:00
|
|
|
SELECT 'x' FROM {$CFG->prefix}grade_items c WHERE c.itemtype='course' AND c.needsupdate=0 AND c.courseid=i.courseid)";
|
2007-08-09 10:07:47 +00:00
|
|
|
|
2007-08-09 09:38:14 +00:00
|
|
|
// go through all courses that have proper final grades and lock them if needed
|
2007-08-09 10:07:47 +00:00
|
|
|
if ($rs = get_recordset_sql($sql)) {
|
2007-10-10 12:19:27 +00:00
|
|
|
while ($item = rs_fetch_next_record($rs)) {
|
|
|
|
$grade_item = new grade_item($item, false);
|
|
|
|
$grade_item->locked = $now;
|
|
|
|
$grade_item->update('locktime');
|
2007-08-09 09:38:14 +00:00
|
|
|
}
|
|
|
|
rs_close($rs);
|
|
|
|
}
|
2007-08-09 10:07:47 +00:00
|
|
|
|
2007-09-22 20:21:44 +00:00
|
|
|
$grade_inst = new grade_grade();
|
|
|
|
$fields = 'g.'.implode(',g.', $grade_inst->required_fields);
|
|
|
|
|
|
|
|
$sql = "SELECT $fields
|
2007-08-09 10:07:47 +00:00
|
|
|
FROM {$CFG->prefix}grade_grades g, {$CFG->prefix}grade_items i
|
|
|
|
WHERE g.locked = 0 AND g.locktime > 0 AND g.locktime < $now AND g.itemid=i.id AND EXISTS (
|
2007-08-09 11:10:13 +00:00
|
|
|
SELECT 'x' FROM {$CFG->prefix}grade_items c WHERE c.itemtype='course' AND c.needsupdate=0 AND c.courseid=i.courseid)";
|
2007-08-09 10:07:47 +00:00
|
|
|
|
|
|
|
// go through all courses that have proper final grades and lock them if needed
|
|
|
|
if ($rs = get_recordset_sql($sql)) {
|
2007-10-10 12:19:27 +00:00
|
|
|
while ($grade = rs_fetch_next_record($rs)) {
|
|
|
|
$grade_grade = new grade_grade($grade, false);
|
|
|
|
$grade_grade->locked = $now;
|
|
|
|
$grade_grade->update('locktime');
|
2007-08-09 10:07:47 +00:00
|
|
|
}
|
|
|
|
rs_close($rs);
|
|
|
|
}
|
|
|
|
|
2007-11-08 08:59:26 +00:00
|
|
|
//TODO: do not run this cleanup every cron invocation
|
|
|
|
// cleanup history tables
|
2007-11-28 09:43:47 +00:00
|
|
|
if (!empty($CFG->gradehistorylifetime)) { // value in days
|
|
|
|
$histlifetime = $now - ($CFG->gradehistorylifetime * 3600 * 24);
|
|
|
|
$tables = array('grade_outcomes_history', 'grade_categories_history', 'grade_items_history', 'grade_grades_history', 'scale_history');
|
|
|
|
foreach ($tables as $table) {
|
|
|
|
if (delete_records_select($table, "timemodified < $histlifetime")) {
|
|
|
|
mtrace(" Deleted old grade history records from '$table'");
|
2007-11-08 08:59:26 +00:00
|
|
|
}
|
|
|
|
}
|
2007-11-28 09:43:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resel all course grades
|
|
|
|
* @param int $courseid
|
|
|
|
* @return success
|
|
|
|
*/
|
|
|
|
function grade_course_reset($courseid) {
|
|
|
|
|
|
|
|
// no recalculations
|
|
|
|
grade_force_full_regrading($courseid);
|
|
|
|
|
|
|
|
$grade_items = grade_item::fetch_all(array('courseid'=>$courseid));
|
|
|
|
foreach ($grade_items as $gid=>$grade_item) {
|
|
|
|
$grade_item->delete_all_grades('reset');
|
|
|
|
}
|
2007-11-08 08:59:26 +00:00
|
|
|
|
2007-11-28 09:43:47 +00:00
|
|
|
//refetch all grades
|
|
|
|
grade_grab_course_grades($courseid);
|
2007-11-08 08:59:26 +00:00
|
|
|
|
2007-11-28 09:43:47 +00:00
|
|
|
// recalculate all grades
|
|
|
|
grade_regrade_final_grades($courseid);
|
|
|
|
return true;
|
2007-08-09 09:38:14 +00:00
|
|
|
}
|
|
|
|
|
2007-04-26 08:29:30 +00:00
|
|
|
?>
|