FogBugz #135: add controller methods in preparation of sending birthday mails only in 7 days + 2 days in advance.

This commit is contained in:
Roland Jesse 2012-07-19 22:49:36 +02:00
parent 775917abef
commit cf32952cd1

View file

@ -3,7 +3,7 @@ class BirthdaysController < ApplicationController
before_filter :authenticate_user!, :except => [:do_mailing] before_filter :authenticate_user!, :except => [:do_mailing]
def index def index
@birthdays = get_next_weeks_birthdays @birthdays = get_birthdays_next_7d
@nav_active = "birthdays" @nav_active = "birthdays"
end end
@ -12,7 +12,7 @@ class BirthdaysController < ApplicationController
# crontab: # crontab:
# 30 3 * * * wget --post-data '' http://contact-o-rama.de/birthdays/do_mailing # 30 3 * * * wget --post-data '' http://contact-o-rama.de/birthdays/do_mailing
def do_mailing def do_mailing
birthdays = get_next_weeks_birthdays birthdays = get_birthdays_next_7d
logger.debug "birthdays.nil? = " + birthdays.nil?.to_s + "......" logger.debug "birthdays.nil? = " + birthdays.nil?.to_s + "......"
unless birthdays.nil? unless birthdays.nil?
birthdays_by_email = group_birthdays_by_email(birthdays) birthdays_by_email = group_birthdays_by_email(birthdays)
@ -37,11 +37,19 @@ class BirthdaysController < ApplicationController
private private
def get_next_weeks_birthdays def get_birthdays_next_7d
n = Date.today get_birthdays_next_n_days(7)
e = Date.today + 7.days end
# two cases here: now + 7days is still the same month. or it's not. def get_birthdays_next_2d
get_birthdays_next_n_days(2)
end
def get_birthdays_next_n_days(num_days)
n = Date.today
e = Date.today + num_days.days
# two cases here: now + x days is still the same month. or it's not.
if n.month == e.month if n.month == e.month
birthdays = Contact.where("birth_month = ? AND birth_day <= ? AND birth_day >= ?", birthdays = Contact.where("birth_month = ? AND birth_day <= ? AND birth_day >= ?",
e.month, e.day, n.day) e.month, e.day, n.day)