summaryrefslogtreecommitdiff
path: root/app/models/occurrence.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/occurrence.rb')
-rw-r--r--app/models/occurrence.rb27
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
2require 'chaos_calendar' 2require 'chaos_calendar'
3 3
4class Occurrence < ActiveRecord::Base 4class 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)