From 3ac4ad00507451416b1a59262699b0adee36c974 Mon Sep 17 00:00:00 2001 From: Rajesh Taneja Date: Tue, 8 Jan 2013 10:25:46 +0800 Subject: [PATCH] MDL-37339 Administration: Unique custom profile should not be checked if it's empty. Currently we have two options for custom profile fields 'Unique' and 'Required' If value s not entered for unique and not required field then we should allow duplicate empty values. If value is entered then we should check for unique input. In case field is unique and required then it should be always checked as required field can't be empty. --- user/profile/lib.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/user/profile/lib.php b/user/profile/lib.php index 4c193e4131d..2ea68f25bef 100644 --- a/user/profile/lib.php +++ b/user/profile/lib.php @@ -129,9 +129,19 @@ class profile_field_base { global $DB; $errors = array(); - /// Check for uniqueness of data if required - if ($this->is_unique()) { - $value = (is_array($usernew->{$this->inputname}) and isset($usernew->{$this->inputname}['text'])) ? $usernew->{$this->inputname}['text'] : $usernew->{$this->inputname}; + // Get input value. + if (isset($usernew->{$this->inputname})) { + if (is_array($usernew->{$this->inputname}) && isset($usernew->{$this->inputname}['text'])) { + $value = $usernew->{$this->inputname}['text']; + } else { + $value = $usernew->{$this->inputname}; + } + } else { + $value = ''; + } + + // Check for uniqueness of data if required. + if ($this->is_unique() && (($value !== '') || $this->is_required())) { $data = $DB->get_records_sql(' SELECT id, userid FROM {user_info_data}