mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-10-22 11:05:53 +02:00
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:
parent
e28baf03db
commit
bba347331f
@ -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;
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -1,24 +1,55 @@
|
||||
<% if Entries %>
|
||||
<table class="CMSList BouncedList" summary="Emails that have bounced">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>User name</th>
|
||||
<th>Email address</th>
|
||||
<th>Reason:</th>
|
||||
<th>Last bounce at</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% control Entries %>
|
||||
<tr>
|
||||
<td>$Member.FirstName $Member.Surname</td>
|
||||
<td>$Member.Email</td>
|
||||
<td>$Record.BounceMessage</td>
|
||||
<td>$Record.Created.Long</td>
|
||||
</tr>
|
||||
<% end_control %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% else %>
|
||||
<p>No emails sent have bounced.</p>
|
||||
<% end_if %>
|
||||
<div id="$id" class="$Classes TableField">
|
||||
<% include TableListField_PageControls %>
|
||||
<table class="data BouncedList">
|
||||
<thead>
|
||||
<tr>
|
||||
<% if Markable %><th width="16"> </th><% end_if %>
|
||||
<% control Headings %>
|
||||
<th class="$Name">$Title</th>
|
||||
<% end_control %>
|
||||
<% if Can(delete) %><th width="18"> </th><% end_if %>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<% if HasSummary %>
|
||||
<tfoot>
|
||||
<tr class="summary">
|
||||
<% if Markable %><th width="16"> </th><% end_if %>
|
||||
<td><i>$SummaryTitle</i></td>
|
||||
<% control SummaryFields %>
|
||||
<td<% if Function %> class="$Function"<% end_if %>> </td>
|
||||
<% end_control %>
|
||||
<% if Can(delete) %><td width="18"> </td><% end_if %>
|
||||
</tr>
|
||||
</tfoot>
|
||||
<% end_if %>
|
||||
|
||||
<tbody>
|
||||
<% 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"> </th><% end_if %>
|
||||
<td colspan="$Headings.Count"><i>No bounce records found</i></td>
|
||||
<% if Can(delete) %><td width="18"> </td><% end_if %>
|
||||
</tr>
|
||||
<% end_if %>
|
||||
<% if Can(add) %>$AddRecordForm.AsTableRow<% end_if %>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="utility">
|
||||
<% if Can(export) %>
|
||||
$ExportButton
|
||||
<% end_if %>
|
||||
</div>
|
||||
</div>
|
Loading…
Reference in New Issue
Block a user