|
|
@ -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
|
|
|
|
|
|
|
|
|
|
|
|
# 判断精品课程是否可见,非课程成员无法查看私有课程
|
|
|
|
# 判断精品课程是否可见,非课程成员无法查看私有课程
|
|
|
|