diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 0e093460f..4bfc236a1 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -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 diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 5ca4eb773..d670614d5 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -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 diff --git a/app/models/course.rb b/app/models/course.rb index ba818449e..6dd361733 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -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 diff --git a/app/views/courses/online_learning.json.jbuilder b/app/views/courses/online_learning.json.jbuilder index 95b44238c..d6b3db136 100644 --- a/app/views/courses/online_learning.json.jbuilder +++ b/app/views/courses/online_learning.json.jbuilder @@ -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) : "" \ No newline at end of file +json.last_shixun @start_learning ? last_subject_shixun(@course, @myshixuns) : "" \ No newline at end of file