|
|
@ -77,11 +77,17 @@ class CoursesController < ApplicationController
|
|
|
|
# 根据搜索关键字进一步筛选
|
|
|
|
# 根据搜索关键字进一步筛选
|
|
|
|
if params[:search].present?
|
|
|
|
if params[:search].present?
|
|
|
|
# REDO:Extension
|
|
|
|
# REDO:Extension
|
|
|
|
user_ids = User.includes(user_extension: :school).where("schools.name like ?", "%#{params[:search]}%").pluck(:id)
|
|
|
|
#user_ids = User.includes(user_extension: :school).where("schools.name like ?", "%#{params[:search]}%").pluck(:id)
|
|
|
|
course_ids = CourseMember.includes(:user, :course).where("course_members.course_id in (?) and course_members.role in (1,2,3)
|
|
|
|
#course_ids = CourseMember.includes(:user, :course).where("course_members.course_id in (?) and course_members.role in (1,2,3)
|
|
|
|
and CONCAT(users.lastname, users.firstname) like ?", @courses.map(&:id), "%#{params[:search]}%")
|
|
|
|
# and CONCAT(users.lastname, users.firstname) like ?", @courses.map(&:id), "%#{params[:search]}%")
|
|
|
|
.pluck(:course_id)
|
|
|
|
# .pluck(:course_id)
|
|
|
|
@courses = @courses.where("name like ?", "%#{params[:search]}%").or(@courses.where(tea_id: user_ids)).or(@courses.where(id: course_ids))
|
|
|
|
#@courses = @courses.where("name like ?", "%#{params[:search]}%").or(@courses.where(tea_id: user_ids)).or(@courses.where(id: course_ids))
|
|
|
|
|
|
|
|
# 6:21 daiao
|
|
|
|
|
|
|
|
sql = %Q{
|
|
|
|
|
|
|
|
(course_members.role in (1,2,3) and CONCAT(users.lastname, users.firstname) like :keyword) or courses.name like :keyword
|
|
|
|
|
|
|
|
or schools.name like :keyword
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@courses.includes(course_members: [user: [user_extension: :school]]).where(sql, keyword: "%#{params[:search]}%")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@courses_count = @courses.size
|
|
|
|
@courses_count = @courses.size
|
|
|
|
|
|
|
|
|
|
|
|