diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 0bb027153..e3d7c9d06 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -561,6 +561,7 @@ class CoursesController < ApplicationController def delete_member member = @course.members.find params[:member_id] student_role = member.member_roles.where("role_id = 10").first + teacher_role = member.member_roles.where("role_id = 7 || role_id = 9").first if member && member.deletable? && student_role user_admin = CourseInfos.where("user_id = ? and course_id = ?", member.user_id, @course.id) if user_admin.size > 0 @@ -569,8 +570,9 @@ class CoursesController < ApplicationController joined = StudentsForCourse.where('student_id = ? and course_id = ?', member.user_id,@course.id) joined.destroy_all - if member.member_roles.count > 1 + if member.member_roles.count > 1&& student_role && teacher_role student_role.destroy + teacher_role.update_attribute("is_current", 1) member.update_attribute("course_group_id", 0) else member.destroy diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index c87cd3d42..3690df1f3 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -15,7 +15,7 @@ class HomeworkCommon < ActiveRecord::Base has_one :homework_detail_group, :dependent => :destroy has_many :student_work_projects, :dependent => :destroy has_many :homework_tests, :dependent => :destroy - has_many :student_works, :dependent => :destroy, :conditions => "is_test=0" + has_many :student_works, :dependent => :destroy, :conditions => "is_test=0 and is_delete != 1" has_many :student_works_evaluation_distributions, :through => :student_works #一个作业的分配的匿评列表 has_many :journals_for_messages, :as => :jour, :dependent => :destroy has_many :apply_homeworks, :dependent => :destroy diff --git a/app/models/students_for_course.rb b/app/models/students_for_course.rb index 767d65b10..d9bf96770 100644 --- a/app/models/students_for_course.rb +++ b/app/models/students_for_course.rb @@ -9,11 +9,21 @@ class StudentsForCourse < ActiveRecord::Base validates_uniqueness_of :student_id, :scope => :course_id after_destroy :delete_student_works + after_create :recovery_student_works + #退出班级或删除学生时隐藏学生的作品 def delete_student_works course = self.course homework_ids = course.homework_commons.blank? ? "(-1)" : "(" + course.homework_commons.map{|hw| hw.id}.join(",") + ")" student_works = StudentWork.where("user_id = #{self.student_id} && homework_common_id in #{homework_ids}") - student_works.destroy_all + student_works.update_all(:is_delete => 1) + end + + #加入班级时还原作品 + def recovery_student_works + course = self.course + homework_ids = course.homework_commons.blank? ? "(-1)" : "(" + course.homework_commons.map{|hw| hw.id}.join(",") + ")" + student_works = StudentWork.where("user_id = #{self.student_id} && homework_common_id in #{homework_ids}") + student_works.update_all(:is_delete => 0) end end diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index f72623d84..43bdf9e09 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -452,12 +452,20 @@ class CoursesService @state = 2 return @state end - @member = Member.where('course_id = ? and user_id = ?', params[:object_id], user.id) - if @member.nil? || @member.count == 0 + @member = Member.where('course_id = ? and user_id = ?', params[:object_id], user.id).first + if @member.nil? @state = 1 return @state end - @member.first.destroy + student_role = @member.member_roles.where("role_id = 10").first + teacher_role = @member.member_roles.where("role_id = 7 || role_id = 9").first + if @member.member_roles.count > 1 && student_role && teacher_role + student_role.destroy + teacher_role.update_attribute("is_current", 1) + @member.update_attribute("course_group_id", 0) + else + @member.destroy + end joined = StudentsForCourse.where('student_id = ? and course_id = ?', user.id, params[:object_id]) joined.each do |join| join.destroy diff --git a/app/views/courses/_set_join.js.erb b/app/views/courses/_set_join.js.erb index 822757dfe..7c395e54e 100644 --- a/app/views/courses/_set_join.js.erb +++ b/app/views/courses/_set_join.js.erb @@ -1,3 +1,4 @@ +hideModal(); <% if object_id && @state != 6%> $("#join_in_course_header").html("<%= escape_javascript(join_in_course_header(course, user)) %>"); <% end %> diff --git a/app/views/layouts/_course_base_info.html.erb b/app/views/layouts/_course_base_info.html.erb index e3041f92c..3b1c70fe8 100644 --- a/app/views/layouts/_course_base_info.html.erb +++ b/app/views/layouts/_course_base_info.html.erb @@ -26,6 +26,18 @@ +<% elsif User.current.logged? && User.current.member_of_course?(@course) %> +