Merge branch 'develop' of https://git.trustie.net/jacknudt/trustieforge into develop

This commit is contained in:
cxt 2016-01-25 10:16:43 +08:00
commit 12f55f039c
2 changed files with 41 additions and 24 deletions

View File

@ -35,14 +35,29 @@ module CoursesHelper
# a_tags = Course.find_by_sql(sql).select{|course| course.is_public ==1 unless User.current.member_of_course?(course)} # a_tags = Course.find_by_sql(sql).select{|course| course.is_public ==1 unless User.current.member_of_course?(course)}
# 通过elastic结果获取精品课程 # 通过elastic结果获取精品课程
a_courses = [] a_courses = []
courses = Course.search(keywords) #courses = Course.search(keywords)
courses.each do |c| #courses.each do |c|
a_courses << c.id # a_courses << c.id
end #end
a_courses << a_tags unless a_tags.length == 0 a_courses << a_tags unless a_tags.length == 0
# 课程本身不能搜索显示自己
excellent_ids = a_courses.flatten.uniq.delete_if{|i| i == current_course.id}
limit = 5 - excellent_ids.length.to_i
sql = "SELECT distinct c.id FROM course_activities cs, courses c where cs.course_id = c.id
and c.is_excellent =1 and c.id != #{current_course.id} order by cs.updated_at desc;"
default_ecourse_ids = Course.find_by_sql(sql).flatten
# REDO:时间紧,待优化
default_ids =[]
default_ecourse_ids.each do |de|
default_ids << de.id
end
default_ids = default_ids - excellent_ids
#default_ecourse = Course.where("id is not in (?)", ids).find_by_sql(sql).flatten.delete_if{|i| i == current_course.id}.flatten
arr_result = excellent_ids << default_ids
arr_result = arr_result.flatten.first(5)
return arr_result
# 过滤条件:精品课程、本身不在搜索范围 # 过滤条件:精品课程、本身不在搜索范围
e_courses = Course.where("is_excellent =? and id in (?)",1,a_courses.flatten.uniq).where("id !=?",current_course.id) #e_courses = Course.where("is_excellent =? and id in (?)",1, arr_result).where("id !=?", current_course.id)
e_courses
end end
# 判断精品课程是否可见,非课程成员无法查看私有课程 # 判断精品课程是否可见,非课程成员无法查看私有课程

View File

@ -1,7 +1,9 @@
<% unless excellent_course_recommend(course).count == 0 %> <% unless excellent_course_recommend(course).length == 0 %>
<ul class="courseR mb10"> <ul class="courseR mb10">
<h4 class="mb5" ><%= l(:label_homework_recommendation) %></h4> <h4 class="mb5" ><%= l(:label_homework_recommendation) %></h4>
<% excellent_course_recommend(course).each do |e_course| %> <% excellent_course_recommend(course).each do |e_course| %>
<% e_course = Course.find(e_course) %>
<li class="mt15"> <%= image_tag(url_to_avatar(e_course), :width => "40", :height => "40", :class => "fl mr10 rankPortrait", :alt => "logo") %> <li class="mt15"> <%= image_tag(url_to_avatar(e_course), :width => "40", :height => "40", :class => "fl mr10 rankPortrait", :alt => "logo") %>
<div class="fl"> <div class="fl">
<p class="f12 mb5"><%=link_to e_course.name, course_path(e_course.id), :class => "hidden fl w170" %></p> <p class="f12 mb5"><%=link_to e_course.name, course_path(e_course.id), :class => "hidden fl w170" %></p>