导入课堂学生创建数据

dev_aliyun
cxt 5 years ago
parent 2e7deeb977
commit df8c6a2bfc

@ -2946,7 +2946,7 @@ end
course_id = worksheet.cell(row, 3)
group_name = worksheet.cell(row, 5)
school_id = worksheet.cell(row, 6).is_a?(Float) ? worksheet.cell(row, 6).to_i : worksheet.cell(row, 6)
if student_id && member_role && [9, 7, 10].include?(member_role) && course_id && school_id
if student_id && member_role && [2, 3, 4].include?(member_role) && course_id && school_id
user = User.find_by_sql("SELECT u.* FROM `users` u, `user_extensions` ue where u.id = ue.user_id and
ue.student_id = '#{student_id}' and ue.school_id= #{school_id}").first
course = Course.where(:id => course_id).first
@ -2955,16 +2955,17 @@ end
course_group = CourseGroup.where(:course_id => course.id, :name => group_name).first ||
CourseGroup.create(:name => group_name, :course_id => course.id) if group_name
member = course.course_members.where(:user_id => user.id, :role => 4).first
member = course.course_members.where(:user_id => user.id, :role => member_role).first
# 如果已是课堂成员且是学生身份and不在指定的分班则移动到该分班
if member.present? && member.course_group_id != course_group.try(:id).to_i
if member.present? && member.role == 4 && member.course_group_id != course_group.try(:id).to_i
member.update_column("course_group_id", course_group.try(:id).to_i)
member_count += 1
elsif !member.present?
member = CourseMember.new(:role => 4, :user_id => user.id)
member = CourseMember.new(:role => member_role, :user_id => user.id)
# if member_role == 10
# StudentsForCourse.create(:student_id => user.id, :course_id => course.id)
# end
extra = member_role == 2 ? 9 : (member_role == 3 ? 7 : 10)
Tiding.create(:user_id => user.id, :trigger_user_id => course.tea_id, :container_id => course.id, :container_type => 'TeacherJoinCourse',
:belong_container_id => course.id, :belong_container_type => "Course", :tiding_type => "System", :extra => member_role)
member.course_group_id = course_group.try(:id).to_i

@ -4,4 +4,82 @@ class CourseMember < ActiveRecord::Base
belongs_to :course, counter_cache: true
belongs_to :user
belongs_to :course_group, counter_cache: true
after_create :create_student_works, :create_exercise_users, :create_poll_users, :create_graduation_works
#加入班级时创建作业的作品
def create_student_works
if role == 4
course = self.course
str = ""
homeworks = course.homework_commons.includes(:homework_detail_manual).where("homework_type in (1, 3, 4)")
if homeworks.count != 0
homeworks.each do |hw|
str += "," if str != ""
str += "('#{hw.name}的作品提交',#{hw.id},#{user_id}, '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')"
end
if str != ""
sql = "insert into student_works (name, homework_common_id, user_id, created_at, updated_at) values" + str
ActiveRecord::Base.connection.execute sql
end
end
end
end
# 加入班级时创建已发布试卷的作品
def create_exercise_users
if role == 4
course = self.course
str = ""
exercises = course.exercises
if exercises.count != 0
exercises.each do |ex|
str += "," if str != ""
str += "(#{ex.id},#{user_id}, 0, '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')"
end
if str != ""
sql = "insert into exercise_users (exercise_id, user_id, commit_status, created_at, updated_at) values" + str
ActiveRecord::Base.connection.execute sql
end
end
end
end
# 加入班级时创建已发布问卷的作品
def create_poll_users
if role == 4
course = self.course
str = ""
polls = course.polls
if polls.count != 0
polls.each do |poll|
str += "," if str != ""
str += "(#{poll.id},#{user_id}, 0, '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')"
end
if str != ""
sql = "insert into poll_users (poll_id, user_id, commit_status, created_at, updated_at) values" + str
ActiveRecord::Base.connection.execute sql
end
end
end
end
# 创建毕设任务作品
def create_graduation_works
if role == 4
course = self.course
str = ""
tasks = course.graduation_tasks
if tasks.count != 0
tasks.each do |task|
str += "," if str != ""
str += "(#{task.id}, #{user_id}, #{course.id}, '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')"
end
if str != ""
sql = "insert into graduation_works (graduation_task_id, user_id, course_id, created_at, updated_at) values" + str
ActiveRecord::Base.connection.execute sql
end
end
end
end
end

Loading…
Cancel
Save