From 2183d53ff89f09a1fd3f5493f23529833b0bc5ed Mon Sep 17 00:00:00 2001 From: Jamie Snape Date: Thu, 22 Oct 2015 14:28:53 -0400 Subject: [PATCH] Directly add a user to a community/group --- core/controllers/CommunityController.php | 25 ++++++++++++++++--- core/public/js/community/community.manage.js | 5 ++++ .../js/community/community.selectgroup.js | 5 +++- core/public/js/community/community.view.js | 5 ++++ core/views/community/manage.phtml | 2 +- core/views/community/selectgroup.phtml | 2 +- core/views/community/view.phtml | 5 ++++ 7 files changed, 43 insertions(+), 6 deletions(-) diff --git a/core/controllers/CommunityController.php b/core/controllers/CommunityController.php index a7097391c..d0812fb42 100644 --- a/core/controllers/CommunityController.php +++ b/core/controllers/CommunityController.php @@ -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 '.$community->getName().' community on Midas Platform.

Click here 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')); } } @@ -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 { diff --git a/core/public/js/community/community.manage.js b/core/public/js/community/community.manage.js index b95f60b2c..0ecfb1e7d 100644 --- a/core/public/js/community/community.manage.js +++ b/core/public/js/community/community.manage.js @@ -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); }); diff --git a/core/public/js/community/community.selectgroup.js b/core/public/js/community/community.selectgroup.js index 1de5a1890..95288e368 100644 --- a/core/public/js/community/community.selectgroup.js +++ b/core/public/js/community/community.selectgroup.js @@ -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 = { @@ -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); diff --git a/core/public/js/community/community.view.js b/core/public/js/community/community.view.js index 9265cd93b..369e04cb2 100644 --- a/core/public/js/community/community.view.js +++ b/core/public/js/community/community.view.js @@ -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); diff --git a/core/views/community/manage.phtml b/core/views/community/manage.phtml index b98825884..0f390b040 100644 --- a/core/views/community/manage.phtml +++ b/core/views/community/manage.phtml @@ -287,7 +287,7 @@ if ($this->isAdmin) { ?>
- t('Create a new group') ?>, , t('Add user to group') ?> + t('Create a new group') ?>, t('Add user to group') ?>, t('Invite user to group') ?>