Skip to content

Instantly share code, notes, and snippets.

@alexeydemin
Last active March 2, 2017 05:59
Show Gist options
  • Save alexeydemin/9c74562caea98d7c26da8a4516bb0186 to your computer and use it in GitHub Desktop.
Save alexeydemin/9c74562caea98d7c26da8a4516bb0186 to your computer and use it in GitHub Desktop.
SendNewsletter extends Command {
function __construct( NewsletterSender $sender )
{
$this->sender = $sender;
}
function execute()
{
$recurring = RecurringSubscription::getEmails();
$single = SingleSubscription::getEmails();
$this->sender->send($recurring);
$this->sender->send($single);
}
}
--------------------------------------------------------
class NewsletterSender{
function __construct( RealSender $sender )
{
$this->sender = $sender;
}
function send( Illuminate\Support\Collection $subscriptions )
{
foreach( $subscriptions as $subscription ){
$email = new Email();
$email->to = $subscription->contact->email; // $email->generateTo($subscription->contact)
$email->subject = $subscription->template->getSubject();
$email->content = $subscription->template->getContent();
$this->sender->queue($email);
}
}
}
--------------------------------------------------------
class RecurringSubscription extends Eloquent //implements Subscription {
function getEmails()
{
...
return self::where( DB::raw('MOD(TO_DAYS( NOW()), period) = 0') );
// or use create_at if date of first email is important
}
}
---------------------------------------------------------
class SingleSubscription extends Eloquent //implements Subscription {
function getEmails()
{
...
return self::where('date', $today);
}
}
@alexeydemin
Copy link
Author

diagram

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment