@ -23,16 +23,17 @@ class SubjectsController < ApplicationController
# 最热排序
if reorder == " myshixun_count "
laboratory_join = current_laboratory . main_site? ? '' : " JOIN laboratory_subjects ls ON ls.subject_id = subjects.id AND ls.laboratory_id = #{ current_laboratory . id } "
if select
@subjects = Subject . find_by_sql ( " SELECT subjects.id, subjects.user_id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status,
subjects . shixuns_count , subjects . excellent , sum ( shixuns . myshixuns_count ) AS myshixun_member_count FROM subjects join stage_shixuns
on stage_shixuns . subject_id = subjects . id join shixuns on shixuns . id = stage_shixuns . shixun_id where
on stage_shixuns . subject_id = subjects . id join shixuns on shixuns . id = stage_shixuns . shixun_id #{laboratory_join} where
subjects . hidden = 0 AND subjects . status = 2 AND subjects . name like '%#{search}%'
AND subjects . repertoire_id = #{select} GROUP BY subjects.id ORDER BY myshixun_member_count DESC")
else
@subjects = Subject . find_by_sql ( " SELECT subjects.id, subjects.user_id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status,
subjects . shixuns_count , subjects . excellent , sum ( shixuns . myshixuns_count ) AS myshixun_member_count FROM subjects join stage_shixuns
on stage_shixuns . subject_id = subjects . id join shixuns on shixuns . id = stage_shixuns . shixun_id where
on stage_shixuns . subject_id = subjects . id join shixuns on shixuns . id = stage_shixuns . shixun_id #{laboratory_join} where
subjects . hidden = 0 AND subjects . status = 2 AND subjects . name like '%#{search}%'
GROUP BY subjects . id ORDER BY myshixun_member_count DESC " )
end
@ -52,6 +53,11 @@ class SubjectsController < ApplicationController
@subjects = Subject . visible . unhidden
end
# 云上实验室过滤
unless current_laboratory . main_site?
@subjects = @subjects . joins ( :laboratory_subjects ) . where ( laboratory_subjects : { laboratory_id : current_laboratory . id } )
end
# 类型
if select
@subjects = @subjects . where ( repertoire_id : select )