added filter start and end date options

This commit is contained in:
Harry Bomrah 2017-12-11 16:44:23 +08:00
parent 30687d655f
commit cf5c45cb34
1 changed files with 18 additions and 1 deletions

View File

@ -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?
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