70 lines
2.1 KiB
Ruby
70 lines
2.1 KiB
Ruby
module Admin::SelectedCoursesHelper
|
|
def page_for_selected_course(selected_course_object)
|
|
page = nil
|
|
pages = Page.where(:module=>"personal_selected_course")
|
|
|
|
page = pages.first if page.nil?
|
|
request.protocol+(request.host_with_port+page.url+'/'+selected_course_object.to_param).gsub('//','/') rescue "#"
|
|
end
|
|
|
|
def get_data_for_excel(year_start,year_end)
|
|
data = []
|
|
roles = Role.where(:disabled => false, :title.ne => "", :title.ne => nil).asc(:key)
|
|
roles.each do |role|
|
|
d = {}
|
|
d["name"] = role.title
|
|
mps = role.member_profile_ids
|
|
# d1 = DateTime.new(year_start,1,1,0,0)
|
|
# d2 = DateTime.new(year_end,12,31,23,59)
|
|
d["data"] = SelectedCourse.where(:year.gte => year_start, :year.lte => year_end, :member_profile_id.in => mps) rescue []
|
|
data << d
|
|
end
|
|
return data
|
|
end
|
|
|
|
def get_chart_data(year_start,year_end,role,type)
|
|
case type
|
|
when "semester"
|
|
jls = CourseSemester.all
|
|
when "category"
|
|
jls = CourseCategory.all
|
|
end
|
|
|
|
finaldata = []
|
|
role = Role.find(role) rescue nil
|
|
mps = []
|
|
if !role.nil?
|
|
mps = role.member_profile_ids
|
|
end
|
|
total_count = SelectedCourse.where(:member_profile_id.in => mps).count
|
|
jls.each do |jl|
|
|
data = {}
|
|
data["name"] = jl.title
|
|
data["data"] = {}
|
|
(year_start..year_end).each do |year|
|
|
# d1 = DateTime.new(year,1,1,0,0)
|
|
# d2 = DateTime.new(year,12,31,23,59)
|
|
t = SelectedCourse.where(:year.gte => year, :year.lte => year, :member_profile_id.in => mps, :course_id.in=>jl.course_ids).count rescue 0
|
|
data["data"][year.to_s] = t
|
|
total_count -= t
|
|
end
|
|
finaldata << data
|
|
end
|
|
data = {"name" => "N/A", "data" => {}}
|
|
(year_start..year_end).each do |year|
|
|
# d1 = DateTime.new(year,1,1,0,0)
|
|
# d2 = DateTime.new(year,12,31,23,59)
|
|
case type
|
|
when "semester"
|
|
t = total_count rescue 0
|
|
when "category"
|
|
t = total_count rescue 0
|
|
end
|
|
|
|
data["data"][year.to_s] = t
|
|
end
|
|
finaldata << data
|
|
finaldata
|
|
end
|
|
|
|
end |