diff --git a/blocks/myprofile/classes/output/myprofile.php b/blocks/myprofile/classes/output/myprofile.php index 870313c3909..6d3a0e4ebd2 100644 --- a/blocks/myprofile/classes/output/myprofile.php +++ b/blocks/myprofile/classes/output/myprofile.php @@ -120,6 +120,13 @@ class myprofile implements renderable, templatable { $data->userlastip = $USER->lastip; } + if (!empty($this->config->display_lastlogin)) { + if (empty($USER->lastlogin)) { + $data->userlastlogin = 0; + } else { + $data->userlastlogin = userdate($USER->lastlogin); + } + } return $data; } } diff --git a/blocks/myprofile/edit_form.php b/blocks/myprofile/edit_form.php index 167b7824a48..74303a69abe 100644 --- a/blocks/myprofile/edit_form.php +++ b/blocks/myprofile/edit_form.php @@ -119,5 +119,12 @@ class block_myprofile_edit_form extends block_edit_form { } else { $mform->setDefault('config_display_lastip', '0'); } + + $mform->addElement('selectyesno', 'config_display_lastlogin', get_string('display_lastlogin', 'block_myprofile')); + if (isset($this->block->config->display_lastlogin)) { + $mform->setDefault('config_display_lastlogin', $this->block->config->display_lastlogin); + } else { + $mform->setDefault('config_display_lastlogin', '0'); + } } } \ No newline at end of file diff --git a/blocks/myprofile/lang/en/block_myprofile.php b/blocks/myprofile/lang/en/block_myprofile.php index a843a70b451..d6ad3b8b368 100644 --- a/blocks/myprofile/lang/en/block_myprofile.php +++ b/blocks/myprofile/lang/en/block_myprofile.php @@ -36,6 +36,7 @@ $string['display_address'] = 'Display address'; $string['display_firstaccess'] = 'Display first access'; $string['display_lastaccess'] = 'Display last access'; $string['display_currentlogin'] = 'Display current login'; +$string['display_lastlogin'] = 'Display last login'; $string['display_lastip'] = 'Display last IP'; $string['myprofile:addinstance'] = 'Add a new logged in user block'; $string['myprofile:myaddinstance'] = 'Add a new logged in user block to Dashboard'; diff --git a/blocks/myprofile/templates/myprofile.mustache b/blocks/myprofile/templates/myprofile.mustache index 5e920d19195..8711073e13c 100644 --- a/blocks/myprofile/templates/myprofile.mustache +++ b/blocks/myprofile/templates/myprofile.mustache @@ -42,6 +42,7 @@ * userlastaccess * usercurrentlogin * userlastip + * userlastlogin Example context (json): { @@ -58,7 +59,8 @@ "userfirstaccess": "Friday, 6 July 2018, 9:03 AM", "userlastaccess": "Wednesday, 26 September 2018, 8:05 AM", "usercurrentlogin": "Wednesday, 26 September 2018, 7:17 AM", - "userlastip": "0:0:0:0:0:0:0:1" + "userlastip": "0:0:0:0:0:0:0:1", + "userlastlogin": "Wednesday, 25 September 2018, 9:01 AM" } }}
@@ -138,6 +140,12 @@ {{ usercurrentlogin }}
{{/usercurrentlogin}} + {{#userlastlogin}} +
+ {{#str}} lastlogin {{/str}}: + {{ userlastlogin }} +
+ {{/userlastlogin}} {{#userlastip}}
IP: diff --git a/blocks/myprofile/tests/behat/block_myprofile.feature b/blocks/myprofile/tests/behat/block_myprofile.feature index ea611007bb3..bbcecd2155d 100644 --- a/blocks/myprofile/tests/behat/block_myprofile.feature +++ b/blocks/myprofile/tests/behat/block_myprofile.feature @@ -231,3 +231,22 @@ Feature: The logged in user block allows users to view their profile information | Display ID number | Yes | And I press "Save changes" And I should see "ID number:" in the "Logged in user" "block" + + Scenario: Configure the logged in user block to show / hide the users last login + Given the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | Teacher | One | teacher1@example.com | + And I log in as "teacher1" + And I press "Customise this page" + 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 last login | No | + And I press "Save changes" + Then I should see "Teacher One" in the "Logged in user" "block" + And I should not see "Last login:" in the "Logged in user" "block" + And I configure the "Logged in user" block + And I set the following fields to these values: + | Display last login | Yes | + And I press "Save changes" + And I should see "Last login:" in the "Logged in user" "block"