Commit fb46accb authored by Clare Lenihan's avatar Clare Lenihan Committed by Clare Lenihan
Browse files

Somewhat working new my friends page. None of the links go anywhere and stuff will be a bit wrong.

parent e7619c78
......@@ -183,6 +183,7 @@ $string['currentfriends'] = 'Current Friends';
$string['pendingfriends'] = 'Pending friends';
$string['backtofriendslist'] = 'Back to Friends List';
$string['findnewfriends'] = 'Find New Friends';
$string['Views'] = 'Views';
$string['seeallviews'] = 'See all %s views...';
$string['noviewstosee'] = 'None that you can see :(';
$string['whymakemeyourfriend'] = 'This is why you should make me your friend:';
......@@ -196,6 +197,8 @@ $string['addtomyfriends'] = 'Add to My Friends!';
$string['friendshiprequested'] = 'Friendship requested!';
$string['existingfriend'] = 'existing friend';
$string['nosearchresultsfound'] = 'No search results found :(';
$string['friend'] = 'friend';
$string['friends'] = 'friends';
$string['friendlistfailure'] = 'Failed to modify your friends list';
$string['userdoesntwantfriends'] = 'This user doesn\'t want any new friends';
......
......@@ -4,6 +4,25 @@
{include file="columnleftstart.tpl"}
<h2>{$heading}</h2>
<div id="friendslistcontainer">
{$form}
{if $users}
<table id="friendslist">
{foreach from=$users item=user}
<tr class="r{cycle values=1,0}">
{include file="user/user.tpl" user=$user }
</tr>
{/foreach}
</table>
</div>
<div class="center">
{$pagination}
{else}
</div>
<div class="message">
{$message}
</div>
{/if}
{include file="columnleftend.tpl"}
{include file="footer.tpl"}
{if $user->pending}
<td class="pending">
<div class="fl">
<img src="{$WWWROOT}thumb.php?type=profileicon&amp;size=40x40&amp;id={$user->id}">
</div>
<table class="friendinfo">
<tr>
<th>
<div class="fr">
{$user->accept}
</div>
<h3>
<a href="{$WWWROOT}user/view.php?id={$user->id}">
{$user->id|display_name|escape}
</a>
- {str tag='pending' section='group'}
</h3>
</th>
</tr>
<tr>
<td id="friendinfo_{$user->id}">
{if $user->introduction}
<p>
{$user->introduction|escape}
</p>
{/if}
<div class="pending">
<div>
<strong>
{str tag='whymakemeyourfriend' section='group'}
{user->reason}
</strong>
</div>
<div/>
<div>
<ul>
<li>
<a href="{$WWWROOT}user/denyrequest.php?id={$user->id}">
{str tag='denyrequest' section='group'}
</a>
</li>
{if $user->messages == 1}
<li>
<a href="{$WWWROOT}user/sendmessage.php?id={$user->id}">
{str tag='sendmessage' section='group'}
</a>
</li>
{/if}
</ul>
</div>
</td>
</tr>
</table>
</td>
{else}
<td>
<div class="fl">
<img src="{$WWWROOT}thumb.php?type=profileicon&amp;size=40x40&amp;id={$user->id}">
</div>
<table class="friendinfo">
<tr>
<th>
<h3>
<a href="{$WWWROOT}user/view.php?id=}$user->id}">
{$user->id|display_name|escape}
</a>
</h3>
</th>
<td rowspan="2" class="viewlist">
<h3>
{str tag='Views' section='group'}
</h3>
{if $user->views}
<ul>
{foreach from=$user->views item=view}
<li>
{$view}
<a href="{$WWWROOT}view/view.php?id={$view->id}">
{$view->title|escape}
</a>
</li>
{/foreach}
</ul>
{else}
<p>
{str tag='noviewstosee' section='group'}
</p>
{/if}
</td>
</tr>
<tr>
<td id="friendinfo_{$user->id}">
{if $user->introduction}
<p>
{$user->introduction|escape}
</p>
{/if}
<ul>
{if $user->messages > 0}
<li>
<a href="{$WWWROOT}user/sendmessage.php?id={$user->id}">
{str tag='sendmessage' section='group'}
</a>
</li>
{/if}
<li>
<a href="{$WWWROOT}user/removefriend.php?id={$user->id}">
{str tag='removefromfriendslist' section='group'}
</a>
</li>
</ul>
</td>
</tr>
</table>
</td>
{/if}
\ No newline at end of file
......@@ -30,8 +30,202 @@ require(dirname(dirname(__FILE__)) . '/init.php');
require_once('pieforms/pieform.php');
define('TITLE', get_string('myfriends'));
$filter = param_alpha('filter', 'all');
$offset = param_integer('offset', 0);
$limit = 25;
$userid = $USER->get('id');
$data = array();
if ($filter == 'current') {
$count = count_records_select('usr_friend', 'usr1 = ? OR usr2 = ?', array($userid, $userid));
$sql = 'SELECT u.id, u.username, u.firstname, u.lastname, u.preferredname,
(SELECT a.title FROM {artefact} a WHERE a.owner = u.id AND a.artefacttype = \'introduction\') AS introduction,
COALESCE((SELECT ap.value FROM {usr_account_preference} ap WHERE ap.usr = u.id AND ap.field = \'messages\'), \'allow\') AS messages
FROM {usr} u
WHERE u.id IN (
SELECT (CASE WHEN usr1 = ? THEN usr2 ELSE usr1 END) AS userid
FROM {usr_friend} WHERE (usr1 = ? OR usr2 = ?))
ORDER BY u.id';
$data = get_records_sql_assoc($sql, array($userid, $userid, $userid), $offset, $limit);
if (!$data || !$views = get_views(array_keys($data), null, null)) {
$views = array();
}
}
else if ($filter == 'pending') {
$count = count_records('usr_friend_request', 'owner', array($userid));
$sql = 'SELECT u.id, u.username, u.firstname, u.lastname, u.preferredname, fr.reason, 1 AS pending,
(SELECT a.title FROM {artefact} a WHERE a.owner = u.id AND a.artefacttype = \'introduction\') AS introduction,
COALESCE((SELECT ap.value FROM {usr_account_preference} ap WHERE ap.usr = u.id AND ap.field = \'messages\'), \'allow\') AS messages
FROM {usr} u
JOIN {usr_friend_request} fr ON fr.requester = u.id
WHERE fr.owner = ?
ORDER BY u.id';
$data = get_records_sql_array($sql, array($userid), $offset, $limit);
$views = array();
}
else {
$filter = 'all';
$count = count_records_select('usr_friend', 'usr1 = ? OR usr2 = ?', array($userid, $userid))
+ count_records('usr_friend_request', 'owner', array($userid));
$sql = 'SELECT u.id, u.username, u.firstname, u.lastname, u.preferredname, NULL as reason, 0 AS pending,
(SELECT a.title FROM {artefact} a WHERE a.owner = u.id AND a.artefacttype = \'introduction\') AS introduction,
COALESCE((SELECT ap.value FROM {usr_account_preference} ap WHERE ap.usr = u.id AND ap.field = \'messages\'), \'allow\') AS messages
FROM {usr} u
WHERE u.id IN (
SELECT (CASE WHEN usr1 = ? THEN usr2 ELSE usr1 END) AS userid
FROM {usr_friend} WHERE (usr1 = ? OR usr2 = ?))
UNION
SELECT u.id, u.username, u.firstname, u.lastname, u.preferredname, fr.reason, 1 AS pending,
(SELECT a.title FROM {artefact} a WHERE a.owner = u.id AND a.artefacttype = \'introduction\') AS introduction,
COALESCE((SELECT ap.value FROM {usr_account_preference} ap WHERE ap.usr = u.id AND ap.field = \'messages\'), \'allow\') AS messages
FROM {usr} u
JOIN {usr_friend_request} fr ON fr.requester = u.id
WHERE fr.owner = ?
ORDER BY pending DESC, id';
$data = get_records_sql_assoc($sql, array($userid, $userid, $userid, $userid));
if (!$data || !$views = get_views(array_keys($data), null, null)) {
$views = array();
}
}
if ($data) {
$data = array_values($data);
foreach ($data as $d) {
$d->name = display_name($d);
if (isset($d->introduction)) {
$d->introduction = format_introduction($d->introduction);
}
$d->messages = ($d->messages == 'allow' || is_friend($userid, $d->id) && $d->messages == 'friends' || $USER->get('admin')) ? 1 : 0;
}
}
$viewcount = array_map('count', $views);
// since php is so special and inconsistent, we can't use array_map for this because it breaks the top level indexes.
$cleanviews = array();
foreach ($views as $userindex => $viewarray) {
$cleanviews[$userindex] = array_slice($viewarray, 0, 5);
// Don't reveal any more about the view than necessary
foreach ($cleanviews as $userviews) {
foreach ($userviews as &$view) {
foreach (array_keys(get_object_vars($view)) as $key) {
if ($key != 'id' && $key != 'title') {
unset($view->$key);
}
}
}
}
}
if ($data) {
foreach ($data as $friend) {
if (isset($cleanviews[$friend->id])) {
$friend->views = $cleanviews[$friend->id];
}
}
foreach ($data as $friend) {
if ($friend->pending) {
$friend->accept = pieform(array(
'name' => 'acceptfriend' . $friend->id,
'successcallback' => 'acceptfriend_submit',
'renderer' => 'div',
'autofocus' => 'false',
'elements' => array(
'submit' => array(
'type' => 'submit',
'value' => get_string('approverequest', 'group')
),
'id' => array(
'type' => 'hidden',
'value' => $friend->id
)
)
));
}
}
}
$filterform = pieform(array(
'name' => 'filter',
'renderer' => 'oneline',
'elements' => array(
'filter' => array(
'type' => 'select',
'options' => array(
'all' => get_string('allfriends', 'group'),
'current' => get_string('currentfriends', 'group'),
'pending' => get_string('pendingfriends', 'group')
),
'defaultvalue' => $filter
),
'submit' => array(
'type' => 'submit',
'value' => get_string('filter')
)
)
));
$pagination = build_pagination(array(
'url' => get_config('wwwroot') . 'user/myfriends.php?filter=' . $filter,
'count' => $count,
'limit' => $limit,
'offset' => $offset,
'resultcounttextsingular' => get_string('friend', 'group'),
'resultcounttextplural' => get_string('friends', 'group'),
));
if (!$data) {
if ($filter == 'pending') {
$message = get_string('nobodyawaitsfriendapproval', 'group');
}
else {
$message = get_string('trysearchingforfriends', 'group', '<a href="' . get_config('wwwroot') . 'user/find.php">', '</a>');
}
}
function filter_submit(Pieform $form, $values) {
redirect('/user/myfriends.php?filter=' . $values['filter']);
}
function acceptfriend_submit(Pieform $form, $values) {
global $USER, $SESSION;
$user = get_record('usr', 'id', $values['id']);
// friend db record
$f = new StdClass;
$f->ctime = db_format_timestamp(time());
$f->usr1 = $user->id;
$f->usr2 = $USER->get('id');
// notification info
$n = new StdClass;
$n->url = get_config('wwwroot') . 'user/view.php?id=' . $USER->get('id');
$n->users = array($user->id);
$lang = get_user_language($user->id);
$displayname = display_name($USER, $user);
$n->message = get_string_from_language($lang, 'friendrequestacceptedmessage', 'group', $displayname, $displayname);
$n->subject = get_string_from_language($lang, 'friendrequestacceptedsubject', 'group');
db_begin();
delete_records('usr_friend_request', 'owner', $USER->get('id'), 'requester', $user->id);
insert_record('usr_friend', $f);
db_commit();
$SESSION->add_ok_msg(get_string('friendformacceptsuccess', 'group'));
redirect('/user/view.php?id=' . $values['id']);
}
$smarty = smarty();
$smarty->assign('heading', TITLE);
$smarty->assign('users', $data);
$smarty->assign('form', $filterform);
$smarty->assign('pagination', $pagination['html']);
if (isset($message)) {
$smarty->assign('message', $message);
}
$smarty->display('user/myfriends.tpl');
?>
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