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
This commit is contained in:
Ingo Schommer 2007-09-16 02:16:47 +00:00
parent e28baf03db
commit bba347331f
3 changed files with 117 additions and 32 deletions

View File

@ -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;

View File

@ -291,7 +291,7 @@ class NewsletterAdmin extends LeftAndMain {
$unsubscribedList = new UnsubscribedList("Unsubscribed", $mailType)
),
new Tab("Bounced",
new LiteralField('Instructions', '<p><b>Instructions:</b></p><ul><li>Uncheck the box and click the "Save" button to disable sending to an email address.</li><li>To delete an email address from your mailing list, click the red "X" icon.</li></ul>'),
new LiteralField('Instructions', '<p><b>Instructions:</b></p><ul><li>Uncheck the box and click the "Save" button to disable sending to an email address. <b>@TODO Make this functional</b></li><li>To remove a recipients\'s email address from your mailing list, click the red "X" icon.</li></ul>'),
$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
*/

View File

@ -1,24 +1,55 @@
<% if Entries %>
<table class="CMSList BouncedList" summary="Emails that have bounced">
<div id="$id" class="$Classes TableField">
<% include TableListField_PageControls %>
<table class="data BouncedList">
<thead>
<tr>
<th>User name</th>
<th>Email address</th>
<th>Reason:</th>
<th>Last bounce at</th>
<% if Markable %><th width="16">&nbsp;</th><% end_if %>
<% control Headings %>
<th class="$Name">$Title</th>
<% end_control %>
<% if Can(delete) %><th width="18">&nbsp;</th><% end_if %>
</tr>
</thead>
<% if HasSummary %>
<tfoot>
<tr class="summary">
<% if Markable %><th width="16">&nbsp;</th><% end_if %>
<td><i>$SummaryTitle</i></td>
<% control SummaryFields %>
<td<% if Function %> class="$Function"<% end_if %>>&nbsp;</td>
<% end_control %>
<% if Can(delete) %><td width="18">&nbsp;</td><% end_if %>
</tr>
</tfoot>
<% end_if %>
<tbody>
<% control Entries %>
<tr>
<td>$Member.FirstName $Member.Surname</td>
<td>$Member.Email</td>
<td>$Record.BounceMessage</td>
<td>$Record.Created.Long</td>
<% if Items %>
<% control Items %>
<tr id="record-$ID"<% if HighlightClasses %> class="$HighlightClasses"<% end_if %>>
<% if Markable %><td width="16">$MarkingCheckbox</td><% end_if %>
<% control Fields %>
<td>$Value</td>
<% end_control %>
<% if Can(delete) %>
<td width="16"><a class="deletelink" href="admin/newsletter/removebouncedmember/$ID/?GroupID=$GroupID"><img src="cms/images/delete.gif" alt="delete" /></a></td>
<% end_if %>
</tr>
<% end_control %>
<% else %>
<tr class="notfound">
<% if Markable %><th width="18">&nbsp;</th><% end_if %>
<td colspan="$Headings.Count"><i>No bounce records found</i></td>
<% if Can(delete) %><td width="18">&nbsp;</td><% end_if %>
</tr>
<% end_if %>
<% if Can(add) %>$AddRecordForm.AsTableRow<% end_if %>
</tbody>
</table>
<% else %>
<p>No emails sent have bounced.</p>
<% end_if %>
</table>
<div class="utility">
<% if Can(export) %>
$ExportButton
<% end_if %>
</div>
</div>