Skip to content

Commit

Permalink
Merge branch 'MDL-61203_m35v3' of git://github.com/sbourget/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Jan 23, 2018
2 parents b878578 + cfdd8d1 commit 6d326e1
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
17 changes: 14 additions & 3 deletions badges/criteria/award_criteria_profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function get_options(&$mform) {

// 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
Expand Down Expand Up @@ -185,7 +185,12 @@ public function review($userid, $filtered = false) {
$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);
}
}
}

Expand Down Expand Up @@ -224,7 +229,13 @@ public function get_completed_criteria_sql() {
$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);
}
}
}

Expand Down
31 changes: 31 additions & 0 deletions badges/tests/behat/criteria_profile.feature
Original file line number Diff line number Diff line change
@@ -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 changes: 3 additions & 0 deletions lib/moodlelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 6d326e1

Please sign in to comment.