Class: Course
Class Method Summary
collapse
Instance Method Summary
collapse
#to_mumukit_grant, #to_mumukit_slug
#platform_class_name, #to_param
#platform_class_name, #sync_key
active_between, aggregate_of, all_except, defaults, #delete, #destroy!, enum_prefixed_translations_for, numbered, organic_on, resource_fields, #save, #save_and_notify!, #save_and_notify_changes!, serialize_symbolized_hash_array, teaser_on, #update_and_notify!, update_or_create!, whitelist_attributes, with_pg_retry, with_temporary_token
Methods included from WithPgLock
#with_pg_lock
Class Method Details
.allowed_for(user, organization = Organization.current) ⇒ Object
83
84
85
|
# File 'app/models/course.rb', line 83
def self.allowed_for(user, organization = Organization.current)
where(organization: organization).select { |course| user.teacher_of? course.slug }
end
|
.sync_key_id_field ⇒ Object
71
72
73
|
# File 'app/models/course.rb', line 71
def self.sync_key_id_field
:slug
end
|
Instance Method Details
#canonical_code ⇒ Object
58
59
60
|
# File 'app/models/course.rb', line 58
def canonical_code
"#{period}-#{code}".downcase
end
|
#closed? ⇒ Boolean
62
63
64
|
# File 'app/models/course.rb', line 62
def closed?
current_invitation.blank? || current_invitation.expired?
end
|
#current_invitation ⇒ Object
16
17
18
|
# File 'app/models/course.rb', line 16
def current_invitation
invitations.where('expiration_date > ?', Time.current).first
end
|
#ended? ⇒ Boolean
38
39
40
|
# File 'app/models/course.rb', line 38
def ended?
period_end.present? && period_end.past?
end
|
#generate_invitation!(expiration_date) ⇒ Object
66
67
68
69
|
# File 'app/models/course.rb', line 66
def generate_invitation!(expiration_date)
invitations.create expiration_date: expiration_date, course: self
current_invitation
end
|
#import_from_resource_h!(resource_h) ⇒ Object
20
21
22
|
# File 'app/models/course.rb', line 20
def import_from_resource_h!(resource_h)
update! self.class.slice_resource_h(resource_h)
end
|
#infer_period_range! ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
|
# File 'app/models/course.rb', line 46
def infer_period_range!
return if period_start || period_end
period =~ /^(\d{4})?/
year = $1.to_i
return nil unless year.between? 2014, (Time.current.year + 1)
self.period_start = DateTime.new(year).beginning_of_year
self.period_end = DateTime.new(year).end_of_year
end
|
#invite!(expiration_date) ⇒ Object
30
31
32
33
34
35
36
|
# File 'app/models/course.rb', line 30
def invite!(expiration_date)
if closed?
generate_invitation! expiration_date
else
current_invitation
end
end
|
#slug=(slug) ⇒ Object
24
25
26
27
28
|
# File 'app/models/course.rb', line 24
def slug=(slug)
s = slug.to_mumukit_slug
self[:slug] = slug.to_s
self[:organization_id] = Organization.locate!(s.organization).id
end
|
#started? ⇒ Boolean
42
43
44
|
# File 'app/models/course.rb', line 42
def started?
period_start.present? && period_start.past?
end
|
#to_organization ⇒ Object
75
76
77
|
# File 'app/models/course.rb', line 75
def to_organization
organization
end
|
#to_s ⇒ Object
79
80
81
|
# File 'app/models/course.rb', line 79
def to_s
slug.to_s
end
|