diff --git a/blocks/myprofile/classes/output/myprofile.php b/blocks/myprofile/classes/output/myprofile.php index c604a37a67d..870313c3909 100644 --- a/blocks/myprofile/classes/output/myprofile.php +++ b/blocks/myprofile/classes/output/myprofile.php @@ -100,6 +100,10 @@ class myprofile implements renderable, templatable { $data->useraddress = format_string($USER->address); } + if (!empty($this->config->display_idnumber) && !empty($USER->idnumber)) { + $data->useridnumber = s($USER->idnumber); + } + if (!empty($this->config->display_firstaccess) && !empty($USER->firstaccess)) { $data->userfirstaccess = userdate($USER->firstaccess); } diff --git a/blocks/myprofile/edit_form.php b/blocks/myprofile/edit_form.php index 6de49b23ddb..167b7824a48 100644 --- a/blocks/myprofile/edit_form.php +++ b/blocks/myprofile/edit_form.php @@ -85,6 +85,13 @@ class block_myprofile_edit_form extends block_edit_form { $mform->setDefault('config_display_address', '0'); } + $mform->addElement('selectyesno', 'config_display_idnumber', get_string('display_idnumber', 'block_myprofile')); + if (isset($this->block->config->display_idnumber)) { + $mform->setDefault('config_display_idnumber', $this->block->config->display_idnumber); + } else { + $mform->setDefault('config_display_idnumber', '0'); + } + $mform->addElement('selectyesno', 'config_display_firstaccess', get_string('display_firstaccess', 'block_myprofile')); if (isset($this->block->config->display_firstaccess)) { $mform->setDefault('config_display_firstaccess', $this->block->config->display_firstaccess); diff --git a/blocks/myprofile/lang/en/block_myprofile.php b/blocks/myprofile/lang/en/block_myprofile.php index b8f0e8e4086..a843a70b451 100644 --- a/blocks/myprofile/lang/en/block_myprofile.php +++ b/blocks/myprofile/lang/en/block_myprofile.php @@ -30,6 +30,7 @@ $string['display_city'] = 'Display city'; $string['display_email'] = 'Display email'; $string['display_phone1'] = 'Display phone'; $string['display_phone2'] = 'Display mobile phone'; +$string['display_idnumber'] = 'Display ID number'; $string['display_institution'] = 'Display institution'; $string['display_address'] = 'Display address'; $string['display_firstaccess'] = 'Display first access'; diff --git a/blocks/myprofile/templates/myprofile.mustache b/blocks/myprofile/templates/myprofile.mustache index d9505e7f373..5e920d19195 100644 --- a/blocks/myprofile/templates/myprofile.mustache +++ b/blocks/myprofile/templates/myprofile.mustache @@ -37,6 +37,7 @@ * userphone2 * userinstitution * useraddress + * useridnumber * userfirstaccess * userlastaccess * usercurrentlogin @@ -53,6 +54,7 @@ "userphone2": "123456789", "userinstitution": "Institution", "useraddress": "Address", + "useridnumber": "12345", "userfirstaccess": "Friday, 6 July 2018, 9:03 AM", "userlastaccess": "Wednesday, 26 September 2018, 8:05 AM", "usercurrentlogin": "Wednesday, 26 September 2018, 7:17 AM", @@ -112,6 +114,12 @@ {{ useraddress }} {{/useraddress}} + {{#useridnumber}} +
+ {{#str}} idnumber {{/str}}: + {{{ useridnumber }}} +
+ {{/useridnumber}} {{#userfirstaccess}}
{{#str}} firstaccess {{/str}}: diff --git a/blocks/myprofile/tests/behat/block_myprofile.feature b/blocks/myprofile/tests/behat/block_myprofile.feature index d95de68c082..ea611007bb3 100644 --- a/blocks/myprofile/tests/behat/block_myprofile.feature +++ b/blocks/myprofile/tests/behat/block_myprofile.feature @@ -212,3 +212,22 @@ Feature: The logged in user block allows users to view their profile information | Display last IP | Yes | And I press "Save changes" And I should see "IP:" in the "Logged in user" "block" + + Scenario: Configure the logged in user block to show / hide the users idnumber + Given the following "users" exist: + | username | firstname | lastname | email | idnumber | + | teacher1 | Teacher | One | teacher1@example.com | ID12345 | + And I log in as "teacher1" + And I turn editing mode on + When I add the "Logged in user" block + And I configure the "Logged in user" block + And I set the following fields to these values: + | Display ID number | No | + And I press "Save changes" + Then I should see "Teacher One" in the "Logged in user" "block" + And I should not see "ID number:" in the "Logged in user" "block" + And I configure the "Logged in user" block + And I set the following fields to these values: + | Display ID number | Yes | + And I press "Save changes" + And I should see "ID number:" in the "Logged in user" "block"