diff --git a/badges/criteria/award_criteria_profile.php b/badges/criteria/award_criteria_profile.php index 51b498818dc..da76bc87474 100644 --- a/badges/criteria/award_criteria_profile.php +++ b/badges/criteria/award_criteria_profile.php @@ -52,7 +52,7 @@ class award_criteria_profile extends award_criteria { // Note: cannot use user_get_default_fields() here because it is not possible to decide which fields user can modify. $dfields = array('firstname', 'lastname', 'email', 'address', 'phone1', 'phone2', 'icq', 'skype', 'yahoo', - 'aim', 'msn', 'department', 'institution', 'description', 'city', 'url', 'country'); + 'aim', 'msn', 'department', 'institution', 'description', 'picture', 'city', 'url', 'country'); $sql = "SELECT uf.id as fieldid, uf.name as name, ic.id as categoryid, ic.name as categoryname, uf.datatype FROM {user_info_field} uf @@ -185,7 +185,12 @@ class award_criteria_profile extends award_criteria { $whereparts[] = "uid{$idx}.id IS NOT NULL"; } else { // This is a field from {user} table. - $whereparts[] = $DB->sql_isnotempty('u', "u.{$param['field']}", false, true); + if ($param['field'] == 'picture') { + // The picture field is numeric and requires special handling. + $whereparts[] = "u.{$param['field']} != 0"; + } else { + $whereparts[] = $DB->sql_isnotempty('u', "u.{$param['field']}", false, true); + } } } @@ -224,7 +229,13 @@ class award_criteria_profile extends award_criteria { $params["fieldid{$idx}"] = $param['field']; $whereparts[] = "uid{$idx}.id IS NOT NULL"; } else { - $whereparts[] = $DB->sql_isnotempty('u', "u.{$param['field']}", false, true); + // This is a field from {user} table. + if ($param['field'] == 'picture') { + // The picture field is numeric and requires special handling. + $whereparts[] = "u.{$param['field']} != 0"; + } else { + $whereparts[] = $DB->sql_isnotempty('u', "u.{$param['field']}", false, true); + } } } diff --git a/badges/tests/behat/criteria_profile.feature b/badges/tests/behat/criteria_profile.feature new file mode 100644 index 00000000000..abdb166a477 --- /dev/null +++ b/badges/tests/behat/criteria_profile.feature @@ -0,0 +1,31 @@ +@core @core_badges @_file_upload +Feature: Award badges based on user profile field + In order to award badges to users based on completion of their user profile + As an admin + I need to add profile completion criteria to badges in the system + + @javascript + Scenario: Award badge for a uploading a profile picture. + Given the following "users" exist: + | username | firstname | lastname | email | + | user1 | First | User | first@example.com | + And I log in as "admin" + And I navigate to "Add a new badge" node in "Site administration > Badges" + And I set the following fields to these values: + | Name | Site Badge | + | Description | Site badge description | + | issuername | Tester of site badge | + And I upload "badges/tests/behat/badge.png" file to "Image" filemanager + And I press "Create badge" + And I set the field "type" to "Profile completion" + And I set the field "id_field_picture" to "1" + And I press "Save" + And I press "Enable access" + And I press "Continue" + And I log out + When I log in as "user1" + And I follow "Profile" in the user menu + And I click on "Edit profile" "link" in the "region-main" "region" + And I upload "badges/tests/behat/badge.png" file to "New picture" filemanager + And I press "Update profile" + Then I should see "Site Badge" diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 9ba9f3934e5..a488445d25d 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -3667,6 +3667,9 @@ function get_user_field_name($field) { case 'msn' : { return get_string('msnid'); } + case 'picture' : { + return get_string('pictureofuser'); + } } // Otherwise just use the same lang string. return get_string($field);