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
aggregate_of, all_except, defaults, #delete, #destroy!, 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
Class Method Details
.allowed_for(user, organization = Organization.current) ⇒ Object
59
60
61
|
# File 'app/models/course.rb', line 59
def self.allowed_for(user, organization = Organization.current)
where(organization: organization).select { |course| user.teacher_of? course.slug }
end
|
.sync_key_id_field ⇒ Object
47
48
49
|
# File 'app/models/course.rb', line 47
def self.sync_key_id_field
:slug
end
|
Instance Method Details
#closed? ⇒ Boolean
38
39
40
|
# File 'app/models/course.rb', line 38
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.now).first
end
|
#generate_invitation!(expiration_date) ⇒ Object
42
43
44
45
|
# File 'app/models/course.rb', line 42
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
|
#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
|
#to_organization ⇒ Object
51
52
53
|
# File 'app/models/course.rb', line 51
def to_organization
organization
end
|
#to_s ⇒ Object
55
56
57
|
# File 'app/models/course.rb', line 55
def to_s
slug.to_s
end
|