26 lines
673 B
Ruby
26 lines
673 B
Ruby
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
|
|
materials = materials.where(term: params[:term]) if params[:term].present?
|
|
#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 |