Skip to content

Commit

Permalink
MDL-60036 block_online_users: complete string about online users
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
jboulen committed Dec 15, 2017
1 parent 95b7be7 commit 6c519fe
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 11 deletions.
25 changes: 14 additions & 11 deletions blocks/online_users/block_online_users.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,25 @@ function get_content() {

//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 = '<div class="info">'.$usercount.' ('.$periodminutes.')</div>';

// 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 = "<div class=\"info\">".get_string("periodnminutes","block_online_users",$minutes).": $usercount</div>";
return $this->content;
}

$userlimit = 50; // We'll just take the most recent 50 maximum.
if ($users = $onlineusers->get_users($userlimit)) {
foreach ($users as $user) {
Expand All @@ -92,11 +102,6 @@ function get_content() {
$users = array();
}

$usercount = $onlineusers->count_users();
$usercount = ": $usercount";

$this->content->text = "<div class=\"info\">(".get_string("periodnminutes","block_online_users",$minutes)."$usercount)</div>";

//Now, we have in users, the list of users to show
//Because they are online
if (!empty($users)) {
Expand Down Expand Up @@ -133,8 +138,6 @@ function get_content() {
$this->content->text .= "</li>\n";
}
$this->content->text .= '</ul><div class="clearer"><!-- --></div>';
} else {
$this->content->text .= "<div class=\"info\">".get_string("none")."</div>";
}

return $this->content;
Expand Down
3 changes: 3 additions & 0 deletions blocks/online_users/lang/en/block_online_users.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"

0 comments on commit 6c519fe

Please sign in to comment.