regular whitespace cleanup in grade code

This commit is contained in:
skodak 2007-07-18 19:56:07 +00:00
parent e1d2692a73
commit ba74762bda
21 changed files with 297 additions and 297 deletions

View file

@ -1,53 +1,53 @@
<?php // $Id$
/**
* given an import code, commits all entries in buffer tables
* given an import code, commits all entries in buffer tables
* (grade_import_value and grade_import_newitem)
* If this function is called, we assume that all data collected
* If this function is called, we assume that all data collected
* up to this point is fine and we can go ahead and commit
* @param int courseid - id of the course
* @param string importcode - import batch identifier
*/
function grade_import_commit($courseid, $importcode) {
global $CFG;
include_once($CFG->libdir.'/gradelib.php');
include_once($CFG->libdir.'/grade/grade_item.php');
$commitstart = time(); // start time in case we need to roll back
$newitemids = array(); // array to hold new grade_item ids from grade_import_newitem table, mapping array
/// first select distinct new grade_items with this batch
if ($newitems = get_records_sql("SELECT *
if ($newitems = get_records_sql("SELECT *
FROM {$CFG->prefix}grade_import_newitem
WHERE import_code = $importcode")) {
// instances of the new grade_items created, cached
// instances of the new grade_items created, cached
// in case grade_update fails, so that we can remove them
$instances = array();
foreach ($newitems as $newitem) {
// get all grades with this item
if ($grades = get_records('grade_import_values', 'newgradeitem', $newitem->id)) {
if ($grades = get_records('grade_import_values', 'newgradeitem', $newitem->id)) {
// make the grardes array for update_grade
// find the max instance number of 'manual' grade item
// and increment that number by 1 by hand
// I can not find other ways to make 'manual' type work,
// unless we have a 'new' flag for grade_update to let it
// know that this is a new grade_item, and let grade_item
// handle the instance id in the case of a 'manual' import?
if ($lastimport = get_record_sql("SELECT *
if ($lastimport = get_record_sql("SELECT *
FROM {$CFG->prefix}grade_items
WHERE courseid = $courseid
AND itemtype = 'manual'
ORDER BY iteminstance DESC", true)) {
$instance = $lastimport->iteminstance + 1;
} else {
$instance = 1;
$instance = 1;
}
$instances[] = $instance;
// if fails, deletes all the created grade_items and grades
@ -57,7 +57,7 @@ function grade_import_commit($courseid, $importcode) {
// insert each individual grade to this new grade item
$failed = 0;
foreach ($grades as $grade) {
foreach ($grades as $grade) {
if (!$gradeitem->update_final_grade($grade->userid, $grade->finalgrade, NULL, NULL, $grade->feedback)) {
$failed = 1;
break;
@ -65,7 +65,7 @@ function grade_import_commit($courseid, $importcode) {
}
if ($failed) {
foreach ($instances as $instance) {
$gradeitem = new grade_item(array('courseid'=>$courseid, 'itemtype'=>'manual', 'iteminstance'=>$instance));
$gradeitem = new grade_item(array('courseid'=>$courseid, 'itemtype'=>'manual', 'iteminstance'=>$instance));
// this method does not seem to delete all the raw grades and the item itself
// which I think should be deleted in this case, can I use sql directly here?
$gradeitem->delete();
@ -79,15 +79,15 @@ function grade_import_commit($courseid, $importcode) {
/// then find all existing items
if ($gradeitems = get_records_sql("SELECT DISTINCT (itemid)
if ($gradeitems = get_records_sql("SELECT DISTINCT (itemid)
FROM {$CFG->prefix}grade_import_values
WHERE import_code = $importcode
AND itemid > 0")) {
$modifieditems = array();
foreach ($gradeitems as $itemid=>$iteminfo) {
if (!$gradeitem = new grade_item(array('id'=>$itemid))) {
// not supposed to happen, but just in case
import_cleanup($importcode);
@ -107,7 +107,7 @@ function grade_import_commit($courseid, $importcode) {
$modifieditems[] = $itemid;
}
if (!empty($failed)) {
import_cleanup($importcode);
return false;