From 70f9a148afa9fe4cea004772bbb216a87c7c1206 Mon Sep 17 00:00:00 2001 From: nicolasconnault Date: Wed, 9 May 2007 08:10:27 +0000 Subject: [PATCH] MDL-9506 Added grade_grades_text object to grade_grades_final and raw objects. --- lib/grade/grade_grades_final.php | 11 ++++++++--- lib/grade/grade_grades_raw.php | 16 ++++++++-------- lib/grade/grade_grades_text.php | 1 - 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/lib/grade/grade_grades_final.php b/lib/grade/grade_grades_final.php index 64d3a52720373..16a57394017e4 100644 --- a/lib/grade/grade_grades_final.php +++ b/lib/grade/grade_grades_final.php @@ -96,9 +96,14 @@ function grade_grades_final($params=NULL, $fetch=true) { } /** - * - function get_text() { - + * Loads the grade_grades_text object linked to this grade (through the intersection of itemid and userid), and + * saves it as a class variable for this final object. + * @return object + */ + function load_text() { + if (empty($this->grade_grades_text)) { + return $this->grade_grades_text = grade_grades_text::fetch('itemid', $this->itemid, 'userid', $this->userid); + } } /** diff --git a/lib/grade/grade_grades_raw.php b/lib/grade/grade_grades_raw.php index 3294e98e38bbb..eeceef3e32d92 100644 --- a/lib/grade/grade_grades_raw.php +++ b/lib/grade/grade_grades_raw.php @@ -91,9 +91,9 @@ class grade_grades_raw extends grade_object { * Additional textual information about this grade. It can be automatically generated * from the module or entered manually by the teacher. This is kept in its own table * for efficiency reasons, so it is encapsulated in its own object, and included in this raw grade object. - * @var object $text + * @var object $grade_grades_text */ - var $text; + var $grade_grades_text; /** * Constructor. Extends the basic functionality defined in grade_object. @@ -118,14 +118,14 @@ function load_scale() { } /** - * Loads the grade_grades_text object linked to this raw grade, into the $this->text variable, if - * such record exists. Otherwise returns null. + * Loads the grade_grades_text object linked to this grade (through the intersection of itemid and userid), and + * saves it as a class variable for this final object. + * @return object */ function load_text() { - if (!empty($this->id)) { - $this->text = grade_grades_text::fetch('gradesid', $this->id); - } - return $this->text; + if (empty($this->grade_grades_text)) { + return $this->grade_grades_text = grade_grades_text::fetch('itemid', $this->itemid, 'userid', $this->userid); + } } /** diff --git a/lib/grade/grade_grades_text.php b/lib/grade/grade_grades_text.php index f2e7a9d73db8b..9a28bd5bc156d 100644 --- a/lib/grade/grade_grades_text.php +++ b/lib/grade/grade_grades_text.php @@ -94,7 +94,6 @@ class grade_grades_text extends grade_object { function fetch($field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields="*") { if ($grade_text = get_record('grade_grades_text', $field1, $value1, $field2, $value2, $field3, $value3, $fields)) { if (isset($this) && get_class($this) == 'grade_grades_text') { - print_object($this); foreach ($grade_text as $param => $value) { $this->$param = $value; }