Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit 2183d53

Browse files
author
Jamie Snape
committed
Directly add a user to a community/group
1 parent 0c81d73 commit 2183d53

File tree

7 files changed

+43
-6
lines changed

7 files changed

+43
-6
lines changed

core/controllers/CommunityController.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -523,9 +523,28 @@ public function addusertogroupAction()
523523
$member_group = $community->getMemberGroup();
524524
$this->Group->addUser($member_group, $user);
525525
$this->Group->addUser($group, $user);
526-
echo JsonComponent::encode(array(true, 'User added.'));
526+
527+
$email = $user->getEmail();
528+
$url = $this->getServerURL().$this->view->webroot;
529+
$subject = 'Joined New Community';
530+
$body = $this->userSession->Dao->getFullName().' has added you to the <b>'.$community->getName().'</b> community on Midas Platform.<br/><br/><a href="'.$url.'/community/'.$community->getKey().'">Click here</a> to see the community.';
531+
$result = Zend_Registry::get('notifier')->callback(
532+
'CALLBACK_CORE_SEND_MAIL_MESSAGE',
533+
array(
534+
'to' => $email,
535+
'subject' => $subject,
536+
'html' => $body,
537+
'event' => 'community_add_user',
538+
)
539+
);
540+
541+
if ($result) {
542+
echo JsonComponent::encode(array(true, 'User added and notification sent to '.$email));
543+
} else {
544+
echo JsonComponent::encode(array(true, 'User added but notification not sent'));
545+
}
527546
} else {
528-
echo JsonComponent::encode(array(false, 'Unable to add user.'));
547+
echo JsonComponent::encode(array(false, 'Unable to add user'));
529548
}
530549
}
531550

@@ -604,7 +623,7 @@ public function sendinvitationAction()
604623
if ($result) {
605624
echo JsonComponent::encode(array(true, 'Invitation sent to '.$email));
606625
} else {
607-
echo JsonComponent::encode(array(true, 'Invitation not sent'));
626+
echo JsonComponent::encode(array(true, 'Invitation created but not sent'));
608627
}
609628
}
610629
} else {

core/public/js/community/community.manage.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ midas.community.manage.init = function () {
2626

2727
$('a#addUserToGroupLink').click(function () {
2828
midas.loadDialog('invitationCommunity', '/community/invitation?directadd=true&communityId=' + encodeURIComponent(json.community.community_id));
29+
midas.showDialog('Add user', false);
30+
});
31+
32+
$('a#inviteUserToGroupLink').click(function () {
33+
midas.loadDialog('invitationCommunity', '/community/invitation?communityId=' + encodeURIComponent(json.community.community_id));
2934
midas.showDialog(json.community.sendInvitation, false);
3035
});
3136

core/public/js/community/community.selectgroup.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ var midas = midas || {};
66

77
$(document).ready(function () {
88
'use strict';
9+
if (typeof midas.invite.directAdd !== 'undefined' && midas.invite.directAdd == 1) {
10+
$('#inviteOrAdd').html('add');
11+
}
912
$('#groupSelectOk').click(function () {
1013
var url = json.global.webroot + '/community/sendinvitation';
1114
var params = {
@@ -21,7 +24,7 @@ $(document).ready(function () {
2124
if (typeof midas.invite.directAdd !== 'undefined' && midas.invite.directAdd == 1) {
2225
url = json.global.webroot + '/community/addusertogroup';
2326
}
24-
$.post(json.global.webroot + '/community/sendinvitation', params, function (data) {
27+
$.post(url, params, function (data) {
2528
var jsonResponse = $.parseJSON(data);
2629
if (jsonResponse[0]) {
2730
midas.createNotice(jsonResponse[1], 3000);

core/public/js/community/community.view.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ $(document).ready(function () {
3030
$('img.tableLoading').hide();
3131
$('table#browseTable').show();
3232

33+
$('a#addUserLink').click(function () {
34+
midas.loadDialog('invitationCommunity', '/community/invitation?directadd=true&communityId=' + encodeURIComponent(json.community.community_id));
35+
midas.showDialog('Add user', false);
36+
});
37+
3338
$('a#sendInvitationLink').click(function () {
3439
midas.loadDialog('invitationCommunity', '/community/invitation?communityId=' + encodeURIComponent(json.community.community_id));
3540
midas.showDialog(json.community.sendInvitation, false);

core/views/community/manage.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ if ($this->isAdmin) {
287287
?>
288288
</div>
289289
<hr>
290-
<a href="javascript:;" id='createGroupLink'> <?php echo $this->t('Create a new group') ?></a>, , <a href="javascript:;" id='addUserToGroupLink'> <?php echo $this->t('Add user to group') ?></a>
290+
<a href="javascript:;" id='createGroupLink'> <?php echo $this->t('Create a new group') ?></a>, <a href="javascript:;" id='addUserToGroupLink'> <?php echo $this->t('Add user to group') ?></a>, <a href="javascript:;" id='inviteUserToGroupLink'> <?php echo $this->t('Invite user to group') ?></a>
291291

292292
<div style="display:none;" id='createGroupFrom'>
293293
<form class="editGroupForm genericForm" method="<?php echo $this->createGroupForm['method'] ?>"

core/views/community/selectgroup.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
href="<?php echo $this->coreWebroot ?>/public/css/community/community.selectgroup.css"/>
2525

2626
<div class="groupSelectContainer">
27-
Which community group would you like to invite the user to?
27+
Which community group would you like to <span id="inviteOrAdd">invite</span> the user to?
2828
<div>
2929
<select id="groupSelect">
3030
<?php

core/views/community/view.phtml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,11 @@ $strippedDescription = strip_tags($description);
206206
))}'><img alt='' src='{$this->coreWebroot}/public/images/icons/edit.png'/> {$this->t('Manage')}</a></li>
207207
";
208208
echo "
209+
<li><a id='addUserLink'><img alt='' src='{$this->coreWebroot}/public/images/icons/add.png'/> {$this->t(
210+
'Add user'
211+
)}</a></li>
212+
";
213+
echo "
209214
<li><a id='sendInvitationLink'><img alt='' src='{$this->coreWebroot}/public/images/icons/email.png'/> {$this->t(
210215
'Send invitation'
211216
)}</a></li>

0 commit comments

Comments
 (0)