Commit 8f7b65ba authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Show number of friends in my friends block title (bug #3085)

parent 10b1c1bc
......@@ -29,4 +29,5 @@ defined('INTERNAL') || die();
$string['title'] = 'My Friends';
$string['otherusertitle'] = "%s's Friends";
$string['description'] = 'Display your friends';
$string['numberoffriends'] = '(%s of %s)';
?>
......@@ -26,6 +26,8 @@
defined('INTERNAL') || die();
define('MAXFRIENDDISPLAY', 16);
class PluginBlocktypeMyfriends extends SystemBlocktype {
public static function get_title() {
......@@ -58,20 +60,8 @@ class PluginBlocktypeMyfriends extends SystemBlocktype {
WHERE usr1 = ? OR usr2 = ?
ORDER BY ' . db_random() . '
LIMIT ?',
array($userid, $userid, 16)
);
$numberoffriends = count_records_sql('SELECT COUNT(usr1) FROM {usr_friend}
JOIN {usr} u1 ON (u1.id = usr1 AND u1.deleted = 0)
JOIN {usr} u2 ON (u2.id = usr2 AND u2.deleted = 0)
WHERE usr1 = ? OR usr2 = ?',
array($userid, $userid)
array($userid, $userid, MAXFRIENDDISPLAY)
);
if ($numberoffriends > 16) {
$friendsmessage = get_string('numberoffriends', 'group', $records ? count($records) : 0, $numberoffriends);
}
else {
$friendsmessage = get_string('Friends', 'group');
}
// get the friends into a 4x4 array
if ($records) {
$friends = array();
......@@ -95,7 +85,6 @@ class PluginBlocktypeMyfriends extends SystemBlocktype {
$friends = false;
}
$smarty->assign('friends', $friends);
$smarty->assign('friendsmessage', $friendsmessage);
// If the user has no friends, try and display something useful, such
// as a 'request friendship' button
......@@ -157,10 +146,25 @@ class PluginBlocktypeMyfriends extends SystemBlocktype {
public static function override_instance_title(BlockInstance $instance) {
global $USER;
$ownerid = $instance->get_view()->get('owner');
if ($ownerid == $USER->get('id')) {
return get_string('title', 'blocktype.myfriends');
$title = get_string('title', 'blocktype.myfriends');
}
return get_string('otherusertitle', 'blocktype.myfriends', display_name($ownerid, null, true));
else {
$title = get_string('otherusertitle', 'blocktype.myfriends', display_name($ownerid, null, true));
}
$numberoffriends = count_records_sql('SELECT COUNT(usr1) FROM {usr_friend}
JOIN {usr} u1 ON (u1.id = usr1 AND u1.deleted = 0)
JOIN {usr} u2 ON (u2.id = usr2 AND u2.deleted = 0)
WHERE usr1 = ? OR usr2 = ?',
array($ownerid, $ownerid)
);
if ($numberoffriends > MAXFRIENDDISPLAY) {
$title .= ' ' . get_string('numberoffriends', 'blocktype.myfriends', MAXFRIENDDISPLAY, $numberoffriends);
}
return $title;
}
}
......
......@@ -243,7 +243,6 @@ $string['cantrequestfrienship'] = 'You cannot request frienship from this user';
$string['cantmessageuser'] = 'You cannot send this user a message';
$string['requestedfriendship'] = 'requested friendship';
$string['notinanygroups'] = 'Not in any groups';
$string['numberoffriends'] = 'Friends (%s of %s)';
$string['addusertogroup'] = 'Add to ';
$string['inviteusertojoingroup'] = 'Invite to ';
$string['invitemembertogroup'] = 'Invite %s to join \'%s\'';
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment