diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index db18566db..4af7d6644 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -558,6 +558,35 @@ class CoursesController < ApplicationController end end + def delete_member + member = @course.members.find params[:member_id] + student_role = member.member_roles.where("role_id = 10").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 + user_admin.destroy_all + end + joined = StudentsForCourse.where('student_id = ? and course_id = ?', member.user_id,@course.id) + joined.destroy_all + + if member.member_roles.count > 1 + student_role.destroy + member.update_attribute("course_group_id", 0) + else + member.destroy + end + #移出课程发送消息 + CourseMessage.create(:user_id => member.user_id, :course_id => @course.id, :course_message_type => "RemoveFromCourse", :viewed => false, :course_message_id => User.current.id) + + @course_groups = @course.course_groups + @no_group_count = @course.student.count - @course.members.where("course_group_id != 0").count + @canShowCode = isCourseTeacher(User.current.id,@course) + respond_to do |format| + format.js + end + end + end + def handle_course courses, activities course_activity_count_array=activities.values() course_array=[] @@ -800,11 +829,11 @@ class CoursesController < ApplicationController end if @course #发送微信消息 - count = ShieldWechatMessage.where("container_type='User' and container_id=#{User.current.id} and shield_type='Course' and shield_id=#{@course.id}").count - if count == 0 - ss = SyllabusesService.new - ss.send_wechat_create_class_notice User.current,@course - end + # count = ShieldWechatMessage.where("container_type='User' and container_id=#{User.current.id} and shield_type='Course' and shield_id=#{@course.id}").count + # if count == 0 + # ss = SyllabusesService.new + # ss.send_wechat_create_class_notice User.current,@course + # end respond_to do |format| flash[:notice] = l(:notice_successful_create) format.html {redirect_to course_url(@course)} diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index 0be18ea5c..5f0dbda97 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -337,7 +337,7 @@ class MembersController < ApplicationController else joined = StudentsForCourse.where('student_id = ? and course_id = ?', @member.user_id,@course.id) joined.each do |join| - join.delete + join.destroy end @member.course_group_id = 0 end @@ -423,7 +423,7 @@ class MembersController < ApplicationController end joined = StudentsForCourse.where('student_id = ? and course_id = ?', @member.user_id,@course.id) joined.each do |join| - join.delete + join.destroy end @roles = Role.givable.all[3..5] @members = @course.member_principals.includes(:roles, :principal).all.sort diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 8a5441647..f788efd3f 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -597,14 +597,14 @@ class StudentWorkController < ApplicationController @student_work_project.student_work_id = student_work.id @student_work_project.save elsif @homework.homework_detail_group.base_on_project == 0 - stu_project = StudentWorkProject.new(:homework_common_id => @homework.id, :student_work_id => student_work.id, :project_id => student_work.project_id, :user_id => student_work.user_id, :is_leader => 1) + stu_project = StudentWorkProject.new(:homework_common_id => @homework.id, :student_work_id => student_work.id, :project_id => student_work.project_id, :user_id => student_work.user_id, :is_leader => 1, :course_id => @homework.course_id) stu_project.save end members = params[:group_member_ids].split(',') for i in 1 .. members.count-1 stu_work = StudentWork.new(:name => student_work.name, :description => student_work.description,:user_id =>members[i].to_i, :homework_common_id => @homework.id,:project_id => student_work.project_id, :late_penalty => student_work.late_penalty,:work_status => 3, :commit_time => student_work.commit_time) if stu_work.save - stu_project = StudentWorkProject.new(:homework_common_id => @homework.id, :student_work_id => student_work.id, :project_id => stu_work.project_id == 0 ? -1 : stu_work.project_id, :user_id => members[i].to_i, :is_leader => 0) + stu_project = StudentWorkProject.new(:homework_common_id => @homework.id, :student_work_id => student_work.id, :project_id => stu_work.project_id == 0 ? -1 : stu_work.project_id, :user_id => members[i].to_i, :is_leader => 0, :course_id => @homework.course_id) stu_project.save end end @@ -662,7 +662,7 @@ class StudentWorkController < ApplicationController for i in 1 .. members.count-1 stu_work = StudentWork.new(:name => @work.name, :description => @work.description,:user_id=> members[i].to_i, :homework_common_id => @homework.id, :project_id => @work.project_id, :late_penalty => @work.late_penalty,:work_status => 3, :commit_time => @work.commit_time) if stu_work.save - stu_project = StudentWorkProject.new(:homework_common_id => @homework.id, :student_work_id => @work.id, :project_id => stu_work.project_id == 0 ? -1 : stu_work.project_id, :user_id => members[i].to_i, :is_leader => 0) + stu_project = StudentWorkProject.new(:homework_common_id => @homework.id, :student_work_id => @work.id, :project_id => stu_work.project_id == 0 ? -1 : stu_work.project_id, :user_id => members[i].to_i, :is_leader => 0, :course_id => @homework.course_id) stu_project.save end end @@ -1095,6 +1095,7 @@ class StudentWorkController < ApplicationController @project.project_id = params[:projectName].to_i @project.user_id = User.current.id @project.is_leader = 1 + @project.course_id = @homework.course_id if @project.save @user_activity_id = params[:user_activity_id].to_i @hw_status = params[:hw_status].to_i @@ -1180,7 +1181,7 @@ class StudentWorkController < ApplicationController unless work stu_work = StudentWork.new(:name => student_work.name, :description => student_work.description,:user_id =>params[:member_id][i].to_i, :homework_common_id => @homework.id,:project_id => student_work.project_id, :late_penalty => student_work.late_penalty,:work_status => 3, :commit_time => Time.now) if stu_work.save - stu_project = StudentWorkProject.new(:homework_common_id => @homework.id, :student_work_id => student_work.id, :project_id => stu_work.project_id == 0 ? -1 : stu_work.project_id, :user_id => params[:member_id][i].to_i, :is_leader => 0) + stu_project = StudentWorkProject.new(:homework_common_id => @homework.id, :student_work_id => student_work.id, :project_id => stu_work.project_id == 0 ? -1 : stu_work.project_id, :user_id => params[:member_id][i].to_i, :is_leader => 0, :course_id => @homework.course_id) stu_project.save end end diff --git a/app/controllers/watchers_controller.rb b/app/controllers/watchers_controller.rb index 304ba10a2..da0c5733a 100644 --- a/app/controllers/watchers_controller.rb +++ b/app/controllers/watchers_controller.rb @@ -125,7 +125,7 @@ class WatchersController < ApplicationController joined = StudentsForCourse.where('student_id = ? and course_id = ?', User.current.id, params[:object_id]) joined.each do |join| - join.delete + join.destroy end end respond_to do |format| diff --git a/app/controllers/words_controller.rb b/app/controllers/words_controller.rb index de232a423..e4b480e2f 100644 --- a/app/controllers/words_controller.rb +++ b/app/controllers/words_controller.rb @@ -102,7 +102,11 @@ class WordsController < ApplicationController @user_activity_id = params[:user_activity_id] if params[:user_activity_id] @activity = JournalsForMessage.where("id = #{params[:activity_id].to_i}").first if params[:activity_id] unless @activity - redirect_to feedback_path(@user) + if params[:user_activity_id] == params[:activity_id] + redirect_to feedback_path(@user) + else + redirect_to user_path(@user) + end return end elsif @journal_destroyed.jour_type == 'HomeworkCommon' diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 16bbe23e8..051d601de 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -2896,7 +2896,7 @@ module ApplicationHelper end #根据传入作业确定显示为编辑作品还是新建作品,或者显示作品数量 - def user_for_homework_common homework,is_teacher + def user_for_homework_common homework,is_teacher,work count = homework.student_works.has_committed.count if User.current.member_of_course?(homework.course) if is_teacher #老师显示作品数量 diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 37c4c037c..e97d32523 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -895,7 +895,7 @@ module CoursesHelper desc.html_safe end - # 学生按作业总分排序,取前3个 + # 学生按作业总分排序,取前6个 def hero_homework_score(course, score_sort_by) sql_select = "SELECT members.*,( SELECT SUM(work_score) @@ -907,14 +907,15 @@ module CoursesHelper FROM members JOIN students_for_courses ON students_for_courses.student_id = members.user_id AND students_for_courses.course_id = members.course_id - WHERE members.course_id = #{course.id} ORDER BY score #{score_sort_by} limit 3" + WHERE members.course_id = #{course.id} ORDER BY score #{score_sort_by} limit 6" homework_scores = Member.find_by_sql(sql_select) end def contributor_course_scor(course_id) - ccs = CourseContributorScore.find_by_sql("SELECT * FROM `course_contributor_scores` where course_id = #{course_id} order by - (message_num*2 + message_reply_num + news_reply_num + news_num + - resource_num*5 + journal_num + homework_journal_num ) desc limit 3;") + ccs = CourseContributorScore.find_by_sql("SELECT ccs.*, (message_num*2 + message_reply_num + news_reply_num + news_num + + resource_num*5 + journal_num + homework_journal_num ) as con_score FROM `course_contributor_scores` ccs JOIN students_for_courses sfs + ON sfs.student_id = ccs.user_id AND sfs.course_id = ccs.course_id where ccs.course_id = #{course_id} order by + con_score desc limit 6;") end #用户在该课程是否具有某个角色 diff --git a/app/models/course.rb b/app/models/course.rb index 13050ddbe..f974d0e93 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -49,6 +49,7 @@ class Course < ActiveRecord::Base #has_many :course_journals_for_messages, :class_name => 'CourseJournalsForMessage', :as => :jour, :dependent => :destroy has_many :news, :dependent => :destroy, :include => :author has_one :course_status, :class_name => "CourseStatus", :dependent => :destroy + has_many :student_work_projects, :dependent => :destroy has_many :homework_commons, :dependent => :destroy has_many :student_works, :through => :homework_commons, :dependent => :destroy diff --git a/app/models/students_for_course.rb b/app/models/students_for_course.rb index 6958cfe73..767d65b10 100644 --- a/app/models/students_for_course.rb +++ b/app/models/students_for_course.rb @@ -7,5 +7,13 @@ class StudentsForCourse < ActiveRecord::Base validates_presence_of :course_id, :student_id validates_uniqueness_of :student_id, :scope => :course_id - + + after_destroy :delete_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 + end end diff --git a/app/models/user.rb b/app/models/user.rb index 96f0c5c3b..85653feef 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -966,8 +966,12 @@ class User < Principal #是否具有老师角色 def has_teacher_role(course) member = course.members.where("user_id = #{self.id}").first - role = MemberRole.where("member_id = #{member.id} and role_id in (3, 7, 9)") - !role.blank? + if !member.nil? + role = MemberRole.where("member_id = #{member.id} and role_id in (3, 7, 9)") + !role.blank? + else + return false + end end #是否具有学生角色 @@ -992,6 +996,13 @@ class User < Principal # Admin users are authorized for anything else return true if admin? + course_ids = context.student_work_projects.blank? ? "(-1)" : "(" + context.student_work_projects.map{|swp| swp.course_id}.join(",") + ")" + courses = Course.where("id in #{course_ids}") + courses.each do |course| + if self.has_teacher_role(course) + return true + end + end roles = roles_for_project(context) return false unless roles roles.any? {|role| diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index 69864f226..f72623d84 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -207,7 +207,7 @@ class CoursesService unless member.role_ids.include?(10) joined = StudentsForCourse.where('student_id = ? and course_id = ?', member.user_id,c.id) joined.each do |join| - join.delete + join.destroy end end @@ -460,7 +460,7 @@ class CoursesService @member.first.destroy joined = StudentsForCourse.where('student_id = ? and course_id = ?', user.id, params[:object_id]) joined.each do |join| - join.delete + join.destroy end @state = 0 @state @@ -837,7 +837,7 @@ class CoursesService member = Member.new(:role_ids =>[7], :user_id => params[:user_id],:course_id=>params[:course_id]) joined = StudentsForCourse.where('student_id = ? and course_id = ?', member.user_id,course.id) joined.each do |join| - join.delete + join.destroy end member.course_group_id = 0 members << member @@ -858,7 +858,7 @@ class CoursesService end joined = StudentsForCourse.where('student_id = ? and course_id = ?', params[:user_id],params[:course_id]) joined.each do |join| - join.delete + join.destroy end end @@ -1261,7 +1261,7 @@ class CoursesService else joined = StudentsForCourse.where('student_id = ? and course_id = ?', params[:user_id],params[:id]) joined.each do |join| - join.delete + join.destroy end member.course_group_id = 0 end @@ -1305,7 +1305,7 @@ class CoursesService end joined = StudentsForCourse.where('student_id = ? and course_id = ?', member.user_id,course.id) joined.each do |join| - join.delete + join.destroy end roles = Role.givable.all[3..5] #移出课程发送消息 diff --git a/app/views/courses/_course_activity_users.html.erb b/app/views/courses/_course_activity_users.html.erb index 67ec2ede9..459f60f3d 100644 --- a/app/views/courses/_course_activity_users.html.erb +++ b/app/views/courses/_course_activity_users.html.erb @@ -23,11 +23,8 @@ 总得分为以上得分之和 <% contributor_course_scor(course.id).each do |contributor_score| %> - <% total_score = contributor_score.resource_num.to_i * 5 + contributor_score.message_num.to_i * 2 + - contributor_score.message_reply_num.to_i * 1 + contributor_score.journal_num.to_i * 1 + - + contributor_score.homework_journal_num.to_i * 1 + contributor_score.news_reply_num.to_i * 1 + - contributor_score.news_num.to_i * 1 %> - <% unless total_score ==0 %> + <% total_score = contributor_score.con_score %> + <% if !total_score.nil? && total_score !=0 %>
<%=link_to contributor_score.user.show_name, user_path(contributor_score.user.id), :title => contributor_score.user.show_name %>
diff --git a/app/views/courses/_new_member_list.html.erb b/app/views/courses/_new_member_list.html.erb index 7b59b2db6..d04e14cc8 100644 --- a/app/views/courses/_new_member_list.html.erb +++ b/app/views/courses/_new_member_list.html.erb @@ -1,8 +1,9 @@ +<% is_teacher = User.current.allowed_to?(:as_teacher, @course) || User.current.admin? %> <% if members.any? %>