elofgren: Clean up the code which enabled the 'Send to only people not previously sent to' feature committed in r38895

(merged from branches/gsoc)


git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@42002 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2007-09-16 01:03:04 +00:00
parent 24ed3ff68b
commit b784ccc5e7
2 changed files with 19 additions and 15 deletions

View File

@ -8,7 +8,12 @@ class NewsletterEmailProcess extends BatchProcess {
protected $nlType; protected $nlType;
protected $messageID; protected $messageID;
function __construct( $subject, $body, $from, $newsletter, $nlType, $messageID = null, $only_to_unsent = 0) { /**
* Set up a Newsletter Email Process
*
* @recipients A DataObject containing the addresses of the recipients of this newsletter
*/
function __construct( $subject, $body, $from, $newsletter, $nlType, $messageID = null, $recipients) {
$this->subject = $subject; $this->subject = $subject;
$this->body = $body; $this->body = $body;
@ -16,14 +21,8 @@ class NewsletterEmailProcess extends BatchProcess {
$this->newsletter = $newsletter; $this->newsletter = $newsletter;
$this->nlType = $nlType; $this->nlType = $nlType;
$this->messageID = $messageID; $this->messageID = $messageID;
$groupID = $nlType->GroupID; parent::__construct( $recipients );
// Allow sending to only those who have not already received it.
if (0 == $only_to_unsent) {
parent::__construct( DataObject::get( 'Member', "`GroupID`='$groupID'", null, "INNER JOIN `Group_Members` ON `MemberID`=`Member`.`ID`" ) );
} else {
parent::__construct( $newsletter->UnsentSubscribers() );
}
} }

View File

@ -440,12 +440,17 @@ class NewsletterAdmin extends LeftAndMain {
} }
break; break;
case "List": case "List":
echo self::sendToList( $subject, $body, $from, $newsletter, $nlType, $messageID ); // Send to the entire mailing list.
break; $groupID = $nlType->GroupID;
echo self::sendToList( $subject, $body, $from, $newsletter, $nlType, $messageID,
DataObject::get( 'Member', "`GroupID`='$groupID'", null, "INNER JOIN `Group_Members` ON `MemberID`=`Member`.`ID`" )
);
break;
case "Unsent": case "Unsent":
// Send to only those who have not already been sent this newsletter.
$only_to_unsent = 1; $only_to_unsent = 1;
echo self::sendToList( $subject, $body, $from, $newsletter, $nlType, $messageID, $only_to_unsent); echo self::sendToList( $subject, $body, $from, $newsletter, $nlType, $messageID, $newsletter->UnsentSubscribers());
break; break;
} }
return FormResponse::respond(); return FormResponse::respond();
@ -457,8 +462,8 @@ class NewsletterAdmin extends LeftAndMain {
$email->send(); $email->send();
} }
static function sendToList( $subject, $body, $from, $newsletter, $nlType, $messageID = null, $only_to_unsent = 0) { static function sendToList( $subject, $body, $from, $newsletter, $nlType, $messageID = null, $recipients) {
$emailProcess = new NewsletterEmailProcess( $subject, $body, $from, $newsletter, $nlType, $messageID, $only_to_unsent); $emailProcess = new NewsletterEmailProcess( $subject, $body, $from, $newsletter, $nlType, $messageID, $recipients);
return $emailProcess->start(); return $emailProcess->start();
} }