From 6c519fe4d7586ef41ee7acddb207d29c4512485c Mon Sep 17 00:00:00 2001 From: Julien Boulen Date: Fri, 15 Dec 2017 09:36:04 +0100 Subject: [PATCH] MDL-60036 block_online_users: complete string about online users - add 3 varations of "x online users" string - change string format from "x minutes: x online users" to "x online users (x minutes)" - factorize some duplicated code --- blocks/online_users/block_online_users.php | 25 +++++++++++-------- .../lang/en/block_online_users.php | 3 +++ .../behat/block_online_users_course.feature | 2 ++ .../block_online_users_dashboard.feature | 2 ++ .../block_online_users_frontpage.feature | 3 +++ 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/blocks/online_users/block_online_users.php b/blocks/online_users/block_online_users.php index 1a41395f1ed..08521a3069e 100644 --- a/blocks/online_users/block_online_users.php +++ b/blocks/online_users/block_online_users.php @@ -74,15 +74,25 @@ class block_online_users extends block_base { //Calculate minutes $minutes = floor($timetoshowusers/60); + $periodminutes = get_string('periodnminutes', 'block_online_users', $minutes); + + // Count users. + $usercount = $onlineusers->count_users(); + if ($usercount === 0) { + $usercount = get_string('nouser', 'block_online_users'); + } else if ($usercount === 1) { + $usercount = get_string('numuser', 'block_online_users', $usercount); + } else { + $usercount = get_string('numusers', 'block_online_users', $usercount); + } + + $this->content->text = '
'.$usercount.' ('.$periodminutes.')
'; // Verify if we can see the list of users, if not just print number of users if (!has_capability('block/online_users:viewlist', $this->page->context)) { - if (!$usercount = $onlineusers->count_users()) { - $usercount = get_string("none"); - } - $this->content->text = "
".get_string("periodnminutes","block_online_users",$minutes).": $usercount
"; return $this->content; } + $userlimit = 50; // We'll just take the most recent 50 maximum. if ($users = $onlineusers->get_users($userlimit)) { foreach ($users as $user) { @@ -92,11 +102,6 @@ class block_online_users extends block_base { $users = array(); } - $usercount = $onlineusers->count_users(); - $usercount = ": $usercount"; - - $this->content->text = "
(".get_string("periodnminutes","block_online_users",$minutes)."$usercount)
"; - //Now, we have in users, the list of users to show //Because they are online if (!empty($users)) { @@ -133,8 +138,6 @@ class block_online_users extends block_base { $this->content->text .= "\n"; } $this->content->text .= '
'; - } else { - $this->content->text .= "
".get_string("none")."
"; } return $this->content; diff --git a/blocks/online_users/lang/en/block_online_users.php b/blocks/online_users/lang/en/block_online_users.php index 5d641eec3f2..e5a79e31800 100644 --- a/blocks/online_users/lang/en/block_online_users.php +++ b/blocks/online_users/lang/en/block_online_users.php @@ -24,6 +24,9 @@ */ $string['configtimetosee'] = 'Number of minutes determining the period of inactivity after which a user is no longer considered to be online.'; +$string['nouser'] = 'No online users'; +$string['numuser'] = '{$a} online user'; +$string['numusers'] = '{$a} online users'; $string['online_users:addinstance'] = 'Add a new online users block'; $string['online_users:myaddinstance'] = 'Add a new online users block to Dashboard'; $string['online_users:viewlist'] = 'View list of online users'; diff --git a/blocks/online_users/tests/behat/block_online_users_course.feature b/blocks/online_users/tests/behat/block_online_users_course.feature index 22591be631e..e86e4d8c1e0 100644 --- a/blocks/online_users/tests/behat/block_online_users_course.feature +++ b/blocks/online_users/tests/behat/block_online_users_course.feature @@ -24,6 +24,7 @@ Feature: The online users block allow you to see who is currently online And I am on "Course 1" course homepage with editing mode on When I add the "Online users" block Then I should see "Teacher 1" in the "Online users" "block" + And I should see "1 online user" in the "Online users" "block" Scenario: Add the online users on course page and see other logged in users Given I log in as "teacher1" @@ -37,3 +38,4 @@ Feature: The online users block allow you to see who is currently online Then I should see "Teacher 1" in the "Online users" "block" And I should see "Student 1" in the "Online users" "block" And I should not see "Student 2" in the "Online users" "block" + And I should see "2 online users" in the "Online users" "block" diff --git a/blocks/online_users/tests/behat/block_online_users_dashboard.feature b/blocks/online_users/tests/behat/block_online_users_dashboard.feature index 7f88d76bf6a..34207c5cdea 100644 --- a/blocks/online_users/tests/behat/block_online_users_dashboard.feature +++ b/blocks/online_users/tests/behat/block_online_users_dashboard.feature @@ -14,6 +14,7 @@ Feature: The online users block allow you to see who is currently online on dash Scenario: View the online users block on the dashboard and see myself Given I log in as "teacher1" Then I should see "Teacher 1" in the "Online users" "block" + And I should see "1 online user" in the "Online users" "block" Scenario: View the online users block on the dashboard and see other logged in users Given I log in as "student2" @@ -24,3 +25,4 @@ Feature: The online users block allow you to see who is currently online on dash Then I should see "Teacher 1" in the "Online users" "block" And I should see "Student 1" in the "Online users" "block" And I should see "Student 2" in the "Online users" "block" + And I should see "3 online users" in the "Online users" "block" diff --git a/blocks/online_users/tests/behat/block_online_users_frontpage.feature b/blocks/online_users/tests/behat/block_online_users_frontpage.feature index 5909b1c0478..6237d3d436f 100644 --- a/blocks/online_users/tests/behat/block_online_users_frontpage.feature +++ b/blocks/online_users/tests/behat/block_online_users_frontpage.feature @@ -16,6 +16,7 @@ Feature: The online users block allow you to see who is currently online on fron And I navigate to "Turn editing on" node in "Front page settings" When I add the "Online users" block Then I should see "Admin User" in the "Online users" "block" + And I should see "1 online user" in the "Online users" "block" Scenario: View the online users block on the front page as a logged in user Given I log in as "admin" @@ -30,6 +31,7 @@ Feature: The online users block allow you to see who is currently online on fron Then I should see "Admin User" in the "Online users" "block" And I should see "Student 1" in the "Online users" "block" And I should see "Student 2" in the "Online users" "block" + And I should see "3 online users" in the "Online users" "block" Scenario: View the online users block on the front page as a guest Given I log in as "admin" @@ -46,3 +48,4 @@ Feature: The online users block allow you to see who is currently online on fron Then I should see "Admin User" in the "Online users" "block" And I should see "Student 1" in the "Online users" "block" And I should see "Student 2" in the "Online users" "block" + And I should see "3 online users" in the "Online users" "block"