Class: Bible270::DaysController

Inherits:
ApplicationController show all
Defined in:
app/controllers/bible270/days_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



5
6
7
8
9
10
11
12
# File 'app/controllers/bible270/days_controller.rb', line 5

def index
  @plan_totals = Plan.totals

  @start_day = current_reader&.current_day || 1
  # nil outside the plan's window, so no "Go to today" before it begins
  @today_day = current_reader&.today_day
  @community_start_date = Setting.run_start_date
end

#showObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/bible270/days_controller.rb', line 14

def show
  @day = params[:day].to_i
  redirect_to(root_path, alert: 'That day is outside the plan.') and return unless Plan.valid_day?(@day)

  @readings   = Plan.readings_for(@day)
  @comments   = Comment.threads_for_day(@day)
  @editing_comment_id = editing_comment_id
  @new_comment = Comment.new(day: @day, parent_id: reply_parent&.id)
  @reader_tracks = current_reader ? current_reader.read_tracks_for(@day) : []

  # Every box on the day, not every track: an Old Testament reading of three
  # chapters is three rows, so counting tracks would call someone finished
  # who had only read the Old Testament.
  required = Plan.total_parts(@day)
  completer_ids = Checkoff.where(day: @day)
    .group(:reader_id)
    .having('COUNT(*) >= ?', required)
    .pluck(:reader_id)
  @completers = Reader.where(id: completer_ids).order(:display_name)
end