Commit 7c85159f authored by Francois Marier's avatar Francois Marier
Browse files

refactor group invititation to a new function



Based on 7391e47570eae36cf0b6aae586ee8749af626ef0 by Andrew Nicols
Signed-off-by: default avatarFrancois Marier <francois@catalyst.net.nz>
parent 51d1516d
......@@ -91,22 +91,8 @@ $smarty->display('group/invite.tpl');
function invitetogroup_submit(Pieform $form, $values) {
global $SESSION, $USER, $group, $user;
$data = new StdClass;
$data->group = $group->id;
$data->member= $user->id;
$data->ctime = db_format_timestamp(time());
$data->role = $values['role'];
insert_record('group_member_invite', $data);
$lang = get_user_language($user->id);
require_once('activity.php');
activity_occurred('maharamessage',
array('users' => array($user->id),
'subject' => get_string_from_language($lang, 'invitetogroupsubject', 'group'),
'message' => get_string_from_language($lang, 'invitetogroupmessage', 'group', display_name($USER, $user), $group->name),
'url' => get_config('wwwroot')
. 'group/view.php?id=' . $group->id));
group_invite_user($group, $user->id, $USER, $values['role']);
$SESSION->add_ok_msg(get_string('userinvited', 'group'));
redirect('/user/view.php?id=' . $user->id);
}
?>
......@@ -438,6 +438,32 @@ function group_remove_user($groupid, $userid=null, $force=false) {
}
}
/**
* Invite a user to a group.
*
* @param object $group group
* @param object $userid User to invite
* @param object $userfrom User sending the invitation
*/
function group_invite_user($group, $userid, $userfrom, $role='member') {
$user = optional_userobj($userid);
$data = new StdClass;
$data->group = $group->id;
$data->member= $user->id;
$data->ctime = db_format_timestamp(time());
$data->role = $role;
ensure_record_exists('group_member_invite', $data, $data);
$lang = get_user_language($user->id);
require_once('activity.php');
activity_occurred('maharamessage',
array('users' => array($user->id),
'subject' => get_string_from_language($lang, 'invitetogroupsubject', 'group'),
'message' => get_string_from_language($lang, 'invitetogroupmessage', 'group', display_name($userfrom, $user), $group->name),
'url' => get_config('wwwroot')
. 'group/view.php?id=' . $group->id));
}
// Pieforms for various operations on groups
/**
......
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