From 8194cd82d7cb70c5b81bec8ee7a82b542c2570e9 Mon Sep 17 00:00:00 2001 From: hukl Date: Thu, 10 Sep 2009 13:29:14 +0200 Subject: show the next event if none are found for the next 14 days. Closes #19 --- app/helpers/content_helper.rb | 5 +++++ app/models/occurrence.rb | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/app/helpers/content_helper.rb b/app/helpers/content_helper.rb index 5a288ed..c85fcf5 100644 --- a/app/helpers/content_helper.rb +++ b/app/helpers/content_helper.rb @@ -10,6 +10,11 @@ module ContentHelper def calendar occurrences = Occurrence.find_in_range(Time.now, (Time.now+14.days)) + + if occurrences.empty? + occurrences = Occurrence.find_next + end + render( :partial => 'content/front_page_calendar', :locals => {:occurrences => occurrences} diff --git a/app/models/occurrence.rb b/app/models/occurrence.rb index 667ba6f..591e1e0 100644 --- a/app/models/occurrence.rb +++ b/app/models/occurrence.rb @@ -20,6 +20,15 @@ class Occurrence < ActiveRecord::Base ) end + def self.find_next + find( + :all, + :limit => 1, + :include => :node, + :conditions => ["start_time > ?", Time.now] + ) + end + # Deletes all Occurrences which belong to the given event. Afterwards a few # variables are set to save repetitive queries. The occurrences of the given # event are then calculated and created. -- cgit v1.3