diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 45a3f981b..56176119c 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -292,30 +292,79 @@ class CoursesController < ApplicationController end def teacher_assign_group - member = Member.where(:course_id => @course.id, :user_id => params[:user_id]).first - member.course_group_id = params[:course_group_id].to_i - member.save - @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) && params[:role] != '1' + @member = Member.where(:course_id => @course.id, :user_id => params[:user_id]).first + @member.course_group_id = params[:course_group_id].to_i + @member.save + if params[:group_id] && params[:group_id] != "-1" + @group = CourseGroup.find params[:group_id] + results = student_homework_score(@group.id,0,0,"desc") + @limit = 50 + @page = params[:page].nil? ? 1 : params['page'].to_i + @members_count = results.count + @mem_pages = Paginator.new @members_count, @limit, @page + @results = paginateHelper results, @limit + else + @course_groups = @course.course_groups + @no_group_count = @course.student.count - @course.members.where("course_group_id != 0").count + end + @canShowCode = isCourseTeacher(User.current.id,@course) respond_to do |format| format.js end end def join_group - @subPage_title = l :label_student_list group = CourseGroup.find(params[:object_id]) member = Member.where(:course_id => @course.id, :user_id => User.current.id).first member.course_group_id = group.id member.save @group = group - @course_groups = @course.course_groups - @no_group_count = @course.student.count - @course.members.where("course_group_id != 0").count - - search_group_members group + #@course_groups = @course.course_groups + #@no_group_count = @course.student.count - @course.members.where("course_group_id != 0").count + redirect_to group_member_course_path(@course, :group_id => @group.id) + #search_group_members group end + + #查找未分班的学生 + def search_not_group_member + @group = CourseGroup.find params[:group_id] + @search = params[:search] + q = params[:search] ? "#{params[:search].strip}" : "" + @members = [] + if q.nil? || q == "" + @course.members.includes(:user =>[:user_extensions =>[]]).where("course_group_id = 0").each do |m| + if m && m.user && m.user.join_in?(@course) + @members << m + end + end + else + @course.members.includes(:user =>[:user_extensions =>[]]).where("course_group_id = 0").each do |m| + username = m.user[:lastname].to_s.downcase + m.user[:firstname].to_s.downcase + if m && m.user && m.user.join_in?(@course) && (m.user[:login].to_s.downcase.include?(q) || m.user.user_extensions[:student_id].to_s.downcase.include?(q) || username.include?(q)) + @members << m + end + end + end + @is_search = params[:is_search] ? 1 : 0 + respond_to do |format| + format.js + end + end + + def add_members + @group = CourseGroup.find params[:group_id] + if @group && params[:chooseStudent] + params[:chooseStudent].each do |mem| + member = Member.find mem + if member && member.course == @course + member.update_attribute('course_group_id', @group.id) + end + end + redirect_to group_member_course_path(@course, :group_id => @group.id) + end + end + def unjoin_group @subPage_title = l :label_student_list group = CourseGroup.find(params[:object_id]) @@ -353,6 +402,28 @@ class CoursesController < ApplicationController @results = paginateHelper @results, @limit end + def group_member + @canShowCode = isCourseTeacher(User.current.id,@course) + @sort_type = 'score' + @score_sort_by = "desc" + if params[:group_id] && params[:group_id] != "0" && params[:group_id] != "-1" + @group = CourseGroup.find(params[:group_id]) + @results = student_homework_score(@group.id,0, 0,"desc") + else + page_from = params[:page].nil? ? 0 : (params[:page].to_i - 1) + @results = student_homework_score(0,page_from, 10,"desc") + end + @limit = 50 + @page = params[:page].nil? ? 1 : params['page'].to_i + @members_count = @results.count + @mem_pages = Paginator.new @members_count, @limit, @page + @results = paginateHelper @results, @limit + respond_to do |format| + format.html {render :layout => 'base_courses'} + format.js + end + end + def member ## 有角色参数的才是课程,没有的就是项目 if (User.current.admin? || @course.is_public == 1 || (@course.is_public == 0 && User.current.member_of_course?(@course))) @@ -399,7 +470,14 @@ class CoursesController < ApplicationController end def export_course_member_excel - @all_members = student_homework_score(0,0,0,"desc") + if params[:group_id] + group = CourseGroup.find params[:group_id] + unless group.nil? + @all_members = student_homework_score(@group.id,0,0,"desc") + end + else + @all_members = student_homework_score(0,0,0,"desc") + end @homeworks = @course.homework_commons.where("publish_time <= '#{Date.today}'").order("created_at asc") filename="#{@course.teacher.lastname.to_s + @course.teacher.firstname.to_s }_#{@course.name}_#{@course.time.to_s + @course.term}#{l(:excel_member_list)}"; @@ -486,6 +564,7 @@ class CoursesController < ApplicationController #添加成员消息状态 join_course_messages = CourseMessage.where("user_id =? and course_message_type =? and course_id =? and status = ? and viewed =?", User.current.id, 'JoinCourse', @course.id, 1, 0) join_course_messages.update_all(:viewed => true) + @tab = params[:tab].to_i || 0 if User.current.allowed_to?(:as_teacher,@course) @select_tab = params[:tab] @issue_custom_fields = IssueCustomField.sorted.all @@ -1366,14 +1445,16 @@ class CoursesController < ApplicationController #当加入,退出分班时查询分班的学生 def search_group_members group - @subPage_title = l :label_student_list @render_file = 'new_member_list' - @canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1' + @canShowCode = isCourseTeacher(User.current.id,@course) @is_remote = true @score_sort_by = "desc" - page_from = params[:page].nil? ? 0 : (params[:page].to_i - 1) @results = student_homework_score(group.id,0,0, "desc") - + @limit = 50 + @page = params[:page].nil? ? 1 : params['page'].to_i + @members_count = @results.count + @mem_pages = Paginator.new @members_count, @limit, @page + @results = paginateHelper @results, @limit end def member_to_xls homeworks, course, members,groups diff --git a/app/helpers/watchers_helper.rb b/app/helpers/watchers_helper.rb index 7f027009a..e978ad6a9 100644 --- a/app/helpers/watchers_helper.rb +++ b/app/helpers/watchers_helper.rb @@ -149,34 +149,14 @@ module WatchersHelper link_to text, url, :remote => true, :method => method, :id => "#{course.id}", :class => []+options end end - def join_in_course_group(coursegroups,group, user, options=[]) - return '' unless user && user.logged? + def join_in_course_group(course, group, user, options=[]) + return '' unless user && user.logged? && user.member_of_course?(course) + joined = user.member_of_course_group?(group) - @isjoin = false - coursegroups.each do |g| - g.members.each do |mem| - if mem.user_id == user.id - @isjoin = true - end - end - end - url_t = join_group_path(:object_id => group.id) - url_f = join_group_path(:object_id => group.id) - if @isjoin == true - joined = user.member_of_course_group?(group) - text = l(:label_exit_group) - - if joined - link_to text, {:controller => "courses", :action => "join_group", :object_id => "#{group.id}"}, - :remote => true, :method => 'delete', - :id => "#{group.id}", :style => "padding: 2px 8px 2px; background-color:#15bccf; color:#fff; ", - :confirm => l(:text_are_you_sure_out_group), :class => 'group_in' - - end - else - text = l(:label_new_join_group) - form_tag({:controller => "courses", :action => "join_group", :object_id => "#{group.id}"}, :remote => true, :method => 'post') do - submit_tag text, class: "group_in", style: "width: 90px;height: 21px; background-color:#15bccf; color:#fff;" + unless joined + text = l(:label_join_group) + form_tag({:controller => "courses", :action => "join_group", :object_id => "#{group.id}"},:id => 'join_coursegroup_form', :method => 'post') do + link_to text, 'javascript:void(0)', :class => 'sy_btn_green fl mr10', :onclick => "$('#join_coursegroup_form').submit();" end end end diff --git a/app/views/boards/_course_show.html.erb b/app/views/boards/_course_show.html.erb index 55d4cca62..9b63dcc88 100644 --- a/app/views/boards/_course_show.html.erb +++ b/app/views/boards/_course_show.html.erb @@ -24,6 +24,11 @@