From 4c2402b2f83ef4127dae2aa3fca7080e227885c6 Mon Sep 17 00:00:00 2001 From: skodak Date: Tue, 31 Jul 2007 12:52:17 +0000 Subject: [PATCH] minor scale related changes, added fixed update() into grade_outcome class --- grade/edit/scale/edit_form.php | 2 +- grade/edit/scale/index.php | 10 +++++----- lib/grade/grade_outcome.php | 19 +++++++++++++++++++ lib/grade/grade_scale.php | 5 +++-- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/grade/edit/scale/edit_form.php b/grade/edit/scale/edit_form.php index 20eed49bf27..771efe1edac 100644 --- a/grade/edit/scale/edit_form.php +++ b/grade/edit/scale/edit_form.php @@ -52,7 +52,7 @@ class edit_scale_form extends moodleform { if ($id = $mform->getElementValue('id')) { $scale = grade_scale::fetch(array('id'=>$id)); - $count = $scale->get_uses_count(); + $count = $scale->get_item_uses_count(); if ($count) { $mform->hardFreeze('scale'); diff --git a/grade/edit/scale/index.php b/grade/edit/scale/index.php index 32d652cf114..aad193d7565 100644 --- a/grade/edit/scale/index.php +++ b/grade/edit/scale/index.php @@ -39,7 +39,7 @@ $strname = get_string('name'); $strdelete = get_string('delete'); $stredit = get_string('edit'); $srtcreatenewscale = get_string('scalescustomcreate'); -$stractivities = get_string('activities'); +$stritems = get_string('items', 'grades'); $stredit = get_string('edit'); switch ($action) { @@ -84,7 +84,7 @@ if ($courseid and $scales = grade_scale::fetch_all_local($courseid)) { $line = array(); $line[] = format_string($scale->name).'
'.str_replace(",",", ",$scale->scale).'
'; - $scales_uses = $scale->get_uses_count(); + $scales_uses = $scale->get_item_uses_count(); $line[] = $scales_uses; $buttons = ""; @@ -97,7 +97,7 @@ if ($courseid and $scales = grade_scale::fetch_all_local($courseid)) { $line[] = $buttons; $data[] = $line; } - $table->head = array($strscale, $stractivities, $stredit); + $table->head = array($strscale, $stritems, $stredit); $table->size = array('70%', '20%', '10%'); $table->align = array('left', 'center', 'center'); $table->width = '90%'; @@ -112,7 +112,7 @@ if ($scales = grade_scale::fetch_all_global()) { $line = array(); $line[] = format_string($scale->name).'
'.str_replace(",",", ",$scale->scale).'
'; - $scales_uses = $scale->get_uses_count(); + $scales_uses = $scale->get_item_uses_count(); $line[] = $scales_uses; $buttons = ""; @@ -127,7 +127,7 @@ if ($scales = grade_scale::fetch_all_global()) { $line[] = $buttons; $data[] = $line; } - $table->head = array($strscale, $stractivities, $stredit); + $table->head = array($strscale, $stritems, $stredit); $table->size = array('70%', '20%', '10%'); $table->align = array('left', 'center', 'center'); $table->width = '90%'; diff --git a/lib/grade/grade_outcome.php b/lib/grade/grade_outcome.php index 3087266a182..af00c562dec 100644 --- a/lib/grade/grade_outcome.php +++ b/lib/grade/grade_outcome.php @@ -107,6 +107,25 @@ class grade_outcome extends grade_object { return $result; } + /** + * In addition to update() it also updates grade_outcomes_courses if needed + * @param string $source from where was the object inserted + * @return boolean success + */ + function update($source=null) { + if ($result = parent::update($source)) { + if (!empty($this->courseid)) { + if (!get_records('grade_outcomes_courses', 'courseid', $this->courseid, 'outcomeid', $this->id)) { + $goc = new object(); + $goc->courseid = $this->courseid; + $goc->outcomeid = $this->id; + insert_record('grade_outcomes_courses', $goc); + } + } + } + return $result; + } + /** * Finds and returns a grade_outcome instance based on params. * @static diff --git a/lib/grade/grade_scale.php b/lib/grade/grade_scale.php index bafec25615e..af1df4d0c24 100644 --- a/lib/grade/grade_scale.php +++ b/lib/grade/grade_scale.php @@ -200,7 +200,7 @@ class grade_scale extends grade_object { * @return boolean */ function can_delete() { - $count = $this->get_uses_count(); + $count = $this->get_item_uses_count(); return empty($count); } @@ -208,9 +208,10 @@ class grade_scale extends grade_object { * Returns the number of places where scale is used - activities, grade items, outcomes, etc. * @return int */ - function get_uses_count() { + function get_item_uses_count() { global $CFG; +//TODO: fix me - this methods does some duplicate counting in grade items and activities $count = 0; if (!empty($this->courseid)) { if ($scales_uses = course_scale_used($this->courseid,$this->id)) {