Class: AvailableContentModule

Inherits:
ActiveRecord::Base
  • Object
show all
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

Class Method Details

.available_by(date) ⇒ Object



78
79
80
# File 'app/models/available_content_module.rb', line 78

def self.available_by(date)
  where(arel_table[:available_on].lteq(date))
end

.available_on(date) ⇒ Object



82
83
84
# File 'app/models/available_content_module.rb', line 82

def self.available_on(date)
  where available_on: date
end

.completedObject



29
30
31
# File 'app/models/available_content_module.rb', line 29

def self.completed
  where.not completed_at: nil
end

.didacticObject



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

def self.didactic
  where has_didactic_content: true
end

.excludes_module(content_module_or_id) ⇒ Object



86
87
88
# File 'app/models/available_content_module.rb', line 86

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



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/models/available_content_module.rb', line 45

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



13
14
15
# File 'app/models/available_content_module.rb', line 13

def self.for_participant(participant)
  where participant_id: participant.id
end

.for_past_weeks(membership) ⇒ Object



65
66
67
68
69
70
71
# File 'app/models/available_content_module.rb', line 65

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



17
18
19
# File 'app/models/available_content_module.rb', line 17

def self.for_tool(tool)
  where bit_core_tool_id: tool.id
end

.latest_duplicateObject

Note that this scope must appear at the end of a chain. Its SQL doesn’t play nicely with Arel.



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'app/models/available_content_module.rb', line 100

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

.non_visualizationObject



25
26
27
# File 'app/models/available_content_module.rb', line 25

def self.non_visualization
  where is_viz: false
end

.not_completedObject



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

def self.not_completed
  where completed_at: nil
end

.not_didacticObject



41
42
43
# File 'app/models/available_content_module.rb', line 41

def self.not_didactic
  where has_didactic_content: false
end

.not_terminated_on(date) ⇒ Object



73
74
75
76
# File 'app/models/available_content_module.rb', line 73

def self.not_terminated_on(date)
  where(arel_table[:terminates_on].eq(nil)
        .or(arel_table[:terminates_on].gteq(date)))
end

.order_by_position(direction = :asc) ⇒ Object



90
91
92
# File 'app/models/available_content_module.rb', line 90

def self.order_by_position(direction = :asc)
  order position: direction
end

.position_greater_than(position) ⇒ Object



94
95
96
# File 'app/models/available_content_module.rb', line 94

def self.position_greater_than(position)
  where(arel_table[:position].gt(position))
end

.terminated_on(date) ⇒ Object



61
62
63
# File 'app/models/available_content_module.rb', line 61

def self.terminated_on(date)
  where(arel_table[:terminates_on].lt(date))
end

.visualizationObject



21
22
23
# File 'app/models/available_content_module.rb', line 21

def self.visualization
  where is_viz: true
end