个人主页的收藏

schedule_job
cxt 5 years ago
parent 41e510e108
commit 2fcbd4c351

@ -1,4 +1,7 @@
class Collection < ApplicationRecord
belongs_to :user
belongs_to :container, polymorphic: true, optional: true
scope :shixuns, -> {where(container_type: 'Shixun')}
scope :subjects, -> {where(container_type: 'Subject')}
end

@ -48,8 +48,6 @@ class User < ApplicationRecord
has_many :course_messages
has_many :courses, foreign_key: 'tea_id', dependent: :destroy
has_many :collections, dependent: :destroy
#试卷
has_many :exercise_banks, :dependent => :destroy
has_many :exercise_users, :dependent => :destroy
@ -119,6 +117,11 @@ class User < ApplicationRecord
has_many :manage_course_members, -> { teachers_and_admin }, class_name: 'CourseMember'
has_many :manage_courses, through: :manage_course_members, source: :course
has_many :collections, dependent: :destroy
has_many :shixun_collections, -> { shixuns }, class_name: 'Collection'
has_many :subject_collections, -> { subjects }, class_name: 'Collection'
# 关注
# has_many :be_watchers, foreign_key: :user_id, dependent: :destroy # 我的关注
# has_many :be_watcher_users, through: :be_watchers, dependent: :destroy # 我关注的用户

@ -24,15 +24,17 @@ class Users::ShixunService
user.study_shixuns.where(shixuns: {id: laboratory.shixuns})
when 'manage' then
laboratory.shixuns.where(id: user.shixuns)
when 'collect' then
laboratory.shixuns.where(id: user.shixun_collections.pluck(:container_id))
else
ids = user.study_shixuns.pluck(:id) + user.shixuns.pluck(:id)
ids = user.study_shixuns.pluck(:id) + user.shixuns.pluck(:id) + user.shixun_collections.pluck(:container_id)
laboratory.shixuns.where(id: ids)
end
end
def status_filter(relations)
case params[:category]
when 'study' then
when 'study', 'collect' then
study_shixun_status_filter(relations)
when 'manage' then
manage_shixun_status_filter(relations)
@ -97,7 +99,7 @@ class Users::ShixunService
end
case params[:category]
when 'study' then
when 'study', 'collect' then
relations.order("myshixuns.#{sort_by} #{sort_direction}")
when 'manage' then
relations.order("shixuns.#{sort_by} #{sort_direction}")

@ -25,10 +25,13 @@ class Users::SubjectService
Subject.joins(stage_shixuns: { shixun: :myshixuns }).where(myshixuns: { user_id: user.id })
when 'manage' then
Subject.joins(:subject_members).where(subject_members: { user_id: user.id })
when 'collect' then
Subject.where(id: user.subject_collections.pluck(:container_id))
else
study_subject_ids = StageShixun.where(shixun_id: user.myshixuns.pluck(:shixun_id)).pluck(:subject_id)
manage_subject_ids = user.subject_members.pluck(:subject_id)
Subject.where(id: study_subject_ids + manage_subject_ids)
collect_subject_ids = user.subject_collections.pluck(:container_id)
Subject.where(id: study_subject_ids + manage_subject_ids + collect_subject_ids)
end
end
@ -45,7 +48,7 @@ class Users::SubjectService
return relations unless self_or_admin?
case params[:category]
when 'study' then
when 'study', 'collect' then
study_subject_status_filter(relations)
when 'manage' then
manage_subject_status_filter(relations)

Loading…
Cancel
Save