From cf5c45cb34bb6c1f00cc44939571cbaeaefd6f04 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Mon, 11 Dec 2017 16:44:23 +0800 Subject: [PATCH] added filter start and end date options --- .../announcement_feeds_controller.rb | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/app/controllers/announcement_feeds_controller.rb b/app/controllers/announcement_feeds_controller.rb index d116786..7073277 100644 --- a/app/controllers/announcement_feeds_controller.rb +++ b/app/controllers/announcement_feeds_controller.rb @@ -65,10 +65,27 @@ class AnnouncementFeedsController < ApplicationController def get_announcements(uid) bf = BulletinFeed.find_by(:uid => uid) rescue nil + startdt = params[:start] + enddt = params[:end] + dt = params[:date] if !bf.nil? tags = bf.tag_ids if !tags.empty? - announcements = Bulletin.all.can_display.is_approved.filter_by_tags(tags) + if !dt.nil? + dt = DateTime.parse(dt) + dtt = dt + 1.day + announcements = Bulletin.where(:postdate.gt => dt, :postdate.lt => dtt).can_display.is_approved.filter_by_tags(tags) + elsif !startdt.nil? && enddt.nil? + startdt = DateTime.parse(startdt) + enddt = DateTime.now + announcements = Bulletin.where(:postdate.gt => startdt, :postdate.lt => enddt).can_display.is_approved.filter_by_tags(tags) + elsif !startdt.nil? && !enddt.nil? + startdt = DateTime.parse(startdt) + enddt = DateTime.parse(enddt) + 1.day + announcements = Bulletin.where(:postdate.gt => startdt, :postdate.lt => enddt).can_display.is_approved.filter_by_tags(tags) + else + announcements = Bulletin.all.can_display.is_approved.filter_by_tags(tags) + end else announcements = [] end