Class: Event

Inherits:
Sequel::Model
  • Object
show all
Defined in:
app/models/event.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.batch_delete(ids) ⇒ Object


24
25
26
# File 'app/models/event.rb', line 24

def self.batch_delete(ids)
  where(id: ids).update(deleted: true, applied_schedule_exception_ids: nil)
end

.with_person(username) ⇒ Object


15
16
17
18
# File 'app/models/event.rb', line 15

def self.with_person(username)
  filter(:teacher_ids.pg_array.contains([username]))
    .or(:student_ids.pg_array.contains([username]))
end

.with_teacher(username) ⇒ Object


20
21
22
# File 'app/models/event.rb', line 20

def self.with_teacher(username)
  filter(:teacher_ids.pg_array.contains([username]))
end

Instance Method Details

#move(offset) ⇒ Object


41
42
43
44
45
46
47
# File 'app/models/event.rb', line 41

def move(offset)
  offset_int = offset.to_i
  self.original_starts_at ||= self.starts_at
  self.original_ends_at ||= self.ends_at
  self.starts_at += offset_int.minutes
  self.ends_at += offset_int.minutes
end

#occupiedObject


37
38
39
# File 'app/models/event.rb', line 37

def occupied
  (student_ids || []).size
end

#periodObject


28
29
30
# File 'app/models/event.rb', line 28

def period
  Period.new(starts_at, ends_at)
end

#period=(new_period) ⇒ Object


32
33
34
35
# File 'app/models/event.rb', line 32

def period=(new_period)
  self.starts_at = new_period.starts_at
  self.ends_at = new_period.ends_at
end