diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 6105b22b..dd0b776b 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -75,8 +75,7 @@ class WelcomeController < ApplicationController redirect_to projects_search_path(:name => search_condition, :project_type => Project::ProjectType_project) when :courses - redirect_to projects_search_path(:name => search_condition, - :project_type => Project::ProjectType_course) + redirect_to courses_search_path(:name => search_condition) when :users redirect_to users_search_path(:name => search_condition) when :users_teacher diff --git a/app/helpers/welcome_helper.rb b/app/helpers/welcome_helper.rb index d41e6bd9..f753052c 100644 --- a/app/helpers/welcome_helper.rb +++ b/app/helpers/welcome_helper.rb @@ -83,7 +83,8 @@ module WelcomeHelper # # => 前7个项目为新课程,后面三个是参与人数最多的 # # Returns project&courses array - def find_miracle_course(sum=10, max_rate=7, school_id) + # 原来的取课程逻辑 + def find_miracle_course_base(sum=10, max_rate=7, school_id) if User.current.user_extensions.school.nil? and school_id.nil? Project.active.visible.course_entities. @@ -133,6 +134,52 @@ module WelcomeHelper # (c1.take(max)+c2).take(sum) end + #获取课程列表 + # add by nwb + def find_miracle_course(sum=10, max_rate=7, school_id) + if User.current.user_extensions.school.nil? and school_id.nil? + Course.active.visible. + joins(:memberships). + group('members.course_id'). + reorder("courses.time 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). + group('members.course_id'). + reorder("courses.time DESC, COUNT(members.course_id) DESC").take sum + else + if school_id == "0" + Course.active.visible. + joins(:memberships). + group('members.course_id'). + reorder("courses.time DESC, COUNT(members.course_id) DESC").take sum + else + Course.active.visible. + joins(:memberships). + where("#{Course.table_name}.school_id = ?", school_id). + group('members.course_id'). + reorder("courses.time DESC, COUNT(members.course_id) DESC").take sum + end + end + end +# else +# Project.active.visible.course_entities. +# joins(:course_extra). +# joins(:memberships). +# where("#{Course.table_name}.school_id = ?", school_id). +# group('members.project_id'). +# reorder("courses.time DESC, COUNT(members.project_id) DESC").take sum +# end +# max = sum*(max_rate.to_f/10) +# c1 = find_new_course(sum).to_a.dup +# c2 = find_all_hot_course(sum).to_a.dup +# c2 = c2 - c1 +# (c1.take(max)+c2).take(sum) + end + #查找所有学校按每个学校开设课程数量降序排序 #page 分页查询开始条数的编号,从0开始 #limit 分页查询的数量 diff --git a/app/views/welcome/_search_course.html.erb b/app/views/welcome/_search_course.html.erb new file mode 100644 index 00000000..fda9dae7 --- /dev/null +++ b/app/views/welcome/_search_course.html.erb @@ -0,0 +1,58 @@ +<% + select_option = [] + (select_option << ['项目', 'projects']) if project_type == Project::ProjectType_project + (select_option << ['课程', 'courses']) if project_type == Project::ProjectType_course + select_option << ['用户', 'users'] + #select_option << ['教师', 'users_teacher'], + #select_option << ['学生', 'users_student'] +%> + +<%= form_tag({controller: :welcome, action: :search }, method: :get) do %> + +<% end %> diff --git a/app/views/welcome/course.html.erb b/app/views/welcome/course.html.erb index 5ec76e4c..ca7f0bb7 100644 --- a/app/views/welcome/course.html.erb +++ b/app/views/welcome/course.html.erb @@ -62,7 +62,7 @@ <% end %>
@@ -75,7 +75,7 @@

新开课程

<% school_course = find_miracle_course(10, 7,params[:school_id]) %> <% if(school_course.count == 0) %> - <%= link_to "更多>>", {:controller => 'courses', :action => 'course', :project_type => 1, :school_id => nil} %> + <%= link_to "更多>>", {:controller => 'courses', :action => 'index', :school_id => nil} %>
[<%= get_course_term project %>] - <%= link_to( project.name, project_path(project.id), :class => "d-g-blue d-p-project-name",:title => "#{project.name}" )%> + <%= link_to( project.name, course_path(project.id), :class => "d-g-blue d-p-project-name",:title => "#{project.name}" )%> (<%= "#{studentCount(project)}人" %>) <% files_count = (project.attachments.count.to_i+Version.joins(:project).where("projects.id=#{project.id}").count.to_i).to_s %> - (<%=link_to "#{files_count}份", project_files_path(project) %>资料) + (<%=link_to "#{files_count}份", course_files_path(project) %>资料)
- <% course = Course.find_by_extra(project.identifier) %> + <% course = project %> <%=link_to course.school.name.try(:gsub, /(.+)$/, '\1:'),options={:action => 'course',:school_id => course.school.id}, html_options={:method => 'get'} %> @@ -159,10 +159,10 @@
[<%= get_course_term project %>] - <%= link_to( project.name, project_path(project.id), :class => "d-g-blue d-p-project-name",:title => "#{project.name}" )%> + <%= link_to( project.name, course_path(project.id), :class => "d-g-blue d-p-project-name",:title => "#{project.name}" )%> (<%= "#{studentCount(project)}人" %>) <% files_count = (project.attachments.count.to_i+Version.joins(:project).where("projects.id=#{project.id}").count.to_i).to_s %> - (<%=link_to "#{files_count}份", project_files_path(project) %>资料) + (<%=link_to "#{files_count}份", course_files_path(project) %>资料)