Commit 645ce940 authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review

Merge "Bug 1530045: Show users one is trying to befriend on 'My friends' page"

parents 48050de0 32498d03
......@@ -303,6 +303,7 @@ $string['approverequest'] = 'Approve request';
$string['denyrequest'] = 'Deny request';
$string['pending'] = 'pending';
$string['pendingsince'] = 'pending since %s';
$string['requestedsince'] = 'requested since %s';
$string['trysearchingforfriends'] = 'Try %ssearching for new friends%s to grow your network.';
$string['nobodyawaitsfriendapproval'] = 'Nobody is awaiting your approval to become your friend.';
$string['sendfriendrequest'] = 'Send friend request';
......
......@@ -1121,6 +1121,7 @@ function search_friend($filter, $limit = null, $offset = 0) {
}
if (in_array($filter, array('all', 'pending'))) {
// For the friends being requested
$count += count_records_sql('SELECT COUNT("owner") FROM {usr_friend_request}
JOIN {usr} u ON (u.id = requester AND u.deleted = 0)
WHERE "owner" = ?',
......@@ -1129,6 +1130,15 @@ function search_friend($filter, $limit = null, $offset = 0) {
array_push($sql, 'SELECT requester AS id, 1 AS status FROM {usr_friend_request} WHERE "owner" = ?
');
// For the one doing the request
$count += count_records_sql('SELECT COUNT("requester") FROM {usr_friend_request}
JOIN {usr} u ON (u.id = "owner" AND u.deleted = 0)
WHERE requester = ?',
array($userid)
);
array_push($sql, 'SELECT "owner" AS id, 1 AS status FROM {usr_friend_request} WHERE requester = ?
');
}
$sqlstr = 'SELECT f.id FROM (' . join('UNION ', $sql) . ') f
JOIN {usr} u ON (f.id = u.id AND u.deleted = 0)
......
......@@ -1937,9 +1937,12 @@ function get_users_data($userids, $getviews=true) {
u.profileicon, u.email, u.urlid,
fp.requester AS pending,
fp.ctime AS pending_time,
fp2.ctime AS requested_time,
ap.value AS hidenamepref,
COALESCE((SELECT ap.value FROM {usr_account_preference} ap WHERE ap.usr = u.id AND ap.field = \'messages\'), \'allow\') AS messages,
COALESCE((SELECT ap.value FROM {usr_account_preference} ap WHERE ap.usr = u.id AND ap.field = \'friendscontrol\'), \'auth\') AS friendscontrol,
COALESCE((SELECT ap.value FROM {usr_account_preference} ap
WHERE ap.usr = u.id AND ap.field = \'messages\'), \'allow\') AS messages,
COALESCE((SELECT ap.value FROM {usr_account_preference} ap
WHERE ap.usr = u.id AND ap.field = \'friendscontrol\'), \'auth\') AS friendscontrol,
(SELECT 1 FROM {usr_friend} WHERE ((usr1 = ? AND usr2 = u.id) OR (usr2 = ? AND usr1 = u.id))) AS friend,
(SELECT 1 FROM {usr_friend_request} fr WHERE fr.requester = ? AND fr.owner = u.id) AS requestedfriendship,
(SELECT title FROM {artefact} WHERE artefacttype = \'introduction\' AND owner = u.id) AS introduction,
......@@ -1947,15 +1950,17 @@ function get_users_data($userids, $getviews=true) {
FROM {usr} u
LEFT JOIN {usr_account_preference} ap ON (u.id = ap.usr AND ap.field = \'hiderealname\')
LEFT JOIN {usr_friend_request} fp ON fp.owner = ? AND fp.requester = u.id
LEFT JOIN {usr_friend_request} fp2 ON fp2.requester = ? AND fp2.owner = u.id
WHERE u.id IN (' . join(',', array_fill(0, count($userids), '?')) . ')';
$userid = $USER->get('id');
$data = get_records_sql_assoc($sql, array_merge(array($userid, $userid, $userid, $userid), $userids));
$data = get_records_sql_assoc($sql, array_merge(array($userid, $userid, $userid, $userid, $userid), $userids));
$allowhidename = get_config('userscanhiderealnames');
$showusername = !get_config('nousernames');
$institutionstrings = get_institution_strings_for_users($userids);
foreach ($data as &$record) {
$record->pending_time = format_date(strtotime($record->pending_time), 'strftimedaydate');
$record->requested_time = format_date(strtotime($record->requested_time), 'strftimedaydate');
$record->messages = ($record->messages == 'allow' || $record->friend && $record->messages == 'friends' || $USER->get('admin')) ? 1 : 0;
if (isset($institutionstrings[$record->id])) {
$record->institutions = $institutionstrings[$record->id];
......
......@@ -6,11 +6,12 @@
</p>
{/if}
{if $results}
<div id="friendslist" class="panel-items">
<div id="friendslist" class="panel-items js-masonry" data-masonry-options='{literal}{ "itemSelector": ".panel" }{/literal}'>
{$results.tablerows|safe}
</div>
<div class="panel-pagination">
{$results.pagination|safe}
</div>
{/if}
{include file="footer.tpl"}
<div class="{if $user->pending}pending panel-warning{else}panel-default{/if} panel panel-half myfriend">
<div class="{if $user->pending || $user->requestedfriendship}pending panel-warning{else}panel-default{/if} panel panel-half myfriend">
<h3 class="panel-heading profile-block">
<a href="{profile_url($user)}" class="username">
{$user->display_name}
......@@ -6,6 +6,10 @@
<em class="text-small pendingfriend">
- {str tag='pendingsince' section='group' arg1=$user->pending_time}
</em>
{elseif $user->requestedfriendship}
<em class="text-small requestedfriend">
- {str tag='requestedsince' section='group' arg1=$user->requested_time}
</em>
{elseif $user->friend && $page == 'find'}
<em class="text-small existingfriend">
- {str tag='existingfriend' section='group'}
......@@ -52,6 +56,14 @@
</div>
{/if}
</div>
{if $user->requestedfriendship}
<div class="requested text-small">
<span class="icon icon-lg text-success icon-check left" role="presentation" aria-hidden="true"></span>
<span>
{str tag='friendshiprequested' section='group'}
</span>
</div>
{/if}
{if $user->messages}
<div class="sendmessage text-small">
<span class="icon icon-envelope left" role="presentation" aria-hidden="true"></span>
......
......@@ -6,7 +6,7 @@
</p>
{/if}
{if $results}
<div id="friendslist" class="panel-items">
<div id="friendslist" class="panel-items js-masonry" data-masonry-options='{literal}{ "itemSelector": ".panel" }{/literal}'>
{$results.tablerows|safe}
</div>
<div class="panel-pagination">
......
<div class="{if $user->pending}pending panel-warning{else}panel-default{/if} panel panel-half myfriend">
<div class="{if $user->pending || $user->requestedfriendship}pending panel-warning{else}panel-default{/if} panel panel-half myfriend">
<h3 class="panel-heading profile-block">
<a href="{profile_url($user)}" class="username">
{$user->display_name}
......@@ -6,6 +6,10 @@
<em class="text-small pendingfriend">
- {str tag='pendingsince' section='group' arg1=$user->pending_time}
</em>
{elseif $user->requestedfriendship}
<em class="text-small requestedfriend">
- {str tag='requestedsince' section='group' arg1=$user->requested_time}
</em>
{elseif $user->friend && $page == 'find'}
<em class="text-small existingfriend">
- {str tag='existingfriend' section='group'}
......@@ -52,6 +56,14 @@
</div>
{/if}
</div>
{if $user->requestedfriendship}
<div class="requested text-small">
<span class="icon icon-lg text-success icon-check left" role="presentation" aria-hidden="true"></span>
<span>
{str tag='friendshiprequested' section='group'}
</span>
</div>
{/if}
{if $user->messages}
<div class="sendmessage text-small">
<span class="icon icon-envelope left" role="presentation" aria-hidden="true"></span>
......
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