dev_forum
cxt 5 years ago
parent 38777f1879
commit 057023cf8f

@ -82,8 +82,8 @@ class SubjectsController < ApplicationController
@is_creator = current_user.creator_of_subject?(@subject)
# 合作团队
@members = @subject.subject_members.includes(:user)
# @shixuns = @subject.shixuns.published.pluck(:id)
challenge_ids = @subject.challenge_ids
@shixuns = @subject.shixuns.published.pluck(:id)
challenge_ids = Challenge.where(shixun_id: @shixuns).pluck(:id)
# 实训路径中的所有实训标签
@tags = ChallengeTag.where(challenge_id: challenge_ids).pluck(:name).uniq
# 用户获取的实训标签

@ -1,10 +1,10 @@
module SubjectsHelper
# 实训路径的发布状态
def publish_status subject, is_manager, user, count
def publish_status subject, is_manager, user, shixuns
status = -1
if is_manager
status = 0 if subject.status == 0 && count > 0
status = 0 if subject.status == 0 && shixuns.count > 0
status = 1 if subject.status == 1
status = 2 if subject.status == 2 && user.admin?
end

@ -31,12 +31,6 @@ class Subject < ApplicationRecord
self.tidings << Tiding.new(user_id: self.user_id, trigger_user_id: self.user_id, belong_container_id: self.id, belong_container_type: 'Subject', tiding_type: "System", viewed: 0)
end
def challenge_ids
sub_shixuns = shixuns.published.pluck(:id)
challenge_ids = Challenge.where(shixun_id: sub_shixuns).pluck(:id)
end
# 挑战过路径的成员数
def member_count
shixuns.pluck(:myshixuns_count).sum
@ -60,8 +54,8 @@ class Subject < ApplicationRecord
def my_subject_score
shixuns_id = shixuns.published_closed.pluck(:id)
my_shixun_score = Challenge.joins(:games).where(games: {status: 2, user_id: User.current.id}, shixun_id: shixuns_id).sum(:score)
my_choose_score = ChallengeChoose.joins(challenge: :games).where(games: {status: 2, user_id: User.current.id}, challenges: {shixun_id: shixuns_id}).sum(:score)
my_shixun_score = Challenge.joins(:games).where(games: {status: 2, user_id: User.current.id}, shixun_id: shixuns_id).pluck(:score).sum
my_choose_score = ChallengeChoose.joins(challenge: :games).where(games: {status: 2, user_id: User.current.id}, challenges: {shixun_id: shixuns_id}).pluck(:score).sum
return my_shixun_score.to_i + my_choose_score.to_i
end
@ -74,7 +68,8 @@ class Subject < ApplicationRecord
end
def my_subject_progress
my_challenge_count = Game.where(user_id: User.current.id, status: 2, challenge_id: challenge_ids).pluck(:challenge_id).uniq.size
my_challenge_count = Game.joins(:challenge).where(user_id: User.current.id, status: 2, challenges: {shixun_id: shixuns.published_closed}).
pluck(:challenge_id).uniq.size
count = self.subject_challenge_count == 0 ? 0 : ((my_challenge_count.to_f / self.subject_challenge_count).round(2) * 100).to_i
end

@ -6,7 +6,7 @@ json.subject_score @subject.all_score
json.member_count @subject.member_count
json.allow_delete @is_creator && (@subject.status != 2 || @user.admin?)
json.publish_status publish_status(@subject, @is_creator, @user, @challenge_count)
json.publish_status publish_status(@subject, @is_creator, @user, @shixuns)
json.allow_statistics @user.manager_of_subject?(@subject)
json.allow_send @user.logged?
json.allow_visit @user.manager_of_subject?(@subject) || @user.admin? || @subject.status > 1

Loading…
Cancel
Save