]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-17151: Missing code to check for uniqueness of values.
authorikawhero <ikawhero>
Fri, 7 Nov 2008 05:57:24 +0000 (05:57 +0000)
committerikawhero <ikawhero>
Fri, 7 Nov 2008 05:57:24 +0000 (05:57 +0000)
Merged from MOODLE_19_STABLE

lang/en_utf8/moodle.php
user/profile/lib.php

index 7fa071581cb24e10e879fbce7cb92e0a6a1a6f99..4965e7a71f8cfd4048d7bd24cd17176106263b41 100644 (file)
@@ -1602,6 +1602,7 @@ $string['usersnoaccesssince'] = 'Inactive for more than';
 $string['userzones'] = 'User zones';
 $string['usethiscourse'] = 'Use this course';
 $string['usingexistingcourse'] = 'Using existing course';
+$string['valuealreadyused'] = 'This value has already been used.';
 $string['version'] = 'Version';
 $string['view'] = 'View';
 $string['viewfileinpopup'] = 'View file in a popup window';
index e4a3e2919844e00aafe950de39f746c42f6250d2..418769bbc0f41a33675dec87245bf419a2b814de 100644 (file)
@@ -110,8 +110,16 @@ class profile_field_base {
      * @return  string  contains error message otherwise NULL
      **/
     function edit_validate_field($usernew) {
-        //no errors by default
-        return array();
+        $errors = array();
+        /// Check for uniqueness of data if required
+        if ($this->is_unique()) {
+            if ($userid = get_field('user_info_data', 'userid', 'fieldid', $this->field->id, 'data', $usernew->{$this->inputname})) {
+                if ($userid != $usernew->id) {
+                    $errors["{$this->inputname}"] = get_string('valuealreadyused');
+                }
+            }
+        }
+        return $errors;
     }
 
     /**