在线学习的优化

dev_ec
cxt 5 years ago
parent 4e8e88386d
commit e683b25ead

@ -272,7 +272,7 @@ class CoursesController < ApplicationController
@stages = @course.course_stages.includes(:shixuns)
@user = current_user
@myshixuns = @user.myshixuns.where(shixun_id: @course.course_stage_shixuns.pluck(:shixun_id))
@start_learning = @user_course_identity == Course::STUDENT && @course.learning?(current_user.id)
@start_learning = @user_course_identity == Course::STUDENT && @myshixuns.present?
end
def search_course_list

@ -269,8 +269,8 @@ module CoursesHelper
group_info
end
def last_subject_shixun user_id, course
myshixun = Myshixun.where(user_id: user_id, shixun_id: course.shixuns).order("updated_at desc").first
def last_subject_shixun course, myshixuns
myshixun = myshixuns.sort{|x,y| y[:updated_at] <=> x[:updated_at] }.first
return "" unless myshixun
stage_shixun = course.course_stage_shixuns.where(shixun_id: myshixun.shixun_id).take
progress = stage_shixun&.course_stage&.position.to_s + "-" + stage_shixun&.position.to_s + " " + myshixun.shixun&.name

@ -354,9 +354,8 @@ class Course < ApplicationRecord
Myshixun.where(user_id: user_id, shixun_id: shixuns).exists?
end
def my_subject_progress
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
def my_subject_progress myshixuns
my_challenge_count = Game.where(myshixun_id: myshixuns.pluck(:id), status: 2).pluck(:challenge_id).uniq.size
course_challeng_count = shixuns.pluck(:challenges_count).sum
count = course_challeng_count == 0 ? 0 : ((my_challenge_count.to_f / course_challeng_count).round(2) * 100).to_i
end

@ -7,6 +7,6 @@ end
json.start_learning @start_learning
json.subject_id @subject.id
json.learned @start_learning ? @course.my_subject_progress : 0
json.learned @start_learning ? @course.my_subject_progress(@myshixuns) : 0
json.last_shixun @start_learning ? last_subject_shixun(@user.id, @course) : ""
json.last_shixun @start_learning ? last_subject_shixun(@course, @myshixuns) : ""
Loading…
Cancel
Save