From: moodler Date: Fri, 11 May 2007 02:11:30 +0000 (+0000) Subject: Removed set_timecreated and just tidied up some time-related things X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=b55997c11226333580b78fabb02ae85d037ee9a7;p=moodle.git Removed set_timecreated and just tidied up some time-related things --- diff --git a/lib/grade/grade_history.php b/lib/grade/grade_history.php index 2ee1a36597..56fb5f669b 100644 --- a/lib/grade/grade_history.php +++ b/lib/grade/grade_history.php @@ -125,7 +125,7 @@ class grade_history extends grade_object { $history->newgrade = $grade_raw->gradevalue; $history->note = $note; $history->howmodified = $howmodified; - $history->timemodified = mktime(); + $history->timemodified = time(); $history->usermodified = $USER->id; return $history->insert(); diff --git a/lib/grade/grade_item.php b/lib/grade/grade_item.php index bee72d733c..823759d342 100644 --- a/lib/grade/grade_item.php +++ b/lib/grade/grade_item.php @@ -25,7 +25,6 @@ require_once('grade_object.php'); global $db; -$db->debug = true; /** * Class representing a grade item. It is responsible for handling its DB representation, * modifying and returning its metadata. diff --git a/lib/grade/grade_object.php b/lib/grade/grade_object.php index ed9881d46f..f1a3e53c51 100644 --- a/lib/grade/grade_object.php +++ b/lib/grade/grade_object.php @@ -107,7 +107,11 @@ class grade_object { function insert() { global $USER; - $this->set_timecreated(); + if (!empty($this->id)) { // Object already exists, so let's do an update instead + $this->update(); + } + + $this->timecreated = $this->timemodified = time(); if (empty($this->usermodified)) { $this->usermodified = $USER->id; @@ -179,38 +183,7 @@ class grade_object { } } - /** - * If this object hasn't yet been saved in DB (empty $id), this method sets the timecreated variable - * to the current or given time. If a value is already set in DB, - * this method will do nothing, unless the $override parameter is set to true. This is to avoid - * unintentional overwrites. - * - * @param int $timestamp Optional timestamp to override current timestamp. - * @param boolean $override Whether to override an existing value for this field in the DB. - * @return boolean True if successful, false otherwise. - */ - function set_timecreated($timestamp = null, $override = false) { - if (empty($timestamp)) { - $timestamp = time(); - } - - if (empty($this->id)) { - $this->timecreated = $timestamp; - $this->timemodified = $timestamp; - } else { - $current_time = get_field($this->table, 'timecreated', 'id', $this->id); - - if (empty($current_time) || $override) { - $this->timecreated = $timestamp; - $this->timemodified = $timestamp; - return $this->timecreated; - } else { - return false; - } - } - return $this->timecreated; - } - + /** * Given an associated array or object, cycles through each key/variable * and assigns the value to the corresponding variable in this object. diff --git a/lib/simpletest/grade/simpletest/testgradeitem.php b/lib/simpletest/grade/simpletest/testgradeitem.php index f8019b6f7a..a64f5204bb 100755 --- a/lib/simpletest/grade/simpletest/testgradeitem.php +++ b/lib/simpletest/grade/simpletest/testgradeitem.php @@ -139,15 +139,6 @@ class grade_item_test extends gradelib_test { $this->assertTrue($grade_item->qualifies_for_update()); } - function test_grade_item_set_timecreated() { - $grade_item = new grade_item($this->grade_items[0]); - $this->assertTrue(method_exists($grade_item, 'set_timecreated')); - - $timestamp = mktime(); - $grade_item->set_timecreated(); - $this->assertEqual($grade_item->timecreated, get_field('grade_items', 'timecreated', 'id', $grade_item->id)); - } - function test_grade_item_fetch() { $grade_item = new grade_item(); $this->assertTrue(method_exists($grade_item, 'fetch'));