instructors_controller.rb 745 Bytes
Newer Older
Zac Wood's avatar
Zac Wood committed
1
class InstructorsController < ApplicationController
2 3
  before_action :set_instructor, only: [:show]

Zac Wood's avatar
Zac Wood committed
4
  def index
5
    @instructors = Instructor.all
Zac Wood's avatar
Zac Wood committed
6 7 8
  end

  def show
9
    sections = CourseSection.where instructor: @instructor
Zac Wood's avatar
Zac Wood committed
10 11 12
    sections = sections.select do |s|
      s.course.semester == @semester
    end
13 14 15 16 17 18

    # TODO: move this to a model somewhere
    @courses = [].to_set
    sections.each do |s|
      @courses.add s.course
    end
19 20 21 22 23 24

    @past = []
    @instructor.course_sections.map(&:course).each do |c|
      @past << c unless @past.select { |past| past.full_name == c.full_name }.count.positive?
    end
    @past.sort_by!(&:full_name)
25 26 27 28 29 30
  end

  private

  def set_instructor
    @instructor = Instructor.find_by_id params[:id]
Zac Wood's avatar
Zac Wood committed
31 32
  end
end