]> git.mjollnir.org Git - moodle.git/commitdiff
Removed set_timecreated and just tidied up some time-related things
authormoodler <moodler>
Fri, 11 May 2007 02:11:30 +0000 (02:11 +0000)
committermoodler <moodler>
Fri, 11 May 2007 02:11:30 +0000 (02:11 +0000)
lib/grade/grade_history.php
lib/grade/grade_item.php
lib/grade/grade_object.php
lib/simpletest/grade/simpletest/testgradeitem.php

index 2ee1a3659741186fcfad6f102bf3a4ccd2f81f9d..56fb5f669bea1429928525c7b404b3d7068db387 100644 (file)
@@ -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();
index bee72d733c1161b02f96a852ab9db3cff0bae144..823759d3427364f7111a34b79ff1f3d0d4fe4328 100644 (file)
@@ -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.
index ed9881d46ff0c7eca9e97ad12fd3ef57268f8d6e..f1a3e53c517d3e76dffb316f45c66ad0b6c8304b 100644 (file)
@@ -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.
index f8019b6f7afc86b46a3c27499d481c7ffbfdd456..a64f5204bbe16d51ba78e680d172d11b45d6138e 100755 (executable)
@@ -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'));