diff options
| author | hukl <contact@smyck.org> | 2009-09-10 13:29:14 +0200 |
|---|---|---|
| committer | hukl <contact@smyck.org> | 2009-09-10 13:29:14 +0200 |
| commit | 8194cd82d7cb70c5b81bec8ee7a82b542c2570e9 (patch) | |
| tree | 19c8feba1043492ca191dfd04d58cd513d74fe06 | |
| parent | cc401c9bf20995bc4e02ba835847a7578e727d0c (diff) | |
show the next event if none are found for the next 14 days. Closes #19
| -rw-r--r-- | app/helpers/content_helper.rb | 5 | ||||
| -rw-r--r-- | app/models/occurrence.rb | 9 |
2 files changed, 14 insertions, 0 deletions
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 | |||
| 10 | 10 | ||
| 11 | def calendar | 11 | def calendar |
| 12 | occurrences = Occurrence.find_in_range(Time.now, (Time.now+14.days)) | 12 | occurrences = Occurrence.find_in_range(Time.now, (Time.now+14.days)) |
| 13 | |||
| 14 | if occurrences.empty? | ||
| 15 | occurrences = Occurrence.find_next | ||
| 16 | end | ||
| 17 | |||
| 13 | render( | 18 | render( |
| 14 | :partial => 'content/front_page_calendar', | 19 | :partial => 'content/front_page_calendar', |
| 15 | :locals => {:occurrences => occurrences} | 20 | :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 | |||
| 20 | ) | 20 | ) |
| 21 | end | 21 | end |
| 22 | 22 | ||
| 23 | def self.find_next | ||
| 24 | find( | ||
| 25 | :all, | ||
| 26 | :limit => 1, | ||
| 27 | :include => :node, | ||
| 28 | :conditions => ["start_time > ?", Time.now] | ||
| 29 | ) | ||
| 30 | end | ||
| 31 | |||
| 23 | # Deletes all Occurrences which belong to the given event. Afterwards a few | 32 | # Deletes all Occurrences which belong to the given event. Afterwards a few |
| 24 | # variables are set to save repetitive queries. The occurrences of the given | 33 | # variables are set to save repetitive queries. The occurrences of the given |
| 25 | # event are then calculated and created. | 34 | # event are then calculated and created. |
