Sha256: 62dccc40ba8c3f31e693e5bfb8c7ff10cb74ce60c8fa3cb72954282e0fbbdfbf

Contents?: true

Size: 1.61 KB

Versions: 55

Compression:

Stored size: 1.61 KB

Contents

module ContentProviders
  # Provides a view of current learning tools: videos and lessons
  class LearnLessonsIndexProvider < BitCore::ContentProvider
    DAYS_IN_WEEK = 7

    def render_current(options)
      membership = options.participant.active_membership

      options.view_context.render(
        template: "think_feel_do_engine/learn/lessons_index",
        locals: {
          weekly_tasks: weekly_tasks(options.participant,
                                     membership,
                                     options.app_context),
          week_in_study: membership.week_in_study,
          tool: content_module.tool
        }
      )
    end

    def show_nav_link?
      false
    end

    private

    def weekly_tasks(participant, membership, app_context)
      all_tasks = participant.learning_tasks(content_modules(app_context))
                  .includes(task: :bit_core_content_module)
                  .order("bit_core_content_modules.position")

      (1..week_count).map do |week|
        {
          date: membership.start_date + (week - 1) * DAYS_IN_WEEK,
          week: week,
          tasks: all_tasks
            .where(all_tasks.arel_table[:start_day]
                   .gt((week - 1) * DAYS_IN_WEEK))
            .where(all_tasks.arel_table[:start_day]
                   .lteq(week * DAYS_IN_WEEK))
        }
      end
    end

    def content_modules(app_context)
      ContentModules::LessonModule.joins(:tool)
        .where("bit_core_tools.title" => app_context)
        .where.not(id: bit_core_content_module_id)
    end

    def week_count
      Rails.application.config.lesson_week_length
    end
  end
end

Version data entries

55 entries across 55 versions & 1 rubygems

Version Path
think_feel_do_engine-3.19.9 app/models/content_providers/learn_lessons_index_provider.rb
think_feel_do_engine-3.19.8 app/models/content_providers/learn_lessons_index_provider.rb
think_feel_do_engine-3.19.7 app/models/content_providers/learn_lessons_index_provider.rb
think_feel_do_engine-3.19.6 app/models/content_providers/learn_lessons_index_provider.rb
think_feel_do_engine-3.19.5 app/models/content_providers/learn_lessons_index_provider.rb
think_feel_do_engine-3.19.4 app/models/content_providers/learn_lessons_index_provider.rb
think_feel_do_engine-3.19.3 app/models/content_providers/learn_lessons_index_provider.rb
think_feel_do_engine-3.19.2 app/models/content_providers/learn_lessons_index_provider.rb
think_feel_do_engine-3.19.1 app/models/content_providers/learn_lessons_index_provider.rb
think_feel_do_engine-3.19.0 app/models/content_providers/learn_lessons_index_provider.rb
think_feel_do_engine-3.18.0 app/models/content_providers/learn_lessons_index_provider.rb
think_feel_do_engine-3.17.2 app/models/content_providers/learn_lessons_index_provider.rb
think_feel_do_engine-3.17.1 app/models/content_providers/learn_lessons_index_provider.rb
think_feel_do_engine-3.17.0 app/models/content_providers/learn_lessons_index_provider.rb
think_feel_do_engine-3.16.3 app/models/content_providers/learn_lessons_index_provider.rb
think_feel_do_engine-3.16.2 app/models/content_providers/learn_lessons_index_provider.rb
think_feel_do_engine-3.16.1 app/models/content_providers/learn_lessons_index_provider.rb
think_feel_do_engine-3.15.7 app/models/content_providers/learn_lessons_index_provider.rb
think_feel_do_engine-3.16.0 app/models/content_providers/learn_lessons_index_provider.rb
think_feel_do_engine-3.15.6 app/models/content_providers/learn_lessons_index_provider.rb