Commit 115632da authored by Ruslan Kabalin's avatar Ruslan Kabalin Committed by Francois Marier
Browse files

Add button for denying requests to join a group



For those groups which require people to "Request membership", allow
admins to decline the membership.
Signed-off-by: default avatarRuslan Kabalin <ruslan.kabalin@luns.net.uk>
Signed-off-by: default avatarFrancois Marier <francois@catalyst.net.nz>
parent 3a532a44
......@@ -161,6 +161,7 @@ $string['Group'] = 'Group';
$string['groups'] = 'groups';
$string['notamember'] = 'You are not a member of this group';
$string['notmembermayjoin'] = 'You must join the group \'%s\' to see this page.';
$string['declinerequestsuccess'] = 'Group membership request has been declined sucessfully.';
// friendslist
$string['reasonoptional'] = 'Reason (optional)';
......
......@@ -572,6 +572,32 @@ function group_get_removeuser_form($userid, $groupid) {
));
}
/**
* Form for denying request (request jointype group)
*/
function group_get_denyuser_form($userid, $groupid) {
require_once('pieforms/pieform.php');
return pieform(array(
'name' => 'denyuser' . $userid,
'successcallback' => 'group_denyuser_submit',
'renderer' => 'oneline',
'elements' => array(
'group' => array(
'type' => 'hidden',
'value' => $groupid,
),
'member' => array(
'type' => 'hidden',
'value' => $userid,
),
'denyuser' => array(
'type' => 'submit',
'value' => get_string('declinerequest', 'group'),
),
),
));
}
// Functions for handling submission of group related forms
function joingroup_submit(Pieform $form, $values) {
......@@ -625,6 +651,24 @@ function group_adduser_submit(Pieform $form, $values) {
redirect('/group/members.php?id=' . $group);
}
/**
* Denying request (request jointype group)
*/
function group_denyuser_submit(Pieform $form, $values) {
global $SESSION;
$group = (int)$values['group'];
if (group_user_access($group) != 'admin') {
$SESSION->add_error_msg(get_string('accessdenied', 'error'));
redirect('/group/members.php?id=' . $group . '&membershiptype=request');
}
delete_records('group_member_request', 'group', $values['group'], 'member', $values['member']);
$SESSION->add_ok_msg(get_string('declinerequestsuccess', 'group'));
if (count_records('group_member_request', 'group', $group)) {
redirect('/group/members.php?id=' . $group . '&membershiptype=request');
}
redirect('/group/members.php?id=' . $group);
}
function group_removeuser_validate(Pieform $form, $values) {
global $user, $group, $SESSION;
if (!group_user_can_leave($values['group'], $values['member'])) {
......@@ -814,6 +858,7 @@ function group_get_membersearch_data($group, $query, $offset, $limit, $membershi
if ($membershiptype == 'request') {
foreach ($results['data'] as &$r) {
$r['addform'] = group_get_adduser_form($r['id'], $group);
$r['denyform'] = group_get_denyuser_form($r['id'], $group);
// TODO: this will suck when there's quite a few on the page,
// would be better to grab all the reasons in one go
$r['reason'] = get_field('group_member_request', 'reason', 'group', $group, 'member', $r['id']);
......
......@@ -18,6 +18,7 @@
<label>{str tag=reason}:</label> {$r.reason|format_whitespace}{/if}
</div>
<div class="right btn-add">{$r.addform}</div>
<div class="right btn-add">{$r.denyform}</div>
{elseif $membershiptype == 'invite'}
<div>{str tag=hasbeeninvitedtojoin section=group}</div>
{/if}
......
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