From 2a6cbe28f05140fb040f770e1d5659bb67644c9f Mon Sep 17 00:00:00 2001 From: nwb Date: Thu, 3 Jul 2014 15:24:06 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E9=A6=96=E9=A1=B5=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/welcome_controller.rb | 3 +- app/helpers/welcome_helper.rb | 49 ++++++++++++++++++- app/views/welcome/_search_course.html.erb | 58 +++++++++++++++++++++++ app/views/welcome/course.html.erb | 16 +++---- config/routes.rb | 3 +- db/schema.rb | 3 +- 6 files changed, 119 insertions(+), 13 deletions(-) create mode 100644 app/views/welcome/_search_course.html.erb diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 6105b22b2..dd0b776b4 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 d41e6bd95..f753052c1 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 000000000..fda9dae7c --- /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 5ec76e4cc..cd2bf724d 100644 --- a/app/views/welcome/course.html.erb +++ b/app/views/welcome/course.html.erb @@ -62,7 +62,7 @@ <% end %>
@@ -108,10 +108,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) %>资料)
- <% 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) %>资料)