Skip to content

Commit

Permalink
added: listing of the email invitations for groups (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeabakker committed Mar 7, 2014
1 parent b44bdba commit 9ea9a71
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 37 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ x.x:

- added: plugin setting to indicate if a group is hidden
- added: option to configure a group welcome message (#41)
- added: listing of the email invitations for groups (#42)
- fixed: layout issue in plugin settings
- fixed: you can no join groups you were invited for on the group profile page
- fixed: misleading translation for a group cleanup setting (#22)
Expand Down
13 changes: 11 additions & 2 deletions actions/groups/email_invitation.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,25 @@

if (!empty($group)) {
if (groups_join_group($group, $user)) {
$invitecode = sanitise_string($invitecode);

$options = array(
"guid" => $group->getGUID(),
"annotation_name" => "email_invitation",
"annotation_value" => $invitecode,
"wheres" => array("(v.string = '" . $invitecode . "' OR v.string LIKE '" . $invitecode . "|%')"),
"annotation_owner_guid" => $group->getGUID(),
"limit" => 1
);

if ($annotations = elgg_get_annotations($options)) {
$annotations = elgg_get_annotations($options);
if (!empty($annotations)) {
// ignore access in order to cleanup the invitation
$ia = elgg_set_ignore_access(true);

$annotations[0]->delete();

// restore access
elgg_set_ignore_access($ia);
}

$forward_url = $group->getURL();
Expand Down
32 changes: 32 additions & 0 deletions actions/groups/revoke_email_invitation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* Revoke an email inviation for a group
*/

$annotation_id = (int) get_input("annotation_id");
$group_guid = (int) get_input("group_guid");

if (!empty($group_guid) && !empty($annotation_id)) {
$group = get_entity($group_guid);
$annotation = elgg_get_annotation_from_id($annotation_id);

if (!empty($group) && elgg_instanceof($group, "group") && !empty($annotation)) {

if ($group->canEdit() && ($annotation->name == "email_invitation")) {

if ($annotation->delete()) {
system_message(elgg_echo("group_tools:action:revoke_email_invitation:success"));
} else {
register_error(elgg_echo("group_tools:action:revoke_email_invitation:error"));
}
} else {
register_error(elgg_echo("groups:cantedit"));
}
} else {
register_error(elgg_echo("groups:notfound:details"));
}
} else {
register_error(elgg_echo("InvalidParameterException:MissingParameter"));
}

forward(REFERER);
11 changes: 8 additions & 3 deletions languages/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,10 @@

// group membership requests
'group_tools:groups:membershipreq:requests' => "Membership requests",
'group_tools:groups:membershipreq:invitations' => "Outstanding invitations",
'group_tools:groups:membershipreq:invitations:none' => "No outstanding invitations",
'group_tools:groups:membershipreq:invitations' => "Invited users",
'group_tools:groups:membershipreq:invitations:none' => "No pending user invitations",
'group_tools:groups:membershipreq:email_invitations' => "Invited e-mail addresses",
'group_tools:groups:membershipreq:email_invitations:none' => "No pending e-mail invitations",
'group_tools:groups:membershipreq:invitations:revoke:confirm' => "Are you sure you wish to revoke this invitation",

// group invitations
Expand Down Expand Up @@ -406,7 +408,10 @@
'group_tools:action:welcome_message:success' => "The welcome message was saved",

'group_tools:welcome_message:subject' => "Welcome to %s",
'' => "",

// email invitations
'group_tools:action:revoke_email_invitation:error' => "An error occured while revoking the invitation, please try again",
'group_tools:action:revoke_email_invitation:success' => "The invitation was revoked",
);

add_translation("en", $english);
13 changes: 13 additions & 0 deletions languages/nl.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
<?php
$language = array (
'group_tools:join:already:tooltip' => 'Je bent uitgenodigd voor deze groep, dus je kunt direct lid worden.',
'group_tools:groups:membershipreq:email_invitations' => 'Uitgenodigde e-mail adressen',
'group_tools:groups:membershipreq:email_invitations:none' => 'Geen uitstaande e-mail uitnodigingen',
'group_tools:welcome_message:title' => 'Groep welkom bericht',
'group_tools:welcome_message:description' => 'Je kunt een welkomstbericht configureren welke wordt verzonden aan nieuwe leden van de groep zodra ze lid worden. Als je geen bericht wilt versturen moet je dit veld leeg laten.',
'group_tools:welcome_message:explain' => 'Om het bericht te personaliseren kun je gebruik maken van de volgende plaatsaanduidingen:
[name]: de naam van de nieuwe gebruiker (bijv. %s)
[group_name]: de naam van deze groep (bijv. %s)
[group_url]: de URL naar deze groep (bijv. %s)',
'group_tools:action:welcome_message:success' => 'Het welkomstbericht is opgeslagen',
'group_tools:welcome_message:subject' => 'Welkom bij %s',
'group_tools:action:revoke_email_invitation:error' => 'Er is een fout opgetreden tijdens het intrekken van de uitnodiging, probeer het nogmaals',
'group_tools:action:revoke_email_invitation:success' => 'De uitnodiging is ingetrokken',
'group_tools:settings:show_hidden_group_indicator:group_acl' => 'Ja, als de groep alleen voor leden is',
'group_tools:settings:show_hidden_group_indicator:logged_in' => 'Ja, als de groep niet publiek is',
'group_tools:settings:show_hidden_group_indicator' => 'Toon een icoon als een groep verborgen is',
Expand Down
23 changes: 20 additions & 3 deletions lib/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,18 @@ function group_tools_check_group_email_invitation($invite_code, $group_guid = 0)
"type" => "group",
"limit" => 1,
"site_guids" => false,
"annotation_name_value_pairs" => array("email_invitation" => $invite_code)
"annotation_name_value_pairs" => array(
array(
"name" => "email_invitation",
"value" => $invite_code
),
array(
"name" => "email_invitation",
"value" => $invite_code . "|%",
"operand" => "LIKE"
)
),
"annotation_name_value_pairs_operator" => "OR"
);

if (!empty($group_guid)) {
Expand All @@ -30,6 +41,7 @@ function group_tools_check_group_email_invitation($invite_code, $group_guid = 0)

// find hidden groups
$ia = elgg_set_ignore_access(true);

$groups = elgg_get_entities_from_annotations($options);

if (!empty($groups)) {
Expand Down Expand Up @@ -179,7 +191,7 @@ function group_tools_invite_email(ElggGroup $group, $email, $text = "", $resend

if (empty($found_group)) {
// register invite with group
$group->annotate("email_invitation", $invite_code, ACCESS_LOGGED_IN, $group->getGUID());
$group->annotate("email_invitation", $invite_code . "|" . $email, ACCESS_LOGGED_IN, $group->getGUID());
}

// make subject
Expand All @@ -196,6 +208,7 @@ function group_tools_invite_email(ElggGroup $group, $email, $text = "", $resend
elgg_get_site_url() . "groups/invitations/?invitecode=" . $invite_code,
$invite_code
));
register_error($invite_code);

$params = array(
"group" => $group,
Expand Down Expand Up @@ -319,7 +332,11 @@ function group_tools_get_invited_groups_by_email($email, $site_guid = 0) {
"JOIN " . $dbprefix . "metastrings msv ON a.value_id = msv.id"
),
"wheres" => array(
"(a.name_id = " . $email_invitation_id . " AND msv.string = md5(CONCAT('" . $site_secret . $email . "', e.guid)))"
"(a.name_id = " . $email_invitation_id . " AND
(msv.string = md5(CONCAT('" . $site_secret . $email . "', e.guid))
OR msv.string LIKE CONCAT(md5(CONCAT('" . $site_secret . $email . "', e.guid)), '|%')
)
)"
)
);

Expand Down
16 changes: 15 additions & 1 deletion pages/groups/membershipreq.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
$title = elgg_echo("groups:membershiprequests");

if (!empty($group) && elgg_instanceof($group, "group") && $group->canEdit()) {
// change page title
if ($group->isPublicMembership()) {
$title = elgg_echo("group_tools:menu:invitations");
}

elgg_push_breadcrumb(elgg_echo("groups"), "groups/all");
elgg_push_breadcrumb($group->name, $group->getURL());
elgg_push_breadcrumb($title);
Expand All @@ -26,7 +31,7 @@
"relationship" => "membership_request",
"relationship_guid" => $guid,
"inverse_relationship" => true,
"limit" => 0,
"limit" => false,
));

// invited users
Expand All @@ -37,10 +42,19 @@
"limit" => false
));

// invited emails
$emails = elgg_get_annotations(array(
"annotation_name" => "email_invitation",
"annotation_owner_guid" => $group->getGUID(),
"wheres" => array("(v.string LIKE '%|%')"),
"limit" => false
));

$content = elgg_view("groups/membershiprequests", array(
"requests" => $requests,
"invitations" => $invitations,
"entity" => $group,
"emails" => $emails
));

} else {
Expand Down
16 changes: 5 additions & 11 deletions start.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ function group_tools_init() {

elgg_register_action("groups/email_invitation", dirname(__FILE__) . "/actions/groups/email_invitation.php");
elgg_register_action("groups/decline_email_invitation", dirname(__FILE__) . "/actions/groups/decline_email_invitation.php");
elgg_register_action("group_tools/revoke_email_invitation", dirname(__FILE__) . "/actions/groups/revoke_email_invitation.php");

elgg_register_action("group_tools/order_groups", dirname(__FILE__) . "/actions/order_groups.php", "admin");

Expand Down Expand Up @@ -202,27 +203,20 @@ function group_tools_pagesetup() {
"count" => true
);

$invite_options = array(
"type" => "user",
"relationship" => "invited",
"relationship_guid" => $page_owner->getGUID(),
"count" => true
);
$requests = elgg_get_entities_from_relationship($request_options);

$postfix = "";
if ($requests = elgg_get_entities_from_relationship($request_options)) {
if (!empty($requests)) {
$postfix = " [" . $requests . "]";
} elseif ($invited = elgg_get_entities_from_relationship($invite_options)) {
$postfix = " [" . $invited . "]";
}

if (!$page_owner->isPublicMembership() || !empty($requests)) {
if (!$page_owner->isPublicMembership()) {
elgg_register_menu_item("page", array(
"name" => "membership_requests",
"text" => elgg_echo("groups:membershiprequests") . $postfix,
"href" => "groups/requests/" . $page_owner->getGUID(),
));
} elseif (!empty($invited)) {
} else {
elgg_register_menu_item("page", array(
"name" => "membership_requests",
"text" => elgg_echo("group_tools:menu:invitations") . $postfix,
Expand Down
70 changes: 53 additions & 17 deletions views/default/groups/membershiprequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* @uses $vars["invitations"] Array of ElggUsers who where invited
*/

$group = elgg_extract("entity", $vars);

// show membership requests
$title = elgg_echo("group_tools:groups:membershipreq:requests");

Expand All @@ -22,7 +24,7 @@
"is_trusted" => true,
));

$url = "action/groups/addtogroup?user_guid={$user->guid}&group_guid={$vars["entity"]->guid}";
$url = "action/groups/addtogroup?user_guid=" . $user->getGUID() . "&group_guid=" . $group->getGUID();
$url = elgg_add_action_tokens_to_url($url);
$accept_button = elgg_view("output/url", array(
"href" => $url,
Expand All @@ -31,12 +33,12 @@
"is_trusted" => true,
));

$url = "action/groups/killrequest?user_guid=" . $user->guid . "&group_guid=" . $vars["entity"]->guid;
$url = "action/groups/killrequest?user_guid=" . $user->getGUID() . "&group_guid=" . $group->getGUID();
$delete_button = elgg_view("output/confirmlink", array(
"href" => $url,
"confirm" => elgg_echo("groups:joinrequest:remove:check"),
"text" => elgg_echo("delete"),
"class" => "elgg-button elgg-button-delete mlm",
"href" => $url,
"confirm" => elgg_echo("groups:joinrequest:remove:check"),
"text" => elgg_echo("delete"),
"class" => "elgg-button elgg-button-delete mlm",
));

$body = "<h4>$user_title</h4>";
Expand Down Expand Up @@ -64,24 +66,23 @@
$icon = elgg_view_entity_icon($user, "tiny", array("use_hover" => "true"));

$user_title = elgg_view("output/url", array(
"href" => $user->getURL(),
"text" => $user->name,
"is_trusted" => true,
"href" => $user->getURL(),
"text" => $user->name,
"is_trusted" => true,
));

$url = "action/groups/killinvitation?user_guid=" . $user->guid . "&group_guid=" . $vars["entity"]->guid;
$url = "action/groups/killinvitation?user_guid=" . $user->getGUID() . "&group_guid=" . $group->getGUID();
$delete_button = elgg_view("output/confirmlink", array(
"href" => $url,
"confirm" => elgg_echo("group_tools:groups:membershipreq:invitations:revoke:confirm"),
"text" => elgg_echo("group_tools:revoke"),
"class" => "elgg-button elgg-button-delete mlm",
"href" => $url,
"confirm" => elgg_echo("group_tools:groups:membershipreq:invitations:revoke:confirm"),
"text" => elgg_echo("group_tools:revoke"),
"class" => "elgg-button elgg-button-delete mlm",
));

$body = "<h4>$user_title</h4>";
$alt = $delete_button;


$content .= "<li class='pvs'>";
$content .= elgg_view_image_block($icon, $body, array("image_alt" => $alt));
$content .= elgg_view_image_block($icon, $body, array("image_alt" => $delete_button));
$content .= "</li>";
}

Expand All @@ -91,3 +92,38 @@
}

echo elgg_view_module("info", $title, $content);

// show email invitations
$title = elgg_echo("group_tools:groups:membershipreq:email_invitations");

$emails = elgg_extract("emails", $vars);
if (!empty($emails)) {
$content = "<ul class='elgg-list'>";

foreach ($emails as $annotation) {

list(,$email) = explode("|", $annotation->value);

$email_title = elgg_view("output/email", array("value" => $email));

$url = "action/group_tools/revoke_email_invitation?annotation_id=" . $annotation->id . "&group_guid=" . $group->getGUID();
$delete_button = elgg_view("output/confirmlink", array(
"href" => $url,
"confirm" => elgg_echo("group_tools:groups:membershipreq:invitations:revoke:confirm"),
"text" => elgg_echo("group_tools:revoke"),
"class" => "elgg-button elgg-button-delete mlm",
));

$body = "<h4>$email_title</h4>";

$content .= "<li class='pvs'>";
$content .= elgg_view_image_block("", $body, array("image_alt" => $delete_button));
$content .= "</li>";
}

$content .= "</ul>";
} else {
$content = "<p class='mtm'>" . elgg_echo("group_tools:groups:membershipreq:email_invitations:none") . "</p>";
}

echo elgg_view_module("info", $title, $content);

0 comments on commit 9ea9a71

Please sign in to comment.