Commit 6acb78c2 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Add friend invites and friend suggestions to groups (bug #845290)

When 'invitefriends' is enabled, all members of the group get a
button on the group homepage which allows them to send membership
invitations to anyone on their friends list.  The 'suggestfriends'
setting allows group members to spam their friends with suggestions
that they join the group.

Part of https://wiki.mahara.org/index.php/Developer_Area/Specifications_in_Development/Groups_revamp



Change-Id: Ifaf91ea59d569255de861efdcab97745f3feaa3a
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent 6dafa0fe
......@@ -54,6 +54,8 @@ $ALLOWEDKEYS = array(
'hidden',
'hidemembers',
'hidemembersfrommembers',
'invitefriends',
'suggestfriends',
);
if ($USER->get('admin')) {
$ALLOWEDKEYS[] = 'usersautoadded';
......
......@@ -71,6 +71,8 @@ else {
'hidden' => 0,
'hidemembers' => 0,
'hidemembersfrommembers' => 0,
'invitefriends' => 0,
'suggestfriends' => 0,
);
}
......@@ -182,6 +184,20 @@ if (!empty($forcegrouptype) || count($grouptypeoptions) < 2) {
);
}
$elements['invitefriends'] = array(
'type' => 'checkbox',
'title' => get_string('friendinvitations', 'group'),
'description' => get_string('invitefriendsdescription', 'group'),
'defaultvalue' => $group_data->invitefriends,
);
$elements['suggestfriends'] = array(
'type' => 'checkbox',
'title' => get_string('Recommendations', 'group'),
'description' => get_string('suggestfriendsdescription', 'group'),
'defaultvalue' => $group_data->suggestfriends,
);
$elements['pages'] = array(
'type' => 'html',
'title' => get_string('views'),
......@@ -333,6 +349,9 @@ function editgroup_validate(Pieform $form, $values) {
$form->set_error('request', get_string('membershipopenrequest', 'group'));
}
}
if (!empty($values['invitefriends']) && !empty($values['suggestfriends'])) {
$form->set_error('invitefriends', get_string('suggestinvitefriends', 'group'));
}
}
function editgroup_cancel_submit() {
......@@ -361,6 +380,8 @@ function editgroup_submit(Pieform $form, $values) {
'hidden' => intval($values['hidden']),
'hidemembers' => intval($values['hidemembers']),
'hidemembersfrommembers' => intval($values['hidemembersfrommembers']),
'invitefriends' => intval($values['invitefriends']),
'suggestfriends' => intval($values['suggestfriends']),
);
db_begin();
......@@ -400,6 +421,16 @@ $j(function() {
$j("#editgroup_request").removeAttr("disabled");
}
});
$j("#editgroup_invitefriends").click(function() {
if ($(this).checked) {
$j("#editgroup_suggestfriends").removeAttr("checked");
}
});
$j("#editgroup_suggestfriends").click(function() {
if ($(this).checked) {
$j("#editgroup_invitefriends").removeAttr("checked");
}
});
});
';
......
......@@ -39,9 +39,15 @@ if (!is_logged_in() && !$group->public) {
throw new AccessDeniedException();
}
$friends = param_integer('friends', 0);
$role = group_user_access($group->id);
if ($role != 'admin') {
throw new AccessDeniedException();
// Allow non-admins to get to this page when invitefriends is
// enabled and they're filtering by their friends.
if (!$friends || !$role || !$group->invitefriends) {
throw new AccessDeniedException();
}
}
define('TITLE', $group->name . ' - ' . get_string('sendinvitations', 'group'));
......@@ -61,6 +67,7 @@ $form = pieform(array(
'limit' => 100,
'html' => 0,
'membershiptype' => 'notinvited',
'friends' => $friends,
),
),
'submit' => array(
......@@ -77,10 +84,10 @@ $smarty->display('group/form.tpl');
exit;
function addmembers_submit(Pieform $form, $values) {
global $SESSION, $group, $USER;
global $SESSION, $group, $USER, $friends;
if (empty($values['users'])) {
redirect(get_config('wwwroot') . 'group/inviteusers.php?id=' . GROUP);
redirect(get_config('wwwroot') . 'group/inviteusers.php?id=' . GROUP . ($friends ? '&friends=1' : ''));
}
db_begin();
......@@ -90,5 +97,8 @@ function addmembers_submit(Pieform $form, $values) {
db_commit();
$SESSION->add_ok_msg(get_string('invitationssent', 'group', count($values['users'])));
if ($friends) {
redirect(get_config('wwwroot') . 'group/view.php?id=' . GROUP);
}
redirect(get_config('wwwroot') . 'group/members.php?id=' . GROUP);
}
......@@ -58,7 +58,11 @@ $membershiptype = param_variable('membershiptype', '');
$friends = param_integer('friends', 0);
if (!empty($membershiptype)) {
if ($role != 'admin') {
json_reply('local', get_string('accessdenied', 'error'));
// Non-admins are allowed to find the 'notinvited' users, but only if 'invitefriends'
// or 'suggestfriends' is enabled, and they're filtering by their friends list
if ($membershiptype != 'notinvited' || !$role || !($group->invitefriends || $group->suggestfriends) || !$friends) {
json_reply('local', get_string('accessdenied', 'error'));
}
}
}
......
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2011 Catalyst IT Ltd and others; see:
* http://wiki.mahara.org/Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage core
* @author Richard Mansfield
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
*
*/
define('PUBLIC', 1);
define('INTERNAL', 1);
define('MENUITEM', 'groups/members');
require(dirname(dirname(__FILE__)) . '/init.php');
require_once('group.php');
require_once('pieforms/pieform.php');
define('GROUP', param_integer('id'));
$group = group_current_group();
if (!is_logged_in() && !$group->public) {
throw new AccessDeniedException();
}
$role = group_user_access($group->id);
if (!$role || !$group->suggestfriends) {
throw new AccessDeniedException();
}
$subheading = get_string('suggesttofriends', 'group');
define('TITLE', $group->name . ' - ' . $subheading);
$form = pieform(array(
'name' => 'addmembers',
'elements' => array(
'users' => array(
'type' => 'userlist',
'lefttitle' => get_string('potentialmembers', 'group'),
'righttitle' => get_string('userstosendrecommendationsto', 'group'),
'searchscript' => 'group/membersearchresults.json.php',
'defaultvalue' => array(),
'filter' => false,
'searchparams' => array(
'id' => GROUP,
'limit' => 100,
'html' => 0,
'membershiptype' => 'notinvited',
'friends' => 1,
),
),
'submit' => array(
'type' => 'submit',
'value' => get_string('submit'),
)
)
));
$smarty = smarty();
$smarty->assign('subheading', $subheading);
$smarty->assign('form', $form);
$smarty->display('group/form.tpl');
exit;
function addmembers_submit(Pieform $form, $values) {
global $SESSION, $group, $USER;
if (empty($values['users'])) {
redirect(get_config('wwwroot') . 'group/suggest.php?id=' . GROUP);
}
require_once('activity.php');
activity_occurred('maharamessage', array(
'users' => $values['users'],
'subject' => '',
'message' => '',
'strings' => (object) array(
'subject' => (object) array(
'key' => 'suggestgroupnotificationsubject',
'section' => 'group',
'args' => array(display_name($USER)),
),
'message' => (object) array(
'key' => 'suggestgroupnotificationmessage',
'section' => 'group',
'args' => array(display_name($USER), hsc($group->name), get_config('sitename')),
),
),
'url' => get_config('wwwroot') . 'group/view.php?id=' . GROUP,
'urltext' => hsc($group->name),
));
$SESSION->add_ok_msg(get_string('recommendationssent', 'group', count($values['users'])));
redirect(get_config('wwwroot') . 'group/view.php?id=' . GROUP);
}
......@@ -102,6 +102,17 @@ $string['hidemembers'] = 'Hide membership';
$string['hidemembersdescription'] = 'Hide the group\'s membership listing from non-members.';
$string['hidemembersfrommembers'] = 'Hide membership from members';
$string['hidemembersfrommembersdescription'] = 'Members cannot be listed except by group admins. Admins will still be listed on the group home page.';
$string['friendinvitations'] = 'Friend invitations';
$string['invitefriendsdescription'] = 'If checked, members will be allowed to invite friends to join the group. Regardless of this setting, group admins can always send invitations to anyone.';
$string['invitefriends'] = 'Invite friends';
$string['Recommendations'] = 'Recommendations';
$string['suggestfriendsdescription'] = 'If checked, members can easily send a recommendation about this group to their friends from a button on the group homepage.';
$string['suggesttofriends'] = 'Suggest to friends';
$string['userstosendrecommendationsto'] = 'Users who will be sent a recommendation';
$string['suggestgroupnotificationsubject'] = '%s suggested you join a group';
$string['suggestgroupnotificationmessage'] = '%s suggested that you join the group "%s" on %s';
$string['recommendationssent'] = '%d recommendation(s) sent';
$string['suggestinvitefriends'] = 'You cannot enable both friend invitations and recommendations.';
$string['editgroupmembership'] = 'Edit group membership';
$string['editmembershipforuser'] = 'Edit membership for %s';
......
......@@ -347,6 +347,8 @@
<FIELD NAME="hidden" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" />
<FIELD NAME="hidemembers" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" />
<FIELD NAME="hidemembersfrommembers" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" />
<FIELD NAME="invitefriends" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" />
<FIELD NAME="suggestfriends" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
......
......@@ -2725,6 +2725,16 @@ function xmldb_core_upgrade($oldversion=0) {
$field = new XMLDBField('hidemembersfrommembers');
$field->setAttributes(XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, null, null, 0);
add_field($table, $field);
// Allow group members to invite friends
$field = new XMLDBField('invitefriends');
$field->setAttributes(XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, null, null, 0);
add_field($table, $field);
// Allow group members to recommend the group to friends
$field = new XMLDBField('suggestfriends');
$field->setAttributes(XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, null, null, 0);
add_field($table, $field);
}
return $status;
......
......@@ -285,6 +285,12 @@ function group_create($data) {
$data['quota'] = get_config_plugin('artefact', 'file', 'defaultgroupquota');
if (!empty($data['invitefriends']) && !empty($data['suggestfriends'])) {
throw new InvalidArgumentException("group_create: a group cannot enable both invitefriends and suggestfriends");
}
$data['invitefriends'] = (isset($data['invitefriends'])) ? intval($data['invitefriends']) : 0;
$data['suggestfriends'] = (isset($data['suggestfriends'])) ? intval($data['suggestfriends']) : 0;
if (isset($data['shortname']) && strlen($data['shortname'])) {
// This is a group whose details and membership can be updated automatically, using a
// webservice api or possibly csv upload.
......@@ -358,6 +364,8 @@ function group_create($data) {
'hidden' => $data['hidden'],
'hidemembers' => $data['hidemembers'],
'hidemembersfrommembers' => $data['hidemembersfrommembers'],
'invitefriends' => $data['invitefriends'],
'suggestfriends' => $data['suggestfriends'],
),
'id',
true
......@@ -501,6 +509,17 @@ function group_update($new, $create=false) {
unset($new->open);
unset($new->controlled);
// Ensure only one of invitefriends,suggestfriends gets enabled.
if (!empty($new->invitefriends)) {
$new->suggestfriends = 0;
}
else if (!isset($new->invitefriends)) {
$new->invitefriends = (int) ($old->invitefriends && empty($new->suggestfriends));
}
if (!isset($new->suggestfriends)) {
$new->suggestfriends = $old->suggestfriends;
}
$diff = array_diff_assoc((array)$new, (array)$old);
if (empty($diff)) {
return null;
......
......@@ -7,9 +7,16 @@
{str tag="youaregroup$group->role" section="grouptype.$group->grouptype"}
{/if}
</li>
{if $group->canleave}
<li class="leavegroup"><a href ="{$WWWROOT}group/leave.php?id={$group->id}&amp;returnto={$returnto}" class="btn-leavegroup"><span class="icon">{str tag="leavegroup" section="group"}</span></a></li>
{/if}
<li class="leavegroup">
{if $group->canleave}
<a href ="{$WWWROOT}group/leave.php?id={$group->id}&amp;returnto={$returnto}" class="btn-leavegroup"><span class="icon">{str tag="leavegroup" section="group"}</span></a>
{/if}
{if $group->invitefriends}
<a href ="{$WWWROOT}group/inviteusers.php?id={$group->id}&friends=1" class="btn"><span class="icon">{str tag="invitefriends" section="group"}</span></a>
{elseif $group->suggestfriends && ($group->request || $group->jointype == 'open')}
<a href ="{$WWWROOT}group/suggest.php?id={$group->id}" class="btn"><span class="icon">{str tag="suggesttofriends" section="group"}</span></a>
{/if}
</li>
{elseif $group->membershiptype == 'admin'}
<li class="admincontrol"><a href="{$WWWROOT}group/edit.php?id={$group->id}" title="{str tag=edit}" class="btn-editgroup"><span class="icon">{str tag=edit}</span></a>
<a href="{$WWWROOT}group/delete.php?id={$group->id}" title="{str tag=delete}" class="btn-deletegroup"><span class="icon">{str tag=delete}</span></a></li>
......
Supports Markdown
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