MDL-61203 badges: Allow profile picture as badge criteria

This commit is contained in:
Stephen Bourget
2018-01-16 10:18:23 -05:00
parent 013f0b2266
commit cfdd8d12dd
3 changed files with 48 additions and 3 deletions
+14 -3
View File
@@ -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);
}
}
}
@@ -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"
+3
View File
@@ -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);