From bba347331f24ec217d61b8dfb74c88c58d278189 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Sun, 16 Sep 2007 02:16:47 +0000 Subject: [PATCH] elofgren: Make it so that if red (X) link next to an Email on the Bounced Tab of a Mailing List is clicked, the Email_BounceRecord will be deleted and the Member will be removed from the Mailing List group. @TODO Reload whole right frame so that Recipients and Bounced tabs will be updated after bounced member is removed. (merged from branches/gsoc) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@42037 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- code/Newsletter/BouncedList.php | 37 +++++++-- code/NewsletterAdmin.php | 33 +++++++- .../Includes/NewsletterAdmin_BouncedList.ss | 79 +++++++++++++------ 3 files changed, 117 insertions(+), 32 deletions(-) diff --git a/code/Newsletter/BouncedList.php b/code/Newsletter/BouncedList.php index 38da33e9..fe516903 100755 --- a/code/Newsletter/BouncedList.php +++ b/code/Newsletter/BouncedList.php @@ -19,8 +19,36 @@ class BouncedList extends TableListField { function sourceItems() { $id = $this->nlType->GroupID; - // @TODO Try to find way to show Firstname and Surname under a 'Username' heading - return DataObject::get( 'Email_BounceRecord', "`GroupID`='$id'", null, "INNER JOIN `Group_Members` USING(`MemberID`)" ); + // @TODO Try to find way to show Firstname and Surname under a 'Username' heading"; + // Get a list of all bounces for all subscribers to this mailing list + $bouncedSubscribers = DataObject::get( 'Email_BounceRecord', "`GroupID`='$id'", null, "INNER JOIN `Group_Members` USING(`MemberID`)" ); + + // @TODO Find faster/elegenter way to do this. Probably some sort of SQL JOIN would work instead + // If there are bounces logged for this Mailing List + if ($bouncedSubscribers) { + $bouncedSubscribersWithMemberID = new DataObjectSet(); + // Convert bounce to array so we can easily iterate through them + $bouncedSubscribersArray = $bouncedSubscribers->toArray(); + // Iterate through each bounce record and add 'GroupID' to it (this is clumsy) + foreach($bouncedSubscribersArray as $key => $bouncedSubscriberObject) + { + $bouncedSubscriberArray = $bouncedSubscriberObject->getAllFields(); + // Add MemberID to DataObjectSet so the removebouncedmember link will work + $bouncedSubscriberArray['GroupID'] = $id; + $bouncedSubscribersWithMemberID->push(new ArrayData($bouncedSubscriberArray)); + } + return $bouncedSubscribersWithMemberID; + } else { + return null; + } + + } + + /** + * Sets the template to be rendered with + */ + function FieldHolder() { + return $this->renderWith('NewsletterAdmin_BouncedList'); } function setController($controller) { @@ -28,12 +56,7 @@ class BouncedList extends TableListField { } // Not needed now that we are extending TableListField instead of FormField - // @TODO Remove NewsletterAdmin_BouncedList.ss after copying out any needed bits /* - function FieldHolder() { - return $this->renderWith( 'NewsletterAdmin_BouncedList' ); - } - function Entries() { $id = $this->nlType->GroupID; diff --git a/code/NewsletterAdmin.php b/code/NewsletterAdmin.php index 705102f2..e6f7c7e4 100755 --- a/code/NewsletterAdmin.php +++ b/code/NewsletterAdmin.php @@ -291,7 +291,7 @@ class NewsletterAdmin extends LeftAndMain { $unsubscribedList = new UnsubscribedList("Unsubscribed", $mailType) ), new Tab("Bounced", - new LiteralField('Instructions', '

Instructions:

'), + new LiteralField('Instructions', '

Instructions:

'), $bouncedList = new BouncedList("Bounced", $mailType ) ) ) @@ -323,6 +323,37 @@ class NewsletterAdmin extends LeftAndMain { } + /** + * Removes a bounced member from the mailing list + * + * @return String + */ + function removebouncedmember($urlParams) { + // First remove the Bounce entry + $memberID = Convert::raw2sql($urlParams['ID']); + if (is_numeric($memberID)) { + $bounceObject = DataObject::get_by_id('Email_BounceRecord', $memberID); + if($bounceObject) { + // Remove this bounce record + $bounceObject->delete(); + + $memberObject = DataObject::get_by_id('Member', $bounceObject->MemberID); + $groupID = Convert::raw2sql($_REQUEST['GroupID']); + if(is_numeric($groupID) && is_object($memberObject)) { + // Remove the member from the mailing list + $memberObject->Groups()->remove($groupID); + } else { + user_error("MemberTableField::delete: Bad parameters: Group=$groupID, Member=$memberID", E_USER_ERROR); + } + // @TODO Reload whole right frame so that Recipients and Bounced tabs will be updated after bounced member is removed. + return 1; + } + }else{ + return 0; + } + } + + /** * Reloads the list of recipients via ajax */ diff --git a/templates/Includes/NewsletterAdmin_BouncedList.ss b/templates/Includes/NewsletterAdmin_BouncedList.ss index 38199653..6f105bb7 100755 --- a/templates/Includes/NewsletterAdmin_BouncedList.ss +++ b/templates/Includes/NewsletterAdmin_BouncedList.ss @@ -1,24 +1,55 @@ -<% if Entries %> - - - - - - - - - - - <% control Entries %> - - - - - - - <% end_control %> - -
User nameEmail addressReason:Last bounce at
$Member.FirstName $Member.Surname$Member.Email$Record.BounceMessage$Record.Created.Long
-<% else %> -

No emails sent have bounced.

-<% end_if %> +
+ <% include TableListField_PageControls %> + + + + <% if Markable %><% end_if %> + <% control Headings %> + + <% end_control %> + <% if Can(delete) %><% end_if %> + + + + <% if HasSummary %> + + + <% if Markable %><% end_if %> + + <% control SummaryFields %> + class="$Function"<% end_if %>>  + <% end_control %> + <% if Can(delete) %><% end_if %> + + + <% end_if %> + + + <% if Items %> + <% control Items %> + class="$HighlightClasses"<% end_if %>> + <% if Markable %><% end_if %> + <% control Fields %> + + <% end_control %> + <% if Can(delete) %> + + <% end_if %> + + <% end_control %> + <% else %> + + <% if Markable %><% end_if %> + + <% if Can(delete) %><% end_if %> + + <% end_if %> + <% if Can(add) %>$AddRecordForm.AsTableRow<% end_if %> + +
 $Title 
 $SummaryTitle 
$MarkingCheckbox$Valuedelete
 No bounce records found 
+
+ <% if Can(export) %> + $ExportButton + <% end_if %> +
+
\ No newline at end of file