实训作业的选用实训弹框、申请加入课堂时判断是否有同学号的用户存在

dev_forum
cxt 6 years ago
parent a94222aa02
commit 03e5b0cf09

@ -879,6 +879,13 @@ class CoursesController < ApplicationController
return normal_status(-1, "同一课堂不允许申请多个教师身份")
end
# 验证是否存在同学号的学生
u_extension = current_user.user_extension
if params[:student].present? && u_extension.student?
same_student_id_users = UserExtension.where.not(user_id: current_user.id).where(student_id: u_extension.student_id, identity: %i[student], school_id: u_extension.school_id).pluck(:user_id)
tip_exception("该课堂已存在同学号的学生,暂时无法加入,请联系老师") if course.students.where(user_id: same_student_id_users).size > 0
end
# 创建学生身份
if params[:student].present?
existing_student = CourseMember.find_by(course_id: course.id, role: %i[STUDENT], user_id: current_user.id)

@ -845,12 +845,12 @@ class HomeworkCommonsController < ApplicationController
@shixuns = @shixuns.joins(:shixun_tag_repertoires).where(shixun_tag_repertoires: {tag_repertoire_id: type}).distinct
end
@shixuns = @shixuns.select([:id, :name, :status, :myshixuns_count, :identifier, :user_id, :trainee]).reorder("shixuns.created_at desc")
@shixuns_count = @shixuns.size
@shixuns = @shixuns.select([:id, :name, :status, :myshixuns_count, :identifier, :user_id, :trainee])
@total_count = @shixuns.size
## 分页参数
page = params[:page] || 1
@shixuns = @shixuns.includes(:challenges, user: [user_extension: :school]).page(page).per(10)
@shixuns = @shixuns.reorder("shixuns.created_at desc").includes(:challenges, user: [user_extension: :school]).page(page).per(10)
# 新版用下面的代码
# ## 我的实训

Loading…
Cancel
Save