Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
integration
prechecker
Commits
db924647
Commit
db924647
authored
Jun 28, 2022
by
Carsten Nielsen
Browse files
MDL-72592 block_myprofile: Add lastlogin date to myprofile block
parent
ceb41588
Changes
5
Hide whitespace changes
Inline
Side-by-side
blocks/myprofile/classes/output/myprofile.php
View file @
db924647
...
...
@@ -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
;
}
}
blocks/myprofile/edit_form.php
View file @
db924647
...
...
@@ -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
blocks/myprofile/lang/en/block_myprofile.php
View file @
db924647
...
...
@@ -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'
;
...
...
blocks/myprofile/templates/myprofile.mustache
View file @
db924647
...
...
@@ -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>
...
...
blocks/myprofile/tests/behat/block_myprofile.feature
View file @
db924647
...
...
@@ -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"
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment