Class: AvailableContentModule
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- AvailableContentModule
- Defined in:
- app/models/available_content_module.rb
Overview
A read-only, view backed model that represents an assigned Content Module.
Class Method Summary collapse
- .available_by(date) ⇒ Object
- .available_on(date) ⇒ Object
- .excludes_module(content_module_or_id) ⇒ Object
- .for_current_week(membership) ⇒ Object
- .for_participant(participant) ⇒ Object
- .for_past_weeks(membership) ⇒ Object
- .for_tool(tool) ⇒ Object
- .is_completed ⇒ Object
- .is_didactic ⇒ Object
- .is_not_completed ⇒ Object
- .is_not_didactic ⇒ Object
- .is_not_terminated_on(date) ⇒ Object
- .is_not_viz ⇒ Object
- .is_terminated_on(date) ⇒ Object
- .is_viz ⇒ Object
-
.latest_duplicate ⇒ Object
Note that this scope must appear at the end of a chain.
- .order_by_position(direction = :asc) ⇒ Object
- .position_greater_than(position) ⇒ Object
Class Method Details
.available_by(date) ⇒ Object
74 75 76 |
# File 'app/models/available_content_module.rb', line 74 def self.available_by(date) where(arel_table[:available_on].lteq(date)) end |
.available_on(date) ⇒ Object
78 79 80 |
# File 'app/models/available_content_module.rb', line 78 def self.available_on(date) where available_on: date end |
.excludes_module(content_module_or_id) ⇒ Object
82 83 84 |
# File 'app/models/available_content_module.rb', line 82 def self.excludes_module(content_module_or_id) where.not(id: content_module_or_id.try(:id) || content_module_or_id) end |
.for_current_week(membership) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/models/available_content_module.rb', line 44 def self.for_current_week(membership) study_week_number = membership.week_in_study membership_start_date = membership.start_date available_on = arel_table[:available_on] for_participant(membership.participant) .where( available_on .lt(membership_start_date + study_week_number.weeks) .and( available_on .gteq(membership_start_date + (study_week_number - 1).weeks))) end |
.for_participant(participant) ⇒ Object
12 13 14 |
# File 'app/models/available_content_module.rb', line 12 def self.for_participant(participant) where participant_id: participant.id end |
.for_past_weeks(membership) ⇒ Object
62 63 64 65 66 67 |
# File 'app/models/available_content_module.rb', line 62 def self.for_past_weeks(membership) for_participant(membership.participant) .where( arel_table[:available_on] .lt(membership.start_date + (membership.week_in_study - 1).weeks)) end |
.for_tool(tool) ⇒ Object
16 17 18 |
# File 'app/models/available_content_module.rb', line 16 def self.for_tool(tool) where bit_core_tool_id: tool.id end |
.is_completed ⇒ Object
28 29 30 |
# File 'app/models/available_content_module.rb', line 28 def self.is_completed where.not completed_at: nil end |
.is_didactic ⇒ Object
36 37 38 |
# File 'app/models/available_content_module.rb', line 36 def self.is_didactic where has_didactic_content: true end |
.is_not_completed ⇒ Object
32 33 34 |
# File 'app/models/available_content_module.rb', line 32 def self.is_not_completed where completed_at: nil end |
.is_not_didactic ⇒ Object
40 41 42 |
# File 'app/models/available_content_module.rb', line 40 def self.is_not_didactic where has_didactic_content: false end |
.is_not_terminated_on(date) ⇒ Object
69 70 71 72 |
# File 'app/models/available_content_module.rb', line 69 def self.is_not_terminated_on(date) where(arel_table[:terminates_on].eq(nil) .or(arel_table[:terminates_on].gteq(date))) end |
.is_not_viz ⇒ Object
24 25 26 |
# File 'app/models/available_content_module.rb', line 24 def self.is_not_viz where is_viz: false end |
.is_terminated_on(date) ⇒ Object
58 59 60 |
# File 'app/models/available_content_module.rb', line 58 def self.is_terminated_on(date) where(arel_table[:terminates_on].lt(date)) end |
.is_viz ⇒ Object
20 21 22 |
# File 'app/models/available_content_module.rb', line 20 def self.is_viz where is_viz: true end |
.latest_duplicate ⇒ Object
Note that this scope must appear at the end of a chain. Its SQL doesn’t play nicely with Arel.
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'app/models/available_content_module.rb', line 96 def self.latest_duplicate select(" DISTINCT ON (has_didactic_content, bit_core_tool_id, is_viz, position, title, membership_id, participant_id) * ") .order(:has_didactic_content, :bit_core_tool_id, :is_viz, :position, :title, :membership_id, :participant_id, available_on: :desc) end |
.order_by_position(direction = :asc) ⇒ Object
86 87 88 |
# File 'app/models/available_content_module.rb', line 86 def self.order_by_position(direction = :asc) order position: direction end |
.position_greater_than(position) ⇒ Object
90 91 92 |
# File 'app/models/available_content_module.rb', line 90 def self.position_greater_than(position) where(arel_table[:position].gt(position)) end |