From 7529a944cfb150351c23966d14deb626489951e2 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Tue, 14 Oct 2014 10:32:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AF=BE=E7=A8=8B=E9=A6=96?= =?UTF-8?q?=E9=A1=B5=E6=98=BE=E7=A4=BA=E8=AF=BE=E7=A8=8B=EF=BC=9A=201.3-8?= =?UTF-8?q?=E6=9C=88=E4=BB=BD=E4=B8=BA=E6=98=BE=E7=A4=BA=E6=98=A5=E5=AD=A3?= =?UTF-8?q?=E8=AF=BE=E7=A8=8B=EF=BC=8C9-2=E6=9C=88=E4=BB=BD=E4=B8=BA?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E7=A7=8B=E5=AD=A3=E8=AF=BE=E7=A8=8B=201.?= =?UTF-8?q?=E5=BD=93=E5=89=8D=E7=94=A8=E6=88=B7=E6=9C=AA=E7=99=BB=E5=BD=95?= =?UTF-8?q?=EF=BC=9A=E6=98=BE=E7=A4=BA=E7=B3=BB=E7=BB=9F=E4=B8=AD=E5=9C=A8?= =?UTF-8?q?=E5=BD=93=E5=89=8D=E5=B9=B4=E5=BA=A6=E3=80=81=E5=AD=A3=E5=BA=A6?= =?UTF-8?q?=E4=B8=AD=E4=BA=BA=E6=95=B0=E6=9C=80=E5=A4=9A=E7=9A=8410?= =?UTF-8?q?=E4=B8=AA=E5=85=AC=E5=BC=80=E8=AF=BE=E7=A8=8B=202.=E5=BD=93?= =?UTF-8?q?=E5=89=8D=E7=94=A8=E6=88=B7=E4=BB=A5=E7=99=BB=E5=BD=95=EF=BC=8C?= =?UTF-8?q?=E6=88=96=E8=80=85=E9=80=89=E6=8B=A9=E6=8C=87=E5=AE=9A=E5=AD=A6?= =?UTF-8?q?=E6=A0=A1=EF=BC=9A=E6=98=BE=E7=A4=BA=E8=AF=A5=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=89=80=E5=9C=A8=E5=AD=A6=E6=A0=A1/=E6=8C=87=E5=AE=9A?= =?UTF-8?q?=E5=AD=A6=E6=A0=A1=E5=9C=A8=E5=BD=93=E5=89=8D=E5=B9=B4=E5=BA=A6?= =?UTF-8?q?=E3=80=81=E5=AD=A3=E5=BA=A6=E4=B8=AD=E4=BA=BA=E6=95=B0=E6=9C=80?= =?UTF-8?q?=E5=A4=9A=E7=9A=8410=E9=97=A8=E8=AF=A5=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=8F=AF=E8=A7=81=E7=9A=84=E8=AF=BE=E7=A8=8B(=E5=8C=85?= =?UTF-8?q?=E6=8B=AC=E8=AF=A5=E7=94=A8=E6=88=B7=E5=8F=AF=E8=A7=81=E7=9A=84?= =?UTF-8?q?=E7=A7=81=E6=9C=89=E8=AF=BE=E7=A8=8B)=EF=BC=8C=E5=A6=82?= =?UTF-8?q?=E6=9E=9C=E8=AF=A5=E5=AD=A6=E6=A0=A1=E8=AF=BE=E7=A8=8B=E6=95=B0?= =?UTF-8?q?=E9=87=8F=E4=B8=8D=E8=B6=B3=EF=BC=8C=E5=90=91=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=8E=A8=E8=8D=90=E5=85=B6=E4=BB=96=E8=AF=BE=E7=A8=8B=E8=A1=A5?= =?UTF-8?q?=E5=85=85=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/welcome_controller.rb | 11 +++--- app/helpers/welcome_helper.rb | 44 +++++++++++++++--------- app/views/welcome/course.html.erb | 48 +++++++++++++++------------ 3 files changed, 62 insertions(+), 41 deletions(-) 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 @@