|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
class SubjectsController < ApplicationController
|
|
|
|
|
before_action :require_login, except: [:index]
|
|
|
|
|
before_action :require_login, :check_auth, except: [:index]
|
|
|
|
|
# before_action :check_auth, except: [:index]
|
|
|
|
|
before_action :find_subject, except: [:index, :create, :append_to_stage]
|
|
|
|
|
before_action :allowed, only: [:update, :edit, :destroy, :publish, :cancel_publish, :cancel_has_publish,
|
|
|
|
@ -22,17 +22,17 @@ class SubjectsController < ApplicationController
|
|
|
|
|
# 最热排序
|
|
|
|
|
if reorder == "myshixun_count"
|
|
|
|
|
if select
|
|
|
|
|
@subjects = Subject.find_by_sql("SELECT subjects.id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status,
|
|
|
|
|
subjects.shixuns_count, COUNT(myshixuns.id) AS myshixun_member_count FROM myshixuns, stage_shixuns, subjects
|
|
|
|
|
WHERE myshixuns.shixun_id = stage_shixuns.shixun_id AND stage_shixuns.subject_id = subjects.id
|
|
|
|
|
AND `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")
|
|
|
|
|
@subjects = Subject.find_by_sql("SELECT subjects.id, subjects.user_id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status,
|
|
|
|
|
subjects.shixuns_count, 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
|
|
|
|
|
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.name, subjects.stages_count, subjects.repertoire_id, subjects.status,
|
|
|
|
|
subjects.shixuns_count, COUNT(myshixuns.id) AS myshixun_member_count FROM myshixuns, stage_shixuns, subjects
|
|
|
|
|
WHERE myshixuns.shixun_id = stage_shixuns.shixun_id AND stage_shixuns.subject_id = subjects.id
|
|
|
|
|
AND `subjects`.`hidden` = 0 AND `subjects`.`status` = 2 AND `subjects`.`name` like '%#{search}%'
|
|
|
|
|
GROUP BY subjects.id ORDER BY myshixun_member_count DESC")
|
|
|
|
|
@subjects = Subject.find_by_sql("SELECT subjects.id, subjects.user_id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status,
|
|
|
|
|
subjects.shixuns_count, 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
|
|
|
|
|
subjects.hidden = 0 AND subjects.status = 2 AND subjects.name like '%#{search}%'
|
|
|
|
|
GROUP BY subjects.id ORDER BY myshixun_member_count DESC")
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
# 我的路径
|
|
|
|
@ -65,9 +65,11 @@ class SubjectsController < ApplicationController
|
|
|
|
|
@total_count = @subjects.size
|
|
|
|
|
|
|
|
|
|
if reorder != "myshixun_count"
|
|
|
|
|
@subjects = @subjects.page(page).per(limit).includes(:shixuns)
|
|
|
|
|
@subjects = @subjects.page(page).per(limit).includes(:shixuns, :repertoire)
|
|
|
|
|
else
|
|
|
|
|
@subjects = @subjects[offset, limit]
|
|
|
|
|
subject_ids = @subjects.pluck(:id)
|
|
|
|
|
@subjects = Subject.where(id: subject_ids).order("field(id,#{subject_ids.join(',')})").includes(:shixuns, :repertoire)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|