查詢關鍵字新增查詢老師名稱
This commit is contained in:
parent
6c9cb2b23d
commit
ffce95eeaf
|
@ -345,20 +345,20 @@ class AsiaDatabasesController < ApplicationController
|
|||
render json: { 'success' => true }.to_json
|
||||
end
|
||||
def filter_keywords(asia_data,select_field,keywords)
|
||||
member_fields = []
|
||||
file_fields = []
|
||||
link_fields = []
|
||||
if select_field == nil
|
||||
asia_data = asia_data.where(:slug_title=>/#{gsub_invalid_character(keywords)}/)
|
||||
elsif select_field == "member_profile"
|
||||
ms = MemberProfile.all.select{|m| m.name.include?(keywords)}
|
||||
asia_data = asia_data.where(:member_profile_id.in=>ms.map{|m| m.id})
|
||||
elsif member_fields.include?(select_field)
|
||||
ms = MemberProfile.all.select{|m| m.name.include?(keywords)}
|
||||
m_ids = ms.map{|m| m.id.to_s }
|
||||
tmp_asia_data = asia_data.select{|p| (p.send("#{select_field.singularize}_ids") & m_ids).count != 0}
|
||||
asia_data = asia_data.where(:id.in=>tmp_asia_data.map{|p| p.id})
|
||||
elsif select_field.split(".").count > 1
|
||||
# member_fields = []
|
||||
# file_fields = []
|
||||
# link_fields = []
|
||||
# if select_field == nil
|
||||
# asia_data = asia_data.where(:slug_title=>/#{gsub_invalid_character(keywords)}/)
|
||||
# elsif select_field == "member_profile"
|
||||
# ms = MemberProfile.all.select{|m| m.name.include?(keywords)}
|
||||
# asia_data = asia_data.where(:member_profile_id.in=>ms.map{|m| m.id})
|
||||
# elsif member_fields.include?(select_field)
|
||||
# ms = MemberProfile.all.select{|m| m.name.include?(keywords)}
|
||||
# m_ids = ms.map{|m| m.id.to_s }
|
||||
# tmp_asia_data = asia_data.select{|p| (p.send("#{select_field.singularize}_ids") & m_ids).count != 0}
|
||||
# asia_data = asia_data.where(:id.in=>tmp_asia_data.map{|p| p.id})
|
||||
if select_field.split(".").count > 1
|
||||
relate_name = select_field.split(".").first
|
||||
field_name = select_field.split(".").last.gsub(/^\$+/, '')
|
||||
relate = relate_name.camelize.constantize
|
||||
|
@ -388,22 +388,38 @@ class AsiaDatabasesController < ApplicationController
|
|||
elsif (asia_data.klass.fields[select_field].options[:type] == Integer rescue false)
|
||||
tmp_asia_data = asia_data.select{|p| p.send(select_field).to_s.include?(keywords)}
|
||||
asia_data = asia_data.where(:id.in=>tmp_asia_data.map{|p| p.id})
|
||||
elsif file_fields.include?(select_field)
|
||||
file_field = select_field.camelize.constantize
|
||||
ids1 = file_field.where(:file=>/#{gsub_invalid_character(keywords)}/).pluck(:id)
|
||||
ids2 = file_field.where(:title=>/#{gsub_invalid_character(keywords)}/).pluck(:id)
|
||||
ids = ids1 + ids2
|
||||
tmp_asia_data = asia_data.select{|p| (p.send("#{select_field}_ids") & ids).count != 0}
|
||||
asia_data = asia_data.where(:id.in=>tmp_asia_data.map{|p| p.id})
|
||||
elsif link_fields.include?(select_field)
|
||||
link_field = select_field.camelize.constantize
|
||||
ids1 = link_field.where(:title=>/#{gsub_invalid_character(keywords)}/).pluck(:id)
|
||||
ids2 = link_field.where(:url=>/#{gsub_invalid_character(keywords)}/).pluck(:id)
|
||||
ids = ids1 + ids2
|
||||
tmp_asia_data = asia_data.select{|p| (p.send("#{select_field}_ids") & ids).count != 0}
|
||||
asia_data = asia_data.where(:id.in=>tmp_asia_data.map{|p| p.id})
|
||||
# elsif file_fields.include?(select_field)
|
||||
# file_field = select_field.camelize.constantize
|
||||
# ids1 = file_field.where(:file=>/#{gsub_invalid_character(keywords)}/).pluck(:id)
|
||||
# ids2 = file_field.where(:title=>/#{gsub_invalid_character(keywords)}/).pluck(:id)
|
||||
# ids = ids1 + ids2
|
||||
# tmp_asia_data = asia_data.select{|p| (p.send("#{select_field}_ids") & ids).count != 0}
|
||||
# asia_data = asia_data.where(:id.in=>tmp_asia_data.map{|p| p.id})
|
||||
# elsif link_fields.include?(select_field)
|
||||
# link_field = select_field.camelize.constantize
|
||||
# ids1 = link_field.where(:title=>/#{gsub_invalid_character(keywords)}/).pluck(:id)
|
||||
# ids2 = link_field.where(:url=>/#{gsub_invalid_character(keywords)}/).pluck(:id)
|
||||
# ids = ids1 + ids2
|
||||
# tmp_asia_data = asia_data.select{|p| (p.send("#{select_field}_ids") & ids).count != 0}
|
||||
# asia_data = asia_data.where(:id.in=>tmp_asia_data.map{|p| p.id})
|
||||
else
|
||||
asia_data = asia_data.where(select_field=>/#{gsub_invalid_character(keywords)}/)
|
||||
if asia_data.klass == AsiaTeacher
|
||||
asia_data = asia_data.any_of([
|
||||
{
|
||||
select_field=> /#{gsub_invalid_character(keywords)}/
|
||||
},{
|
||||
teacher => /#{gsub_invalid_character(keywords)}/
|
||||
}
|
||||
])
|
||||
else
|
||||
asia_data = asia_data.any_of([
|
||||
{
|
||||
select_field=> /#{gsub_invalid_character(keywords)}/
|
||||
},{
|
||||
:asia_teacher_id.in => AsiaTeacher.where(teacher: /#{gsub_invalid_character(keywords)}/).pluck(:id)
|
||||
}
|
||||
])
|
||||
end
|
||||
end
|
||||
return asia_data
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue