From: nicolasconnault Date: Wed, 27 Feb 2008 12:48:20 +0000 (+0000) Subject: MDL-13674 Course category fullname field is no longer required. If set to empty it... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=8f6fdf4335e21fe9bf9abb80c1f4473ee7ac158b;p=moodle.git MDL-13674 Course category fullname field is no longer required. If set to empty it will be recorded in the DB as ?, and the course name will be used instead wherever the category name is displayed. Merging from MOODLE_19_STABLE. --- diff --git a/grade/edit/tree/category.php b/grade/edit/tree/category.php index c1b66a8ede..853bcfe291 100644 --- a/grade/edit/tree/category.php +++ b/grade/edit/tree/category.php @@ -75,6 +75,11 @@ if ($mform->is_cancelled()) { redirect($returnurl); } else if ($data = $mform->get_data(false)) { + // If no fullname is entered for a course category, put ? in the DB + if (!isset($data->fullname) || $data->fullname == '') { + $data->fullname = '?'; + } + if (!isset($data->aggregateonlygraded)) { $data->aggregateonlygraded = 0; } diff --git a/grade/edit/tree/category_form.php b/grade/edit/tree/category_form.php index 5c5958f9dc..3768d8bfd9 100644 --- a/grade/edit/tree/category_form.php +++ b/grade/edit/tree/category_form.php @@ -266,6 +266,18 @@ class edit_category_form extends moodleform { $mform->removeElement('aggregatesubcats'); } } + + // If it is a course category, remove the "required" rule from the "fullname" element + if ($grade_category->is_course_category()) { + unset($mform->_rules['fullname']); + $key = array_search('fullname', $mform->_required); + unset($mform->_required[$key]); + } + + // If it is a course category and its fullname is ?, show an empty field + if ($grade_category->is_course_category() && $mform->getElementValue('fullname') == '?') { + $mform->setDefault('fullname', ''); + } } // no parent header for course category @@ -273,8 +285,7 @@ class edit_category_form extends moodleform { $mform->removeElement('headerparent'); } - } - + } } ?> diff --git a/lib/db/upgradelib.php b/lib/db/upgradelib.php index f27b7862f5..8a227ee9be 100644 --- a/lib/db/upgradelib.php +++ b/lib/db/upgradelib.php @@ -129,7 +129,7 @@ function upgrade_18_gradebook($courseid) { // create course category $course_category = new object(); $course_category->courseid = $courseid; - $course_category->fullname = get_string('coursegradecategory', 'grades'); + $course_category->fullname = '?'; $course_category->parent = null; $course_category->aggregation = GRADE_AGGREGATE_WEIGHTED_MEAN2; $course_category->timemodified = $course_category->timecreated = time(); diff --git a/lib/grade/grade_category.php b/lib/grade/grade_category.php index e8d7a36095..495001b6b5 100644 --- a/lib/grade/grade_category.php +++ b/lib/grade/grade_category.php @@ -315,7 +315,7 @@ class grade_category extends grade_object { */ function insert_course_category($courseid) { $this->courseid = $courseid; - $this->fullname = get_string('coursegradecategory', 'grades'); + $this->fullname = '?'; $this->path = null; $this->parent = null; $this->aggregation = GRADE_AGGREGATE_WEIGHTED_MEAN2; @@ -995,7 +995,8 @@ class grade_category extends grade_object { * @return string name */ function get_name() { - if (empty($this->parent)) { + // For a course category, we return the course name if the fullname is set to '?' in the DB (empty in the category edit form) + if (empty($this->parent) && $this->fullname == '?') { $course = get_record('course', 'id', $this->courseid); return format_string($course->fullname); } else {