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 %>
+
+
+ <%= text_field_tag :q, nil, placeholder:'请输入要搜索的关键字', :size => 27 %>
+ <%= select_tag(:search_type, options_for_select(select_option) ) %>
+
+ <%#= hidden_field_tag 'project_type', project_type %>
+ <%= submit_tag l(:label_search), :class => "enterprise", :name => nil %>
+
+<% 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 %>
- <%= render :partial => "search_project", :locals => {:project_type => Project::ProjectType_course}%>
+ <%= render :partial => "search_course", :locals => {:project_type => Project::ProjectType_course}%>
@@ -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) %>资料)
diff --git a/config/routes.rb b/config/routes.rb
index 88d2725b..7c1ad802 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -573,7 +573,8 @@ RedmineApp::Application.routes.draw do
end
end
- match 'projects/course', :to => 'courses#course', :as => 'course'
+ match 'projects/course', :to => 'courses#course', :as => 'courses_course'
+ match 'courses/search', :to => 'courses#search'
# add by nwb
# 课程路由设置
resources :courses do
diff --git a/db/schema.rb b/db/schema.rb
index e8ce039c..9e05357b 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20140701031909) do
+ActiveRecord::Schema.define(:version => 20140701075839) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@@ -925,6 +925,7 @@ ActiveRecord::Schema.define(:version => 20140701031909) do
add_index "taggings", ["tag_id"], :name => "index_taggings_on_tag_id"
add_index "taggings", ["taggable_id", "taggable_type", "context"], :name => "index_taggings_on_taggable_id_and_taggable_type_and_context"
+ add_index "taggings", ["taggable_type"], :name => "index_taggings_on_taggable_type"
create_table "tags", :force => true do |t|
t.string "name"