FogBugz #135: add controller methods in preparation of sending birthday mails only in 7 days + 2 days in advance.
This commit is contained in:
parent
775917abef
commit
cf32952cd1
1 changed files with 14 additions and 6 deletions
|
|
@ -3,7 +3,7 @@ class BirthdaysController < ApplicationController
|
|||
before_filter :authenticate_user!, :except => [:do_mailing]
|
||||
|
||||
def index
|
||||
@birthdays = get_next_weeks_birthdays
|
||||
@birthdays = get_birthdays_next_7d
|
||||
@nav_active = "birthdays"
|
||||
end
|
||||
|
||||
|
|
@ -12,7 +12,7 @@ class BirthdaysController < ApplicationController
|
|||
# crontab:
|
||||
# 30 3 * * * wget --post-data '' http://contact-o-rama.de/birthdays/do_mailing
|
||||
def do_mailing
|
||||
birthdays = get_next_weeks_birthdays
|
||||
birthdays = get_birthdays_next_7d
|
||||
logger.debug "birthdays.nil? = " + birthdays.nil?.to_s + "......"
|
||||
unless birthdays.nil?
|
||||
birthdays_by_email = group_birthdays_by_email(birthdays)
|
||||
|
|
@ -37,11 +37,19 @@ class BirthdaysController < ApplicationController
|
|||
|
||||
private
|
||||
|
||||
def get_next_weeks_birthdays
|
||||
def get_birthdays_next_7d
|
||||
get_birthdays_next_n_days(7)
|
||||
end
|
||||
|
||||
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 + 7.days
|
||||
e = Date.today + num_days.days
|
||||
|
||||
# two cases here: now + 7days is still the same month. or it's not.
|
||||
# two cases here: now + x days is still the same month. or it's not.
|
||||
if n.month == e.month
|
||||
birthdays = Contact.where("birth_month = ? AND birth_day <= ? AND birth_day >= ?",
|
||||
e.month, e.day, n.day)
|
||||
|
|
@ -49,7 +57,7 @@ class BirthdaysController < ApplicationController
|
|||
birthdays = Contact.where("(birth_month = ? AND birth_day <= ?) OR (birth_month = ? AND birth_day >= ?)",
|
||||
e.month, e.day, n.month, n.day)
|
||||
end
|
||||
birthdays
|
||||
birthdays
|
||||
end
|
||||
|
||||
# in: Array [contact,contact,contact,...]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue