module Admin::CoursesHelper def page_for_course(course_object) page = Page.where(:module=>"personal_course").first ("/#{I18n.locale}"+page.url+'/'+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"] = Course.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 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 = jl.courses.where(:year.gte => year, :year.lte => year, :member_profile_id.in => mps).count rescue 0 data["data"][year.to_s] = 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 = Course.where(:year.gte => year, :year.lte => year, :member_profile_id.in => mps, :course_semester_id => nil).count rescue 0 when "category" t = Course.where(:year.gte => year, :year.lte => year, :member_profile_id.in => mps, :course_category_id => nil).count rescue 0 end data["data"][year.to_s] = t end finaldata << data finaldata end end