From: skodak Date: Tue, 12 Jun 2007 20:19:38 +0000 (+0000) Subject: MDL-10104 grade_create_item() in gradelib.php was obsoleted by grade_update() functio... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=f70152b7bb351965a593952c7b9adca0b19da57d;p=moodle.git MDL-10104 grade_create_item() in gradelib.php was obsoleted by grade_update() function which does the creation and update of grade_items --- diff --git a/lib/gradelib.php b/lib/gradelib.php index ac6fbc4932..f91bd6c6d0 100644 --- a/lib/gradelib.php +++ b/lib/gradelib.php @@ -127,8 +127,8 @@ function grade_update($source, $courseid, $itemtype, $itemmodule, $iteminstance, $params[$k] = $v; } } - $itemid = grade_create_item($params); - $grade_item = grade_item::fetch('id', $itemid); + $grade_item = new grade_item($params); + $grade_item->insert(); } else { if ($grade_item->locked) { @@ -317,8 +317,8 @@ function grade_is_locked($courseid, $itemtype, $itemmodule, $iteminstance, $item * @param string $itemtype 'mod', 'blocks', 'import', 'calculated' etc * @param string $itemmodule 'forum, 'quiz', 'csv' etc * @param int $iteminstance id of the item module -* @param string $itemname The name of the grade item * @param int $itemnumber Can be used to distinguish multiple grades for an activity +* @param string $itemname The name of the grade item * @param int $idnumber grade item Primary Key * @return array An array of grade items */ @@ -328,25 +328,6 @@ function grade_get_items($courseid, $itemtype=NULL, $itemmodule=NULL, $iteminsta return $grade_items; } - -/** -* Creates a new grade_item in case it doesn't exist. -* This function is called when a new module is created. -* -* @param mixed $params array or object -* @return mixed New grade_item id if successful -*/ -function grade_create_item($params) { - $grade_item = new grade_item($params); - - if (empty($grade_item->id)) { - return $grade_item->insert(); - } else { - debugging('Grade item already exists - id:'.$grade_item->id); - return $grade_item->id; - } -} - /** * For a given set of items, create a category to group them together (if one doesn't yet exist). * Modules may want to do this when they are created. However, the ultimate control is in the gradebook interface itself. @@ -582,12 +563,10 @@ function grade_get_legacy_grade_item($modinstance, $grademax, $scaleid) { $params['grademin'] = 0; } - if (!$itemid = grade_create_item($params)) { - debugging('Can not create new legacy grade item'); - return false; - } + $grade_item = new grade_item($params); + $grade_item->insert(); - return grade_item::fetch('id', $itemid); + return $grade_item; } /** diff --git a/lib/simpletest/testgradelib.php b/lib/simpletest/testgradelib.php index 01ddbcf97a..12f778045c 100644 --- a/lib/simpletest/testgradelib.php +++ b/lib/simpletest/testgradelib.php @@ -52,30 +52,6 @@ class gradelib_test extends grade_test { $this->assertEqual(count($grade_items), 10); } } - - function test_grade_create_item() { - if (get_class($this) == 'gradelib_test') { - $params = new stdClass(); - - $params->courseid = $this->courseid; - $params->categoryid = $this->grade_categories[0]->id; - $params->itemname = 'unittestgradeitem4'; - $params->itemtype = 'mod'; - $params->itemmodule = 'database'; - $params->grademin = 0; - $params->grademax = 100; - $params->iteminstance = 4; - $params->iteminfo = 'Grade item used for unit testing'; - $params->timecreated = mktime(); - $params->timemodified = mktime(); - - $params->id = grade_create_item($params); - $last_grade_item = end($this->grade_items); - - $this->assertEqual($params->id, $last_grade_item->id + 1); - $this->grade_items[] = $params; - } - } function test_grade_create_category() { if (get_class($this) == 'gradelib_test') {