From cde696c76755e880a13d8e6789a9d9f3f00b94c5 Mon Sep 17 00:00:00 2001 From: Frank Dillon Date: Mon, 22 Sep 2008 22:26:59 +0000 Subject: [PATCH] Added isAdHocMailGroup flag which can be used to build temporary groups of users to send notifications to. Once the users have been added to the mail queue in WebGUI::Mail::send, the group is deleted. --- docs/upgrades/upgrade_7.5.21-7.6.0.pl | 8 +++ lib/WebGUI/Group.pm | 71 +++++++++++++++++++++++++++ lib/WebGUI/Mail/Send.pm | 5 +- 3 files changed, 82 insertions(+), 2 deletions(-) diff --git a/docs/upgrades/upgrade_7.5.21-7.6.0.pl b/docs/upgrades/upgrade_7.5.21-7.6.0.pl index 7608d7049..e3f292c66 100644 --- a/docs/upgrades/upgrade_7.5.21-7.6.0.pl +++ b/docs/upgrades/upgrade_7.5.21-7.6.0.pl @@ -37,6 +37,7 @@ addEMSBadgeTemplate ( $session ); redirectChoice ($session); badgePriceDates ($session); addIsDefaultTemplates( $session ); +addAdHocMailGroups( $session ); finish($session); # this line required @@ -225,6 +226,13 @@ sub redirectChoice { print "DONE!\n" unless $quiet; } +#---------------------------------------------------------------------------- +sub addAdHocMailGroups { + my $session = shift; + print "\tAdding AdHocMailGroups to Groups.. " unless $quiet; + $session->db->write("alter table groups add column isAdHocMailGroup tinyint(4) not null default 0"); + print "DONE!\n" unless $quiet; +} # -------------- DO NOT EDIT BELOW THIS LINE -------------------------------- diff --git a/lib/WebGUI/Group.pm b/lib/WebGUI/Group.pm index 80bc209d0..a4da349de 100755 --- a/lib/WebGUI/Group.pm +++ b/lib/WebGUI/Group.pm @@ -103,6 +103,7 @@ sub _defaults { autoDelete=>0, isEditable=>1, showInForms=>1, + isAdHocMailGroup=>0, }; } @@ -877,6 +878,55 @@ sub getUsers { return \@users; } +#------------------------------------------------------------------- + +=head2 getUsersNotIn ( group [,withoutExpired]) + +Returns an array reference containing a list of all of the users that are in this group +and are not in the group passed in + +=head3 groupId + +groupId to check the users in this group against. + +=head3 withoutExpired + +A boolean that if set to true will return only the groups that the user is in where +their membership hasn't expired. + +=cut + +sub getUsersNotIn { + my $self = shift; + my $groupId = shift; + my $withoutExpired = shift; + + if($groupId eq "") { + return $self->getUsers($withoutExpired); + } + + my $expireTime = 0; + if ($withoutExpired) { + $expireTime = $self->session->datetime->time(); + } + + my $sql = q{ + select + userId + from + groupings + where + expireDate > ? + and groupId=? + and userId not in (select userId from groupings where expireDate > ? and groupId=?) + }; + + my @users = $self->session->db->buildArray($sql, [$expireTime,$self->getId,$expireTime,$self->getId]); + return \@users; + +} + + #------------------------------------------------------------------- @@ -899,6 +949,27 @@ sub karmaThreshold { return $self->get("karmaThreshold"); } +#------------------------------------------------------------------- + +=head2 isAdHocMailGroup ( [ value ] ) + +Returns a boolean value indicating whether the group is flagged as an AdHoc Mail Group or not. +AdHoc Mail Groups are automatically deleted once the mail they are associated to has been sent. + +=head3 value + +If specified, isAdHocMailGroup is set to this value. + +=cut + +sub isAdHocMailGroup { + my $self = shift; + my $value = shift; + if (defined $value) { + $self->set("isAdHocMailGroup",$value); + } + return $self->get("isAdHocMailGroup"); +} #------------------------------------------------------------------- diff --git a/lib/WebGUI/Mail/Send.pm b/lib/WebGUI/Mail/Send.pm index 3d4ac0027..e7ad886ea 100644 --- a/lib/WebGUI/Mail/Send.pm +++ b/lib/WebGUI/Mail/Send.pm @@ -489,8 +489,7 @@ sub send { delete $self->{_toGroup}; if ($group) { my $group = WebGUI::Group->new($self->session, $group); - return $status - if !defined $group; + return $status if !defined $group; $mail->head->replace("bcc", undef); $mail->head->replace("cc", undef); foreach my $userId (@{$group->getAllUsers(1)}) { @@ -501,6 +500,8 @@ sub send { $self->queue; } } + #Delete the group if it is flagged as an AdHocMailGroup + $group->delete if ($group->isAdHocMailGroup); } return $status;