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

Commit

Permalink
Directly add a user to a community/group
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie Snape committed Oct 22, 2015
1 parent 0c81d73 commit 2183d53
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 6 deletions.
25 changes: 22 additions & 3 deletions core/controllers/CommunityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -523,9 +523,28 @@ public function addusertogroupAction()
$member_group = $community->getMemberGroup();
$this->Group->addUser($member_group, $user);
$this->Group->addUser($group, $user);
echo JsonComponent::encode(array(true, 'User added.'));

$email = $user->getEmail();
$url = $this->getServerURL().$this->view->webroot;
$subject = 'Joined New Community';
$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.';
$result = Zend_Registry::get('notifier')->callback(
'CALLBACK_CORE_SEND_MAIL_MESSAGE',
array(
'to' => $email,
'subject' => $subject,
'html' => $body,
'event' => 'community_add_user',
)
);

if ($result) {
echo JsonComponent::encode(array(true, 'User added and notification sent to '.$email));
} else {
echo JsonComponent::encode(array(true, 'User added but notification not sent'));
}
} else {
echo JsonComponent::encode(array(false, 'Unable to add user.'));
echo JsonComponent::encode(array(false, 'Unable to add user'));
}
}

Expand Down Expand Up @@ -604,7 +623,7 @@ public function sendinvitationAction()
if ($result) {
echo JsonComponent::encode(array(true, 'Invitation sent to '.$email));
} else {
echo JsonComponent::encode(array(true, 'Invitation not sent'));
echo JsonComponent::encode(array(true, 'Invitation created but not sent'));
}
}
} else {
Expand Down
5 changes: 5 additions & 0 deletions core/public/js/community/community.manage.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ midas.community.manage.init = function () {

$('a#addUserToGroupLink').click(function () {
midas.loadDialog('invitationCommunity', '/community/invitation?directadd=true&communityId=' + encodeURIComponent(json.community.community_id));
midas.showDialog('Add user', false);
});

$('a#inviteUserToGroupLink').click(function () {
midas.loadDialog('invitationCommunity', '/community/invitation?communityId=' + encodeURIComponent(json.community.community_id));
midas.showDialog(json.community.sendInvitation, false);
});

Expand Down
5 changes: 4 additions & 1 deletion core/public/js/community/community.selectgroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ var midas = midas || {};

$(document).ready(function () {
'use strict';
if (typeof midas.invite.directAdd !== 'undefined' && midas.invite.directAdd == 1) {
$('#inviteOrAdd').html('add');
}
$('#groupSelectOk').click(function () {
var url = json.global.webroot + '/community/sendinvitation';
var params = {
Expand All @@ -21,7 +24,7 @@ $(document).ready(function () {
if (typeof midas.invite.directAdd !== 'undefined' && midas.invite.directAdd == 1) {
url = json.global.webroot + '/community/addusertogroup';
}
$.post(json.global.webroot + '/community/sendinvitation', params, function (data) {
$.post(url, params, function (data) {
var jsonResponse = $.parseJSON(data);
if (jsonResponse[0]) {
midas.createNotice(jsonResponse[1], 3000);
Expand Down
5 changes: 5 additions & 0 deletions core/public/js/community/community.view.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ $(document).ready(function () {
$('img.tableLoading').hide();
$('table#browseTable').show();

$('a#addUserLink').click(function () {
midas.loadDialog('invitationCommunity', '/community/invitation?directadd=true&communityId=' + encodeURIComponent(json.community.community_id));
midas.showDialog('Add user', false);
});

$('a#sendInvitationLink').click(function () {
midas.loadDialog('invitationCommunity', '/community/invitation?communityId=' + encodeURIComponent(json.community.community_id));
midas.showDialog(json.community.sendInvitation, false);
Expand Down
2 changes: 1 addition & 1 deletion core/views/community/manage.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ if ($this->isAdmin) {
?>
</div>
<hr>
<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='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>

<div style="display:none;" id='createGroupFrom'>
<form class="editGroupForm genericForm" method="<?php echo $this->createGroupForm['method'] ?>"
Expand Down
2 changes: 1 addition & 1 deletion core/views/community/selectgroup.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
href="<?php echo $this->coreWebroot ?>/public/css/community/community.selectgroup.css"/>

<div class="groupSelectContainer">
Which community group would you like to invite the user to?
Which community group would you like to <span id="inviteOrAdd">invite</span> the user to?
<div>
<select id="groupSelect">
<?php
Expand Down
5 changes: 5 additions & 0 deletions core/views/community/view.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ $strippedDescription = strip_tags($description);
))}'><img alt='' src='{$this->coreWebroot}/public/images/icons/edit.png'/> {$this->t('Manage')}</a></li>
";
echo "
<li><a id='addUserLink'><img alt='' src='{$this->coreWebroot}/public/images/icons/add.png'/> {$this->t(
'Add user'
)}</a></li>
";
echo "
<li><a id='sendInvitationLink'><img alt='' src='{$this->coreWebroot}/public/images/icons/email.png'/> {$this->t(
'Send invitation'
)}</a></li>
Expand Down

0 comments on commit 2183d53

Please sign in to comment.