Merge branch 'MDL-72592-master' of https://github.com/lameze/moodle

This commit is contained in:
Jun Pataleta 2022-08-29 13:12:18 +08:00
commit b58b121d0b
5 changed files with 42 additions and 1 deletions

View File

@ -120,6 +120,10 @@ class myprofile implements renderable, templatable {
$data->userlastip = $USER->lastip;
}
if (!empty($this->config->display_lastlogin) && !empty($USER->lastlogin)) {
$data->userlastlogin = userdate($USER->lastlogin);
}
return $data;
}
}

View File

@ -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');
}
}
}

View File

@ -37,6 +37,7 @@ $string['display_firstaccess'] = 'Display first access';
$string['display_lastaccess'] = 'Display last access';
$string['display_currentlogin'] = 'Display current login';
$string['display_lastip'] = 'Display last IP';
$string['display_lastlogin'] = 'Display last login';
$string['myprofile:addinstance'] = 'Add a new logged in user block';
$string['myprofile:myaddinstance'] = 'Add a new logged in user block to Dashboard';
$string['myprofile_settings'] = 'Visible user information';

View File

@ -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"
}
}}
<div>
@ -138,6 +140,12 @@
{{ usercurrentlogin }}
</div>
{{/usercurrentlogin}}
{{#userlastlogin}}
<div class="myprofileitem lastlogin">
<span>{{#str}} lastlogin {{/str}}:</span>
{{ userlastlogin }}
</div>
{{/userlastlogin}}
{{#userlastip}}
<div class="myprofileitem lastip">
<span>IP:</span>

View File

@ -231,3 +231,24 @@ 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 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 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 log out
And I log in as "teacher1"
And I should see "Last login:" in the "Logged in user" "block"