diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index dee79bc31..6cc565863 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -62,11 +62,12 @@ class WelcomeController < ApplicationController def course @course_page = FirstPage.where("page_type = 'course'").first - if params[:school_id] - @school_id = params[:school_id] - elsif User.current.logged? && User.current.user_extensions.try(:school) - @school_id = User.current.user_extensions.school.try(:id) - end + #if params[:school_id] + # @school_id = params[:school_id] + #elsif User.current.logged? && User.current.user_extensions.try(:school) + # @school_id = User.current.user_extensions.school.try(:id) + #end + @school_id = params[:school_id] || User.current.user_extensions.school.try(:id) @logoLink ||= logolink() end diff --git a/app/helpers/welcome_helper.rb b/app/helpers/welcome_helper.rb index 1139deb35..2399179b8 100644 --- a/app/helpers/welcome_helper.rb +++ b/app/helpers/welcome_helper.rb @@ -136,31 +136,33 @@ module WelcomeHelper #获取课程列表 # add by nwb - def find_miracle_course(sum=10, max_rate=7, school_id) + def find_miracle_course(sum=10, max_rate=7, school_id, time,term) if User.current.user_extensions.nil? && User.current.user_extensions.school.nil? and school_id.nil? Course.active.visible. joins(:memberships). + where("courses.time = #{time} and courses.term = #{term}"). group('members.course_id'). reorder("courses.created_at DESC, COUNT(members.course_id) DESC").take sum else if school_id.nil? Course.active.visible. joins(:memberships). - where("#{Course.table_name}.school_id = ?", User.current.user_extensions.school.id). + where("#{Course.table_name}.school_id = ? and courses.time = ? and courses.term = ?", User.current.user_extensions.school.id, time, term). group('members.course_id'). - reorder("courses.created_at DESC, COUNT(members.course_id) DESC").take sum + reorder("COUNT(members.course_id) DESC").take sum else if school_id == "0" Course.active.visible. joins(:memberships). + where("courses.time = #{time} and courses.term = #{term}"). group('members.course_id'). - reorder("courses.created_at DESC, COUNT(members.course_id) DESC").take sum + reorder("COUNT(members.course_id) DESC").take sum else Course.active.visible. joins(:memberships). - where("#{Course.table_name}.school_id = ?", school_id). + where("#{Course.table_name}.school_id = ? and courses.time = ? and courses.term = ?", school_id, time, term). group('members.course_id'). - reorder("courses.created_at DESC, COUNT(members.course_id) DESC").take sum + reorder("COUNT(members.course_id) DESC").take sum end end end @@ -229,16 +231,28 @@ module WelcomeHelper end # modif by nwb - def find_all_new_hot_course limit = 9 ,school_id = 0 + def find_all_new_hot_course limit = 9 ,school_id = nil, year_now, course_term #sort_project_by_hot_rails 1, 'course_ac_para DESC', limit - time_now = Time.new.strftime("%Y") - if school_id - courses = Course.includes(:school, :members).visible.joins(:course_status).where("#{Course.table_name}.created_at like '%#{time_now}%' and #{Course.table_name}.school_id <> - ?", school_id).order("course_ac_para DESC").limit(limit).all - else - courses = Course.includes(:school, :members).visible.joins(:course_status).where("#{Course.table_name}.created_at like '%#{time_now}%' and #{Course.table_name}.school_id is not NULL - ").order("course_ac_para DESC").limit(limit).all - end + #time_now = Time.new.strftime("%Y") + #if school_id + #courses = Course.includes(:school, :members).visible.joins(:course_status).where("#{Course.table_name}.created_at like '%#{time_now}%' and #{Course.table_name}.school_id <> + # ?", school_id).order("course_ac_para DESC").limit(limit).all + #else + # courses = Course.includes(:school, :members).visible.joins(:course_status).where("#{Course.table_name}.created_at like '%#{time_now}%' and #{Course.table_name}.school_id is not NULL + # ").order("course_ac_para DESC").limit(limit).all + # end + school_id.nil? ? + courses = Course.includes(:school, :members).visible. + joins(:memberships). + where("courses.time = ? and courses.term = ? and courses.school_id is not NULL", year_now, course_term). + group('members.course_id'). + reorder("COUNT(members.course_id) DESC").limit(limit).all + : + courses = Course.includes(:school, :members).visible. + joins(:course_status). + where("courses.time = ? and courses.term = ? and courses.school_id <> ?",year_now, course_term, school_id). + group('members.course_id'). + reorder("COUNT(members.course_id) DESC").limit(limit).all courses end diff --git a/app/views/welcome/course.html.erb b/app/views/welcome/course.html.erb index d28c89aa8..ea8963f7e 100644 --- a/app/views/welcome/course.html.erb +++ b/app/views/welcome/course.html.erb @@ -78,29 +78,28 @@