diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-06-27 22:52:50 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-06-27 22:52:50 +0200 |
| commit | 9a19a0494ef51cdac9a78e24d517ca48ba44c453 (patch) | |
| tree | 8eaae12d8047a40e29d3ea7ff3116b5c869e04bd /app/models/occurrence.rb | |
| parent | 85a01e35274b8d4d4165a7b26bd7986e211246bb (diff) | |
| parent | 1853082fcd8c067390c246f9daa01a9b47387497 (diff) | |
Migration from Rails 2.3.5 to Rails 8.1 successful.
Merging dev branch.
Diffstat (limited to 'app/models/occurrence.rb')
| -rw-r--r-- | app/models/occurrence.rb | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/app/models/occurrence.rb b/app/models/occurrence.rb index 591e1e0..3baf447 100644 --- a/app/models/occurrence.rb +++ b/app/models/occurrence.rb | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | # TODO Make a gem out of the c wrapper | 1 | # TODO Make a gem out of the c wrapper |
| 2 | require 'chaos_calendar' | 2 | require 'chaos_calendar' |
| 3 | 3 | ||
| 4 | class Occurrence < ActiveRecord::Base | 4 | class Occurrence < ApplicationRecord |
| 5 | 5 | ||
| 6 | # Associations | 6 | # Associations |
| 7 | 7 | ||
| @@ -11,29 +11,22 @@ class Occurrence < ActiveRecord::Base | |||
| 11 | # Class Methods | 11 | # Class Methods |
| 12 | 12 | ||
| 13 | def self.find_in_range start_time, end_time | 13 | def self.find_in_range start_time, end_time |
| 14 | find( | 14 | includes(:node) |
| 15 | :all, | 15 | .where("start_time > ? AND end_time < ?", start_time, end_time) |
| 16 | :include => :node, | 16 | .order("start_time") |
| 17 | :conditions => [ | ||
| 18 | "start_time > ? AND end_time < ?", start_time, end_time | ||
| 19 | ] | ||
| 20 | ) | ||
| 21 | end | 17 | end |
| 22 | 18 | ||
| 23 | def self.find_next | 19 | def self.find_next |
| 24 | find( | 20 | includes(:node) |
| 25 | :all, | 21 | .where("start_time > ?", Time.now) |
| 26 | :limit => 1, | 22 | .limit(1) |
| 27 | :include => :node, | ||
| 28 | :conditions => ["start_time > ?", Time.now] | ||
| 29 | ) | ||
| 30 | end | 23 | end |
| 31 | 24 | ||
| 32 | # Deletes all Occurrences which belong to the given event. Afterwards a few | 25 | # Deletes all Occurrences which belong to the given event. Afterwards a few |
| 33 | # variables are set to save repetitive queries. The occurrences of the given | 26 | # variables are set to save repetitive queries. The occurrences of the given |
| 34 | # event are then calculated and created. | 27 | # event are then calculated and created. |
| 35 | def self.generate event | 28 | def self.generate event |
| 36 | self.delete_all(:event_id => event.id) | 29 | self.where(:event_id => event.id).delete_all |
| 37 | 30 | ||
| 38 | node = event.node | 31 | node = event.node |
| 39 | duration = (event.end_time - event.start_time) | 32 | duration = (event.end_time - event.start_time) |
