From 60f1368c1ea73919ef3b2d023839220031ebe697 Mon Sep 17 00:00:00 2001 From: Roland Jesse Date: Thu, 19 Jul 2012 23:22:01 +0200 Subject: [PATCH] FogBugz #135: completed controller methods in preparation of sending birthday mails only in 7 days + 2 days in advance. --- app/controllers/birthdays_controller.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/controllers/birthdays_controller.rb b/app/controllers/birthdays_controller.rb index fb9be8d..ada8769 100644 --- a/app/controllers/birthdays_controller.rb +++ b/app/controllers/birthdays_controller.rb @@ -3,7 +3,7 @@ class BirthdaysController < ApplicationController before_filter :authenticate_user!, :except => [:do_mailing] def index - @birthdays = get_birthdays_next_7d + @birthdays = get_birthdays_in_2d # get_birthdays_next_7d @nav_active = "birthdays" end @@ -45,6 +45,14 @@ class BirthdaysController < ApplicationController get_birthdays_next_n_days(2) end + def get_birthdays_in_7d + get_birthdays_in_n_days(7) + end + + def get_birthdays_in_2d + get_birthdays_in_n_days(2) + end + def get_birthdays_next_n_days(num_days) n = Date.today e = Date.today + num_days.days @@ -60,6 +68,11 @@ class BirthdaysController < ApplicationController birthdays end + def get_birthdays_in_n_days(num_days) + target_date = Date.today + num_days.days + birthdays = Contact.where("birth_month = ? AND birth_day = ?", target_date.month, target_date.day) + end + # in: Array [contact,contact,contact,...] # out: Hash[email] = [contact,contact,contact,....] def group_birthdays_by_email(birthday_contacts)