Merge branch 'MDL-18375_master' of git://github.com/markn86/moodle
authorDamyon Wiese <damyon@moodle.com>
Mon, 9 Sep 2013 02:41:12 +0000 (10:41 +0800)
committerDamyon Wiese <damyon@moodle.com>
Mon, 9 Sep 2013 02:41:12 +0000 (10:41 +0800)
1  2 
course/edit_form.php
lib/classes/component.php
version.php

@@@ -327,25 -338,27 +338,31 @@@ class course_edit_form extends moodlefo
          }
      }
  
- /// perform some extra moodle validation
+     /**
+      * Validation.
+      *
+      * @param array $data
+      * @param array $files
+      * @return array the errors that were found
+      */
      function validation($data, $files) {
 -        global $DB, $CFG;
 +        global $DB;
  
          $errors = parent::validation($data, $files);
 -        if ($foundcourses = $DB->get_records('course', array('shortname'=>$data['shortname']))) {
 -            if (!empty($data['id'])) {
 -                unset($foundcourses[$data['id']]);
 +
 +        // Add field validation check for duplicate shortname.
 +        if ($course = $DB->get_record('course', array('shortname' => $data['shortname']), '*', IGNORE_MULTIPLE)) {
 +            if (empty($data['id']) || $course->id != $data['id']) {
 +                $errors['shortname'] = get_string('shortnametaken', '', $course->fullname);
              }
 -            if (!empty($foundcourses)) {
 -                foreach ($foundcourses as $foundcourse) {
 -                    $foundcoursenames[] = $foundcourse->fullname;
 +        }
 +
 +        // Add field validation check for duplicate idnumber.
 +        if (!empty($data['idnumber']) && (empty($data['id']) || $this->course->idnumber != $data['idnumber'])) {
 +            if ($course = $DB->get_record('course', array('idnumber' => $data['idnumber']), '*', IGNORE_MULTIPLE)) {
 +                if (empty($data['id']) || $course->id != $data['id']) {
 +                    $errors['idnumber'] = get_string('courseidnumbertaken', 'error', $course->fullname);
                  }
 -                $foundcoursenamestring = implode(',', $foundcoursenames);
 -                $errors['shortname']= get_string('shortnametaken', '', $foundcoursenamestring);
              }
          }
  
Simple merge
diff --cc version.php
Simple merge