function next($count = 10) { $max = $this->current + $count; $max = $max < count($this->objects) ? $max : count($this->objects); while ($this->current < $max) { $index = $this->current++; $member = $this->objects[$index]; // check to see if the user has unsubscribed from the mailing list // TODO Join in the above query first $unsubscribeRecord = DataObject::get_one('Member_UnsubscribeRecord', "`MemberID`='{$member->ID}' AND `NewsletterTypeID`='{$this->nlType->ID}'"); if (!$unsubscribeRecord) { $address = $member->Email; /** * Email Blacklisting Support */ if ($member->BlacklistedEmail && Email_BlackList::isBlocked($address)) { $bounceRecord = new Email_BounceRecord(); $bounceRecord->BounceEmail = $member->Email; $bounceRecord->BounceTime = date("Y-m-d H:i:s", time()); $bounceRecord->BounceMessage = "BlackListed Email"; $bounceRecord->MemberID = $member->ID; $bounceRecord->write(); // Log the blacklist for this specific Newsletter $newsletter = new Newsletter_SentRecipient(); $newsletter->Email = $address; $newsletter->MemberID = $member->ID; $newsletter->Result = 'BlackListed'; $newsletter->ParentID = $this->newsletter->ID; $newsletter->write(); } else { $e = new Newsletter_Email($this->nlType); $e->setBody($this->body); $e->setSubject($this->subject); $e->setFrom($this->from); $e->setTemplate($this->nlType->Template); if (method_exists($member, "getNameForEmail")) { $nameForEmail = $member->getNameForEmail(); } $e->populateTemplate(array('Member' => $member, 'FirstName' => $member->FirstName, 'NameForEmail' => $nameForEmail)); $this->sendToAddress($e, $address, $this->messageID, $member); } } } if ($this->current >= count($this->objects)) { return $this->complete(); } else { return parent::next(); } }
/** * Add the members email address to the blacklist * * With this method the blacklisted email table is updated to ensure that * no promotional material is sent to the member (newsletters). * Standard system messages are still sent such as receipts. * * @param bool $val Set to TRUE if the address should be added to the * blacklist, otherwise to FALSE. */ function setBlacklistedEmail($val) { if ($val && $this->Email) { $blacklisting = new Email_BlackList(); $blacklisting->BlockedEmail = $this->Email; $blacklisting->MemberID = $this->ID; $blacklisting->write(); } $this->setField("BlacklistedEmail", $val); // Save the BlacklistedEmail field to the Member table $this->write(); }