@ -12,6 +12,59 @@ module CoursesHelper
#AllPeople = StudentRoles+TeacherRoles
#AllPeople = StudentRoles+TeacherRoles
## return people count
## return people count
# 推荐的精品课程
def excellent_course_recommend new_course
q = " % #{ new_course . name . strip } % "
result = find_excelletn_course ( q , new_course )
end
# 查询符合条件的精品课程
# 用新课程名去匹配精品课程中按课程名和Tag名
def find_excelletn_course keywords , current_course
# 获取tag匹配结果ID
a_tags = [ ]
# kc = keywords.to_a
Course . visible . where ( " is_excellent =? " , 1 ) . each do | ec |
if ec . tags . any? { | value | current_course . name . include? ( value . to_s ) }
a_tags << ec . id
end
end
# sql = "SELECT distinct c.* FROM `courses` c, tags t, taggings ts where t.id = ts.tag_id and ts.taggable_id = c.id and c.is_excellent = 1 and is_delete = 0 and
# ts.taggable_type = 'Course' and t.name like '%#{keywords}%'"
# a_tags = Course.find_by_sql(sql).select{|course| course.is_public ==1 unless User.current.member_of_course?(course)}
# 通过elastic结果获取精品课程
a_courses = [ ]
#courses = Course.search(keywords)
#courses.each do |c|
# a_courses << c.id
#end
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, arr_result).where("id !=?", current_course.id)
end
# 判断精品课程是否可见,非课程成员无法查看私有课程
def visible_excellent_course obj
# if course.is_pu
end
# 返回x项目成员数量, 即roles表中定义的所有成员
# 返回x项目成员数量, 即roles表中定义的所有成员
def projectCount project
def projectCount project
#searchCountByRoles project, AllPeople
#searchCountByRoles project, AllPeople
@ -509,7 +562,7 @@ module CoursesHelper
type = [ ]
type = [ ]
month = Time . now . month
month = Time . now . month
now_year = year . nil? ? Time . now . year : ( Time . now . year < = year ? Time . now . year : year )
now_year = year . nil? ? Time . now . year : ( Time . now . year < = year ? Time . now . year : year )
year = month < 3 ? now_year - 1 : now_year
year = month < 3 && now_year > = Time . now . year ? now_year - 1 : now_year
for i in ( year .. year + 10 )
for i in ( year .. year + 10 )
option = [ ]
option = [ ]
option << i
option << i