class Admins::GlccExamineMaterial < ApplicationQuery
  include CustomSortable

  attr_reader :params

  sort_columns :created_on, default_direction: :desc

  def initialize(params)
    @params = params
  end

  def call
    materials = GlccMediumTermExamineMaterial.all

    # term
    term = params[:term] || [1,2]
    if term.present?
      materials = materials.where(term: term)
    end
    #year
    year = if params[:date]
      params[:date][:year] 
    end
    year = year || Time.now.year
    date = Time.now.change(year:year)
    materials = materials.where(created_on: [date.beginning_of_year..date.end_of_year])
    custom_sort(materials, params[:sort_by], params[:sort_direction])
  end
end