Commit 2b79e29a authored by Lisa Seeto's avatar Lisa Seeto Committed by Robert Lyon
Browse files

Bug 1814621: Consolidate "My friends" and "Find people" screens



Change-Id: I4fc0334d50500d649e9f2c6125f0f181df0ccba4
Signed-off-by: default avatarLisa Seeto <lisaseeto@catalyst.net.nz>
parent 988ef71e
......@@ -412,7 +412,7 @@ class PluginArtefactInternal extends PluginArtefact {
return 'group/index.php?filter=notmember';
break;
case 'makefriend':
return 'user/find.php';
return 'user/index.php';
break;
default:
return 'view/index.php';
......
......@@ -86,7 +86,7 @@ class PluginBlocktypeMyfriends extends MaharaCoreBlocktype {
$smarty = smarty_core();
$smarty->assign('friends', $friends);
$smarty->assign('searchingforfriends', array('<a href="' . get_config('wwwroot') . 'user/find.php">', '</a>'));
$smarty->assign('searchingforfriends', array('<a href="' . get_config('wwwroot') . 'user/index.php">', '</a>'));
// If the user has no friends, try and display something useful, such
// as a 'request friendship' button
......
......@@ -102,7 +102,7 @@ $urls = array(
'resume' => $wwwroot . 'artefact/resume/index.php',
'blog' => $wwwroot . 'artefact/blog/index.php',
'views' => $wwwroot . 'view/index.php',
'friends' => $wwwroot . 'user/find.php',
'friends' => $wwwroot . 'user/index.php?filter=current',
'groups' => $wwwroot . 'group/index.php',
'topics' => $wwwroot . 'group/topics.php',
'share' => $wwwroot . 'view/share.php',
......
......@@ -20,16 +20,16 @@ $offset = param_integer('offset', 0);
$limit = param_integer('limit', 10);
$filter = param_alpha('filter', 'all');
$page = 'myfriends';
$searchtype = 'myfriends';
if ($extradata = param_variable('extradata', null)) {
$extradata = json_decode($extradata);
if ($extradata->page) {
$page = $extradata->page;
if ($extradata->searchtype) {
$searchtype = $extradata->searchtype;
}
}
if ($page == 'myfriends') {
$data = search_friend($filter, $limit, $offset);
if ($searchtype == 'myfriends') {
$data = search_friend($filter, $limit, $offset, $query);
$data['filter'] = $filter;
}
else {
......@@ -46,7 +46,7 @@ else {
require_once('group.php');
$admingroups = (bool) group_get_user_admintutor_groups();
build_userlist_html($data, $page, $admingroups);
build_userlist_html($data, $searchtype, $admingroups, $filter, $query);
unset($data['data']);
json_reply(false, array('data' => $data));
......@@ -294,6 +294,7 @@ $string['addtofriendsfailed'] = 'Failed to add %s to your friends list.';
$string['allfriends'] = 'All friends';
$string['currentfriends'] = 'Current friends';
$string['pendingfriends'] = 'Pending friends';
$string['pendingfriend'] = 'Pending friend';
$string['backtofriendslist'] = 'Back to friends list';
$string['findnewfriends'] = 'Find new friends';
$string['Collections'] = 'Collections';
......@@ -319,6 +320,7 @@ $string['friends'] = 'friends';
$string['user'] = 'user';
$string['users'] = 'users';
$string['Friends'] = 'Friends';
$string['friendrequests'] = 'Friend requests';
$string['Everyone'] = 'Everyone';
$string['myinstitutions'] = 'My institutions';
......@@ -341,6 +343,7 @@ $string['viewmessage'] = 'View message';
$string['Reply'] = 'Reply';
$string['denyfriendrequest'] = 'Deny friend request';
$string['deny'] = 'Deny';
$string['sendfriendshiprequest'] = 'Send %s a friendship request';
$string['cantdenyrequest'] = 'That is not a valid friendship request.';
$string['cantmessageuser'] = 'You cannot send this user a message.';
......
<!-- @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later -->
<!-- @copyright For copyright information on Mahara, please see the README file distributed with this software. -->
<h3>People</h3>
<p>This page lets you search for users to add as friends or simply to find
their profile page. Depending on their friendship control settings, you may
be automatically accepted as their friend or you may need to send a
friendship request. Some users may not allow friendship requests at all.</p>
<p>When sending a friendship request, you can choose to include a short message
introducing yourself. This is especially important if you have a display name
set as others will not see your real name.</p>
<p>You can also see a list of your current and pending friends.</p>
<p>A user can resubmit a friendship request to you, even if you have previously rejected that user.</p>
......@@ -773,6 +773,7 @@ $string['Create'] = 'Create';
$string['Engage'] = 'Engage';
$string['Manage'] = 'Manage';
$string['settings'] = 'Settings';
$string['people'] = 'People';
$string['myfriends'] = 'My friends';
$string['findpeople'] = 'Find people';
$string['groups'] = 'Groups';
......
......@@ -1192,5 +1192,9 @@ function xmldb_core_upgrade($oldversion=0) {
}
}
if ($oldversion < 2019031900) {
log_debug('Clearing cache for new people menu structure');
}
return $status;
}
......@@ -209,11 +209,13 @@ $manual_link_map = array(
"create|views|add" => "portfolio/pages.html#add-a-page",
"create|views|blocks" => "portfolio/page_editor.html",
"create|views|versioning" => "portfolio/pages.html#new-in-mahara-18-10-timeline-of-a-page-s-development",
"engage|findfriends" => "groups/find_friends.html#send-a-friend-request",
"engage|findfriends|find" => "groups/find_friends.html",
"engage|findfriends|removefriend" => "groups/my_friends.html#remove-a-friend",
"engage|people|index" => "groups/find_friends.html#find-people",
"engage|people|index|current" => "groups/my_friends.html",
"engage|people|index|pending" => "groups/my_friends.html",
"engage|people|requestfriendship" => "groups/find_friends.html#send-a-friend-request",
"engage|people|denyrequest" => "groups/find_friends.html#deny-a-friend-request",
"engage|people|removefriend" => "groups/my_friends.html#remove-a-friend",
"engage|institutions" => "groups/institution_membership.html",
"engage|myfriends" => "groups/my_friends.html",
"engage|index" => "groups/my_groups.html",
"engage|index|blocks" => "groups/inside_group.html#id3",
"engage|index|edittopic|forums" => "groups/inside_group.html#add-a-forum-topic",
......
......@@ -1131,24 +1131,50 @@ function get_search_plugins() {
* ),
* );
*/
function search_friend($filter, $limit = null, $offset = 0) {
function search_friend($filter, $limit = null, $offset = 0, $query='') {
global $USER;
$userid = $USER->get('id');
if (!in_array($filter, array('all','current','pending'))) {
if (!in_array($filter, array('allmy','current','pending'))) {
throw new SystemException('Invalid search filter');
}
$sql = array();
$count = 0;
if (in_array($filter, array('all', 'current'))) {
$extravalues = array();
$querystr = "";
if ($query) {
$querystr.=' AND (u.username ' . db_ilike() . " '%' || ? || '%' " .
'OR u.firstname ' . db_ilike() . " '%' || ? || '%' " .
'OR u.lastname ' . db_ilike() . " '%' || ? || '%' )";
$extravalues = array($query, $query, $query);
}
if (in_array($filter, array('allmy', 'current'))) {
$where = array($userid, $userid);
if ($query) {
$where = array($userid, $query, $query, $query, $userid, $query, $query, $query);
$count += 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 = ? AND u1.username ' . db_ilike() . " '%' || ? || '%' " .
'OR u1.firstname ' . db_ilike() . " '%' || ? || '%' " .
'OR u1.lastname ' . db_ilike() . " '%' || ? || '%' )
OR (usr2 = ? AND u2.username " . db_ilike() . " '%' || ? || '%' " .
'OR u2.firstname ' . db_ilike() . " '%' || ? || '%' " .
'OR u2.lastname ' . db_ilike() . " '%' || ? || '%' )",
$where
);
}
else {
$count += 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)
$where
);
}
array_push($sql, 'SELECT usr2 AS id, 2 AS status FROM {usr_friend} WHERE usr1 = ?
');
......@@ -1156,32 +1182,41 @@ function search_friend($filter, $limit = null, $offset = 0) {
');
}
if (in_array($filter, array('all', 'pending'))) {
if (in_array($filter, array('allmy', '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" = ?',
array($userid)
$where = array($userid);
if ($query) {
$where = array_merge($where, $extravalues);
}
$count += count_records_sql('SELECT COUNT(ufr.owner) FROM {usr_friend_request} ufr
JOIN {usr} u ON (u.id = ufr.requester AND u.deleted = 0)
WHERE ufr.owner = ?' . $querystr,
$where
);
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)
$where = array($userid);
if ($query) {
$where = array_merge($where, $extravalues);
}
$count += count_records_sql('SELECT COUNT(ufr.requester) FROM {usr_friend_request} ufr
JOIN {usr} u ON (u.id = ufr.owner AND u.deleted = 0)
WHERE ufr.requester = ?' . $querystr,
$where
);
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)
ORDER BY status, firstname, lastname, u.id';
$sqlstr = 'SELECT f.id FROM (' . join('UNION ', $sql) . ') AS f
JOIN {usr} u ON (f.id = u.id AND u.deleted = 0)';
$sqlstr .= 'WHERE u.deleted = 0 ' . $querystr . ' ORDER BY status, firstname, lastname, u.id';
if ($limit) {
$extravalues = array_merge($extravalues, array($limit, $offset));
$data = get_column_sql($sqlstr . ' LIMIT ? OFFSET ?',
array_merge(array_pad($values=array(), count($sql), $userid), array($limit, $offset)));
array_merge(array_pad($values=array(), count($sql), $userid), $extravalues));
}
else {
$data = get_column_sql($sqlstr,
......
......@@ -1970,7 +1970,7 @@ function profile_url($user, $full=true, $useid=false) {
}
/**
* used by user/myfriends.php and user/find.php to get the data (including pieforms etc) for display
* used by user/index.php to get the data (including pieforms etc) for display
* @param array $userids
* @return array containing the users in the order from $userids
*/
......@@ -2059,14 +2059,14 @@ function get_users_data($userids, $getviews=true) {
return $ordereddata;
}
function build_userlist_html(&$data, $page, $admingroups) {
function build_userlist_html(&$data, $searchtype, $admingroups, $filter='', $query='') {
if ($data['data']) {
$userlist = array_map(function($u) { return (int)$u['id']; }, $data['data']);
$userdata = get_users_data($userlist, $page == 'myfriends');
$userdata = get_users_data($userlist, $searchtype == 'myfriends');
}
$smarty = smarty_core();
$smarty->assign('data', isset($userdata) ? $userdata : null);
$smarty->assign('page', $page);
$smarty->assign('page', $searchtype);
$smarty->assign('offset', $data['offset']);
$params = array();
......@@ -2078,7 +2078,7 @@ function build_userlist_html(&$data, $page, $admingroups) {
$params['filter'] = $data['filter'];
}
if ($page == 'myfriends') {
if ($searchtype == 'myfriends') {
$resultcounttextsingular = get_string('friend', 'group');
$resultcounttextplural = get_string('friends', 'group');
}
......@@ -2092,7 +2092,7 @@ function build_userlist_html(&$data, $page, $admingroups) {
$data['tablerows'] = $smarty->fetch('user/userresults.tpl');
$pagination = build_pagination(array(
'id' => 'friendslist_pagination',
'url' => get_config('wwwroot') . 'user/' . $page . '.php?' . http_build_query($params),
'url' => get_config('wwwroot') . 'user/index.php?' . http_build_query($params),
'jsonscript' => 'json/friendsearch.php',
'datatable' => 'friendslist',
'searchresultsheading' => 'searchresultsheading',
......@@ -2104,7 +2104,9 @@ function build_userlist_html(&$data, $page, $admingroups) {
'numbersincludeprevnext' => 2,
'resultcounttextsingular' => $resultcounttextsingular,
'resultcounttextplural' => $resultcounttextplural,
'extradata' => array('page' => $page),
'extradata' => array('searchtype' => $searchtype),
'filter' => $filter,
'query' => $query,
));
$data['pagination'] = $pagination['html'];
$data['pagination_js'] = $pagination['javascript'];
......@@ -2270,23 +2272,27 @@ function friendscontrol_submit(Pieform $form, $values) {
global $USER, $SESSION;
$USER->set_account_preference('friendscontrol', $values['friendscontrol']);
$SESSION->add_ok_msg(get_string('updatedfriendcontrolsetting', 'account'));
redirect($values['returnto'] == 'find' ? '/user/find.php' : '/user/myfriends.php');
redirect('/user/index.php');
}
function acceptfriend_form($friendid) {
function acceptfriend_form($friendid, $modalmode='') {
$value = ($modalmode == 'modal' ? get_string('approverequest', 'group') : '<span class="icon icon-check icon-lg text-success left" role="presentation" aria-hidden="true"></span>' . get_string('approve', 'group'));
$elementclass = $modalmode == 'modal' ? 'form-as-button' : 'form-as-button pull-left';
$class = $modalmode == 'modal' ? 'link-unstyled' : 'default btn-secondary';
return pieform(array(
'name' => 'acceptfriend' . (int) $friendid,
'validatecallback' => 'acceptfriend_validate',
'successcallback' => 'acceptfriend_submit',
'renderer' => 'div',
'class' => 'form-as-button',
'class' => $elementclass,
'autofocus' => 'false',
'elements' => array(
'acceptfriend_submit' => array(
'type' => 'button',
'usebuttontag' => true,
'class' => 'btn-link btn-text',
'value' => get_string('approverequest', 'group'),
'class' => $class,
'value' => $value,
),
'id' => array(
'type' => 'hidden',
......
......@@ -16,7 +16,7 @@ $config = new stdClass();
// See https://wiki.mahara.org/wiki/Developer_Area/Version_Numbering_Policy
// For upgrades on stable branches, increment the version by one. On master, use the date.
$config->version = 2019031500;
$config->version = 2019031900;
$config->series = '19.04';
$config->release = '19.04dev';
$config->minupgradefrom = 2017031605;
......
......@@ -2930,24 +2930,18 @@ function mahara_standard_nav() {
'weight' => 40,
'iconclass' => 'wrench',
),
'engage/people' => array(
'path' => 'engage/people',
'url' => 'user/index.php',
'title' => get_string('people'),
'weight' => 10,
),
'engage/index' => array(
'path' => 'engage/index',
'url' => 'group/index.php',
'title' => get_string('groups'),
'weight' => 10,
'accesskey' => 'g',
),
'engage/myfriends' => array(
'path' => 'engage/myfriends',
'url' => 'user/myfriends.php',
'title' => get_string('myfriends'),
'weight' => 30,
),
'engage/findfriends' => array(
'path' => 'engage/findfriends',
'url' => 'user/find.php',
'title' => get_string('findpeople'),
'weight' => 40,
'accesskey' => 'g',
),
'engage/institutionmembership' => array(
'path' => 'engage/institutions',
......@@ -3221,7 +3215,6 @@ function footer_menu($all=false) {
$helpkeys[] = 'new';
}
}
// To handle when things have an explicit 'filter' state
if (param_exists('filter')) {
$helpkeys[] = param_alphanum('filter', null);
......@@ -3251,7 +3244,6 @@ function footer_menu($all=false) {
}
}
}
return $menu;
}
......
......@@ -161,7 +161,7 @@ $returnto = param_alpha('returnto', 'myfriends');
$offset = param_integer('offset', 0);
switch ($returnto) {
case 'find':
$goto = 'user/find.php';
$goto = 'user/index.php';
break;
case 'view':
$goto = profile_url($user, false);
......
......@@ -228,7 +228,7 @@ abstract class PluginSearch extends Plugin implements IPluginSearch {
public static function header_search_form() {
return pieform(array(
'name' => 'usf',
'action' => get_config('wwwroot') . 'user/find.php',
'action' => get_config('wwwroot') . 'user/index.php',
'renderer' => 'oneline',
'autofocus' => false,
'validate' => false,
......
......@@ -21,7 +21,7 @@
{/if}
{if $sbdata.pendingfriends}
<div id="pendingfriends" class="list-group-item list-group-item-warning list-group-item-profile-notification">
<a href="{$WWWROOT}user/myfriends.php?filter=pending">
<a href="{$WWWROOT}user/index.php?filter=pending">
<span id="pendingfriendscount" class="badge badge-warning">{$sbdata.pendingfriends}</span>
<span id="pendingfriendsmessage">{$sbdata.pendingfriendsmessage}</span>
</a>
......
{include file="header.tpl"}
{$form|safe}
{if $results}
<div class="card view-container">
<h2 id="searchresultsheading" class="card-header">{str tag=Results}</h2>
<div id="friendslist" class="list-group">
{$results.tablerows|safe}
</div>
</div>
{$results.pagination|safe}
{/if}
{include file="footer.tpl"}
{include file="header.tpl"}
{$form|safe}
{if $message}
<p class="no-results">
{$message|safe}
</p>
{/if}
{if $count > 0}
<div class="panel panel-default view-container">
<h2 id="searchresultsheading" class="panel-heading">{str tag=Results}</h2>
<div id="friendslist" class="list-group">
{$results.tablerows|safe}
</div>
</div>
{$results.pagination|safe}
{if $results.pagination_js}
<script>
{$results.pagination_js|safe}
</script>
{/if}
{else}
<p class="no-results">{str tag=nosearchresultsfound section=group}</p>
{/if}
{include file="footer.tpl"}
{include file="header.tpl"}
{$form|safe}
{if $message}
<p class="no-results">
{$message|safe}
</p>
{/if}
{if $results}
<div id="friendslist" class="card-items js-masonry" data-masonry-options='{literal}{ "itemSelector": ".card" }{/literal}'>
{$results.tablerows|safe}
</div>
<div class="card-pagination">
{$results.pagination|safe}
</div>
{/if}
{include file="footer.tpl"}
<div class="{if $user->pending || $user->requestedfriendship}pending card bg-warning{else}card{/if} card card-half myfriend">
<h3 class="card-header profile-block">
<a href="{profile_url($user)}" class="username">
{$user->display_name}
{if $user->pending}
<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'}
</em>
{/if}
</a>
<span id="friendinfo_{$user->id}">
<img class="user-icon" src="{profile_icon_url user=$user maxwidth=60 maxheight=60}" alt="{str tag=profileimagetext arg1=$user|display_default_name}">
</span>
</h3>
<div class="card-body">
{if $user->institutions}
<div class="memberof detail with-user-icon-lg">
<span class="icon icon-university left" role="presentation" aria-hidden="true"></span>
{$user->institutions|safe}
</div>
{/if}
<div class="user-content content-text">
{if $user->introduction}
<p class="intro">
{$user->introduction|str_shorten_html:100:true|safe}
</p>
{/if}
{if $user->friend && $page == 'myfriends' && $user->views}
<p class="viewlist">
<strong>
{str tag='Views' section='group'}:
</strong>
{foreach from=$user->views item=view}
<span>
<a href="{$view->fullurl}">{$view->title}</a>
</span>
{/foreach}
</p>
{/if}
{if $user->pending}
<div class="whymakemeyourfriend">
<strong>
{str tag='whymakemeyourfriend' section='group'}
</strong>
<p>{$user->message|format_whitespace|safe}</p>
</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>
<a href="{$WWWROOT}{if $mrmoduleactive}module/multirecipientnotification{else}user{/if}/sendmessage.php?id={$user->id}&amp;returnto={$page}&amp;offset={$offset}" class="text-right" title="{str tag='sendmessage' section='group'}">
{str tag='sendmessage' section='group'}
</a>
</div>
{/if}
{if $admingroups}
<div class="editgroup text-small">
<span class="icon icon-pencil left" role="presentation" aria-hidden="true"></span>
<a href="" id="editgroup-link-{$user->id}" class="js-edit-group" data-userid="{$user->id}">
{str tag='editgroupmembership' section='group'}
</a>
</div>
{/if}
</div>
{if $user->pending}
<div class="has-form text-small card-footer btn-toggle">
<div class="btn">
<span class="icon icon-check icon-lg text-success left" role="presentation" aria-hidden="true"></span>
{$user->accept|safe}
</div>
<a href="{$WWWROOT}user/denyrequest.php?id={$user->id}&amp;returnto={$page}&amp;offset={$offset}" class="btn">
<span class="icon icon-ban left icon-lg text-danger" role="presentation" aria-hidden="true"></span>
<span class="link-unstyled">{str tag='denyrequest' section='group'}</span>
</a>
</div>
{/if}
{if $user->friend}
<a href="{$WWWROOT}user/removefriend.php?id={$user->id}&amp;returnto={$page}&amp;offset={$offset}" class="card-footer">
<span class="icon icon-remove left icon-lg text-danger" role="presentation" aria-hidden="true"></span>
{str tag='removefromfriendslist' section='group'}
</a>
{/if}
</div>
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