Commit c4bb3db4 authored by Penny Leach's avatar Penny Leach
Browse files

communnity watchlist button

parent 63289c56
......@@ -181,6 +181,21 @@ switch ($type) {
$view = new View($view);
$view->release($id);
json_reply(false, get_string('viewreleasedsuccess'));
break;
case 'watchlist':
if (record_exists('usr_watchlist_community', 'usr', $USER->get('id'), 'community', $community->id)) {
delete_records('usr_watchlist_community', 'usr', $USER->get('id'), 'community', $community->id);
json_reply(false, array('message' => get_string('removedcommunityfromwatchlist', 'activity'), 'member' => 0));
}
else {
$cwl = new StdClass;
$cwl->usr = $USER->get('id');
$cwl->community = $community->id;
$cwl->ctime = db_format_timestamp(time());
insert_record('usr_watchlist_community', $cwl);
json_reply(false, array('message' => get_string('addedcommunitytowatchlist', 'activity'), 'member' => 1));
}
break;
}
......
......@@ -131,6 +131,8 @@ $declinestr = get_string('declinerequest');
$updatefailedstr = get_string('updatefailed');
$requeststr = get_string('sendrequest');
$reasonstr = get_string('reason');
$removefromwatchliststr = get_string('removefromwatchlist', 'activity');
$addtowatchliststr = get_string('addtowatchlist', 'activity');
// all the permissions stuff
$tutor = (int)($membership < COMMUNITY_MEMBERSHIP_MEMBER);
......@@ -253,6 +255,25 @@ function releaseView(id) {
return false;
}
function toggleWatchlist() {
var pd = {'type': 'watchlist', 'id': '{$community->id}'};
var d = loadJSONDoc('view.json.php', pd);
var remove = '{$removefromwatchliststr}';
var add = '{$addtowatchliststr}';
d.addCallbacks(function (data) {
if (!data.error) {
if (data.message.member) {
$('watchlistcontrolbutton').innerHTML = remove;
}
else {
$('watchlistcontrolbutton').innerHTML = add;
}
$('messagediv').innerHTML = data.message.message;
}
});
return false;
}
function updateMembership() {
var pd = {'type': 'membercontrol', 'id': '{$community->id}'};
var e = getElementsByTagAndClassName(null, 'member');
......@@ -301,6 +322,7 @@ $smarty->assign('canrequestjoin', $canrequestjoin);
$smarty->assign('canleave', $canleave);
$smarty->assign('canacceptinvite', $invited);
$smarty->assign('community', $community);
$smarty->assign('onwatchlist', record_exists('usr_watchlist_community', 'usr', $USER->get('id'), 'community', $community->id));
$smarty->display('contacts/communities/view.tpl');
......
......@@ -89,4 +89,13 @@ $string['ownedby'] = 'owned by';
$string['objectionablecontentview'] = 'Objectionable content';
$string['objectionablecontentartefact'] = 'Objectionable content';
$string['newcommunitymembersubj'] = '%s is now a community member!';
$string['removedcommunitymembersubj'] = '%s is no longer a community member';
$string['addtowatchlist'] = 'Add to watchlist';
$string['removefromwatchlist'] = 'Remove from watchlist';
$string['removedcommunityfromwatchlist'] = 'The community has been removed from your watchlist';
$string['addedcommunitytowatchlist'] = 'The community was added to your watchlist';
?>
......@@ -290,6 +290,10 @@ function community_remove_member($communityid, $userid) {
}
}
delete_records('community_member', 'member', $userid, 'community', $communityid);
$user = optional_userobj($userid);
activity_occurred('watchlist',
array('community' => $communityid,
'subject' => get_string('removedcommunitymembersubj', 'activity', display_default_name($user))));
}
/**
......@@ -306,7 +310,10 @@ function community_add_member($communityid, $userid) {
$cm->ctime = db_format_timestamp(time());
$cm->tutor = 0;
insert_record('community_member', $cm);
$user = optional_userobj($userid);
activity_occurred('watchlist',
array('community' => $communityid,
'subject' => get_string('newcommunitymembersubj', 'activity', display_default_name($user))));
}
?>
......@@ -338,6 +338,42 @@ function display_name($user, $userto=null) {
return $user->preferredname;
}
/**
* function to format a users name when there is no user to look at them
* ie when display_name is not going to work..
* /
function display_default_name($user) {
if (is_array($user)) {
$user = (object)$user;
}
else if (is_numeric($user)) {
$user = get_record('usr', 'id', $user);
}
if (!is_object($user)) {
throw new InvalidArgumentException("Invalid user passed to display_name");
}
if ($user instanceof User) {
$userObj = $user;
$user = new StdClass;
$user->id = $userObj->get('id');
$user->preferredname = $userObj->get('preferredname');
$user->firstname = $userObj->get('firstname');
$user->lastname = $userObj->get('lastname');
$user->admin = $userObj->get('admin');
}
// if they don't have a preferred name set, just return here
if (empty($user->preferredname)) {
return $user->firstname . ' ' . $user->lastname;
}
else {
return $user->preferedname;
}
}
/**
* Converts a user object to a full name representation, honouring the language
* setting.
......
......@@ -7,7 +7,7 @@
{include file="columnleftstart.tpl"}
<h2>{$community->name}</h2>
<p>{str tag='owner'}: {$community->ownername}</p>
<p>{str tag='owner'}: {$community->ownername}</p>
{assign var="jointype" value=$community->jointype}
{assign var="joinstr" value=communityjointype$jointype}
<p>{str tag=$joinstr}</p>
......@@ -18,6 +18,9 @@
{elseif $canacceptinvite} <p>{str tag='communityhaveinvite'} <a href="view.php?id={$community->id}&amp;joincontrol=acceptinvite">{str tag='acceptinvitecommunity'}</a> | <a href="view.php?id={$community->id}&amp;joincontrol=declineinvite">{str tag='declineinvitecommunity'}</a></p>{/if}
<div id="messagediv"></div>
{if $member}
<div id="communitywatchlistcontrol">
<button type="button" id="watchlistcontrolbutton" class="button" onclick="return toggleWatchlist();">{if $onwatchlist}{str tag="removefromwatchlist" section="activity"}{else}{str tag="addtowatchlist" section="activity"}{/if}</button>
</div>
<div class="communityviews">
<h5>{str tag='views'}</h5>
{if $tutor && $controlled}
......
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