完成精品课程推荐

过滤掉私有课程
过滤掉已删除的课程
This commit is contained in:
huang 2016-01-18 17:36:18 +08:00
parent b93b86b9a0
commit 5862c16c68
1 changed files with 3 additions and 9 deletions

View File

@ -21,16 +21,10 @@ module CoursesHelper
# 查询符合条件的精品课程 # 查询符合条件的精品课程
def find_excelletn_course keywords, course def find_excelletn_course keywords, course
# 用新课程名去匹配精品课程中按课程名和Tag名 # 用新课程名去匹配精品课程中按课程名和Tag名
if !course.is_public? && !User.current.member_of_course?(course) 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
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}%'or c.name like '%#{keywords}%')" ts.taggable_type = 'Course' and (t.name like '%#{keywords}%'or c.name like '%#{keywords}%')"
resultSetTag = Course.find_by_sql(sql) resultSetTag = Course.find_by_sql(sql).select{|e_course| e_course.is_public ==1 unless User.current.member_of_course?(e_course)}.first(3)
else resultSetTag
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}%'or c.name like '%#{keywords}%') ORDER BY c.updated_at desc limit 0,5;"
resultSetTag = Course.visible.find_by_sql(sql)
end
end end
# 判断精品课程是否可见,非课程成员无法查看私有课程 # 判断精品课程是否可见,非课程成员无法查看私有课程