|
|
#encoding: utf-8
|
|
|
class CoursesController < ApplicationController
|
|
|
# layout 'base_courses'
|
|
|
include CoursesHelper
|
|
|
include ActivitiesHelper
|
|
|
helper :activities
|
|
|
helper :members
|
|
|
helper :words
|
|
|
helper :attachments
|
|
|
helper :files
|
|
|
helper :activity_notifys
|
|
|
helper :graduation_tasks
|
|
|
include ApplicationHelper
|
|
|
helper SyllabusesHelper
|
|
|
|
|
|
before_filter :local_exam, :except => [:show, :index]
|
|
|
# before_filter :auth_login1, :only => [:show, :course_activity, :feedback]
|
|
|
if Redmine::Configuration['gitlab_address'].include?("test")
|
|
|
skip_before_filter :verify_authenticity_token, :only => [:update_course_module, :join_course_multi_role]
|
|
|
before_filter :require_login, :only => [:join, :unjoin]
|
|
|
else
|
|
|
skip_before_filter :verify_authenticity_token, :only => [:update_course_module]
|
|
|
before_filter :require_login, :only => [:join, :unjoin, :join_course_multi_role, :join_private_courses]
|
|
|
end
|
|
|
# before_filter :check_authentication, :except => [:update_course_module]
|
|
|
menu_item :overview
|
|
|
menu_item :feedback, :only => :feedback
|
|
|
menu_item :homework, :only => :homework
|
|
|
|
|
|
menu_item :new_homework, :only => :new_homework
|
|
|
|
|
|
menu_item l(:label_sort_by_time), :only => :index
|
|
|
menu_item l(:label_sort_by_active), :only => :index
|
|
|
menu_item l(:label_sort_by_influence), :only => :index
|
|
|
|
|
|
#before_filter :can_show_course, :except => []
|
|
|
before_filter :logged_user_by_apptoken,:only => [:show,:feedback]
|
|
|
before_filter :find_course, :except => [ :index, :search, :new, :join, :unjoin, :create, :new_join, :course, :join_private_courses, :join_course_multi_role, :unjoin_group, :search_course_list, :validate_copy_permission]
|
|
|
# before_filter :authorize_course, :only => [:show, :settings, :update, :course]
|
|
|
before_filter :authorize_course_global, :only => [:new,:create]
|
|
|
before_filter :toggleCourse, :only => [:finishcourse, :restartcourse]
|
|
|
before_filter :is_deleted, :only => [:show, :settings]
|
|
|
|
|
|
#before_filter :allow_join, :only => [:join]
|
|
|
require 'bundler/setup'
|
|
|
if RUBY_PLATFORM =~ /linux/
|
|
|
require 'simple_xlsx_reader'
|
|
|
require 'roo-xls'
|
|
|
end
|
|
|
# params[:search] 搜索课程的名称
|
|
|
# params[:select] "join" "create" "all" 参与的 创建的 所有的课程
|
|
|
#
|
|
|
def index
|
|
|
@user = User.current
|
|
|
@search = params[:search].nil? ? '' : params[:search]
|
|
|
@select = params[:select].nil? ? '' : params[:select]
|
|
|
# @is_over = params[:is_over] # 是否是新建课程页面跳转的查看归档
|
|
|
# @syllabuses_num = Course.count
|
|
|
# @my_courses_count = @user.courses.not_deleted_not_end.count
|
|
|
if params[:order].present?
|
|
|
@order = params[:order]
|
|
|
order_str = params[:order] == "members_count" ? "c.members_count" : (params[:order] == "created_at" ? "c.created_at" : "c.updated_at")
|
|
|
else
|
|
|
@order = "all"
|
|
|
end
|
|
|
# @hidden = params[:hidden] ? params[:hidden].to_i : 0
|
|
|
|
|
|
if params[:search].present?
|
|
|
user_ids = User.where("concat(lastname,firstname) = '#{@search}'").pluck(:id)
|
|
|
user_ids = user_ids.present? ? user_ids.join(",") : -1
|
|
|
course_ids = Course.where("courses.name like '%#{@search}%' or courses.tea_id in (#{user_ids})").pluck(:id)
|
|
|
end
|
|
|
|
|
|
# 页面筛选的课程
|
|
|
# join users 是为了过滤掉用户为nil的课堂
|
|
|
=begin
|
|
|
if @select == "private"
|
|
|
@courses = Course.find_by_sql("select c.id, c.tea_id, c.name, c.is_public, c.members_count, c.homework_commons_count, u.login, u.nickname, u.lastname, u.firstname, u.show_realname, ue.school_id from courses c, users u, user_extensions ue where c.tea_id = u.id and u.id = ue.user_id and c.is_delete = 0 and c.is_public = 0 #{course_ids == -1 ? "" : "and c.id in (#{course_ids})"} order by #{order_str} desc")
|
|
|
elsif @select == "public"
|
|
|
@courses = Course.find_by_sql("select c.id, c.tea_id, c.name, c.is_public, c.members_count, c.homework_commons_count, u.login, u.nickname, u.lastname, u.firstname, u.show_realname, ue.school_id from courses c, users u, user_extensions ue where c.tea_id = u.id and u.id = ue.user_id and c.is_delete = 0 and c.is_public = 1 #{course_ids == -1 ? "" : "and c.id in (#{course_ids})"} order by c.id = 1309 desc, #{order_str} desc")
|
|
|
else
|
|
|
# 全部课堂
|
|
|
@courses = Course.find_by_sql("select c.id, c.tea_id, c.name, c.is_public, c.members_count, c.homework_commons_count, u.login, u.nickname, u.lastname, u.firstname, u.show_realname, ue.school_id from courses c, users u, user_extensions ue where c.tea_id = u.id and u.id = ue.user_id and c.is_delete = 0 #{course_ids == -1 ? "" : "and c.id in (#{course_ids})"} order by c.id = 1309 desc, #{order_str} desc")
|
|
|
end
|
|
|
=end
|
|
|
|
|
|
if @order == "all"
|
|
|
course_ids = course_ids.present? ? course_ids.join(",") : -1
|
|
|
@courses = Course.where("courses.is_delete = 0 and courses.is_hidden = 0 #{course_ids == -1 ? "" : "and courses.id in (#{course_ids})"}").select("courses.id, courses.tea_id, courses.name, courses.is_public, courses.members_count, courses.homework_commons_count,(SELECT MAX(created_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("courses.id = 1309 desc, a desc")
|
|
|
elsif @order == "mine"
|
|
|
my_course_ids = Course.find_by_sql("SELECT c.id FROM courses c, members m, member_roles mr WHERE m.course_id = c.id AND m.id=mr.member_id AND mr.role_id in (3,7,9,10) AND m.user_id=#{@user.id} AND c.is_delete = 0")
|
|
|
course_ids = course_ids.present? ? my_course_ids.map(&:id) & course_ids : my_course_ids.map(&:id)
|
|
|
course_ids = course_ids.size > 0 ? course_ids.join(",") : "-1"
|
|
|
@courses = Course.find_by_sql("select c.id, c.tea_id, c.name, c.is_public, c.members_count, c.homework_commons_count, u.login, u.nickname, u.lastname, u.firstname, u.show_realname, ue.school_id from courses c, users u, user_extensions ue where c.tea_id = u.id and u.id = ue.user_id and c.is_delete = 0 and c.is_hidden = 0 and c.id in (#{course_ids}) order by c.id = 1309 desc, #{order_str} desc")
|
|
|
elsif @order == "created_at"
|
|
|
course_ids = course_ids.present? ? course_ids.join(",") : -1
|
|
|
@courses = Course.find_by_sql("select c.id, c.tea_id, c.name, c.is_public, c.members_count, c.homework_commons_count, u.login, u.nickname, u.lastname, u.firstname, u.show_realname, ue.school_id from courses c, users u, user_extensions ue where c.tea_id = u.id and u.id = ue.user_id and c.is_delete = 0 and c.is_hidden = 0 and c.is_end = 0 #{course_ids == -1 ? "" : "and c.id in (#{course_ids})"} order by c.id = 1309 desc, #{order_str} desc")
|
|
|
else
|
|
|
course_ids = course_ids.present? ? course_ids.join(",") : -1
|
|
|
@courses = Course.find_by_sql("select c.id, c.tea_id, c.name, c.is_public, c.members_count, c.homework_commons_count, u.login, u.nickname, u.lastname, u.firstname, u.show_realname, ue.school_id from courses c, users u, user_extensions ue where c.tea_id = u.id and u.id = ue.user_id and c.is_delete = 0 and c.is_hidden = 0 #{course_ids == -1 ? "" : "and c.id in (#{course_ids})"} order by c.id = 1309 desc, #{order_str} desc")
|
|
|
end
|
|
|
|
|
|
@courses = paginateHelper @courses, 16
|
|
|
|
|
|
respond_to do |format|
|
|
|
format.js
|
|
|
format.html { render :layout => "base_edu" }
|
|
|
end
|
|
|
end
|
|
|
|
|
|
def import_excel
|
|
|
attachments = params[:attachments]
|
|
|
attachments.each do |attachment|
|
|
|
attachment = Attachment.find_by_token_only(attachment[1]['token'])
|
|
|
attachment.container_id = @course.id
|
|
|
attachment.container_type = "ImportStudent"
|
|
|
attachment.save
|
|
|
end
|
|
|
@import_attachments = Attachment.where(:container_id => @course.id, :container_type => "ImportStudent")
|
|
|
end
|
|
|
|
|
|
def shixun_statistics
|
|
|
if params[:homework_id]
|
|
|
@homeworks = @course.homework_commons.where(:id => params[:homework_id])
|
|
|
else
|
|
|
@homeworks = @course.homework_commons.where("homework_type = 4 and publish_time < '#{Time.now}'").order("publish_time desc")
|
|
|
end
|
|
|
#filename="#{format_date(Time.now)}_#{@course.teacher.show_real_name.to_s}_#{@course.name}_实训数据报告";
|
|
|
filename="#{format_date(Time.now)}_#{@course.teacher.show_real_name.to_s}_#{@course.name}_#{@homeworks.first.name}_实训数据报告";
|
|
|
|
|
|
respond_to do |format|
|
|
|
format.xls {
|
|
|
send_data(shixun_xls(@homeworks,@course), :type => 'application/octet-stream', :filename => filename_for_content_disposition("#{filename}.xls"))
|
|
|
}
|
|
|
end
|
|
|
end
|
|
|
|
|
|
# REDO:性能需要优化,这块是管理员后台任务,不影响用户使用
|
|
|
def sync_students
|
|
|
# school_id = User.find(@course.tea_id).try(:user_extensions).try(:school_id)
|
|
|
school_id = nil
|
|
|
@import_attachments = Attachment.where(:container_id => @course.id, :container_type => "ImportStudent")
|
|
|
@had_import_count = 0
|
|
|
@list_count = 0
|
|
|
if @import_attachments.present?
|
|
|
@import_attachments.each do |attachment|
|
|
|
path = attachment.disk_directory
|
|
|
name = attachment.disk_filename
|
|
|
if name.split(".").last == "xls" || name.split(".").last == "xlsx"
|
|
|
lists = readData("files/#{path}/#{name}")
|
|
|
@list_count += lists.count
|
|
|
lists.each_with_index do |list, index|
|
|
|
logger.info("#{list[0]}---#{list[1]}---#{list[2]}")
|
|
|
if list[0]
|
|
|
if index == 0
|
|
|
school_id = list[1]
|
|
|
elsif index > 1
|
|
|
course_group = @course.course_groups.where(:name => list[2]).first
|
|
|
if !course_group && list[2]
|
|
|
course_group = CourseGroup.create(:name => list[2], :course_id => @course.id, :members_count => 0)
|
|
|
end
|
|
|
import_user = ImportCourseUser.new(:user_group_name => list[2], :user_name => list[1], :user_student_id => list[0], :course_id => @course.id, :school_id => school_id)
|
|
|
user = User.find_by_sql("SELECT u.* FROM `users` u, `user_extensions` ue where u.id = ue.user_id and ue.school_id='#{school_id}' and ue.student_id='#{list[0]}'").last
|
|
|
# 用户存在并且用户是非课程成员
|
|
|
if user.present?
|
|
|
member = Member.where(:course_id => @course, :user_id => user.id).first
|
|
|
if !member.present?
|
|
|
members = []
|
|
|
members << Member.new(:role_ids => [10], :user_id => user.id, :course_group_id => course_group ? course_group.id : 0)
|
|
|
@course.members << members
|
|
|
StudentsForCourse.create(:student_id => user.id, :course_id => @course.id)
|
|
|
elsif course_group && member.course_group_id != course_group.id
|
|
|
member.update_attributes(:course_group_id => course_group.id)
|
|
|
end
|
|
|
@had_import_count += 1
|
|
|
import_user.status = 1
|
|
|
end
|
|
|
import_user.save
|
|
|
end
|
|
|
end
|
|
|
end
|
|
|
attachment.destroy
|
|
|
end
|
|
|
end
|
|
|
end
|
|
|
# @members = @course.members.joins("join user_extensions on members.user_id = user_extensions.user_id").order("student_id asc").select{|m| m.roles.to_s.include?("Student")}
|
|
|
# @member_count = @members.count
|
|
|
# @limit = 20
|
|
|
# @is_remote = true
|
|
|
# @page = (params['page'] || 1).to_i
|
|
|
# @member_pages = Paginator.new @member_count, @limit, params['page'] || 1
|
|
|
# @offset ||= @member_pages.offset
|
|
|
# @members = paginateHelper @members,@limit
|
|
|
#
|
|
|
# @teacher_count = TeacherAndAssistantCount @course
|
|
|
# @student_count = studentCount(@course)
|
|
|
# @no_group_count = @course.members.where(:course_group_id => 0).select{|m| m.roles.to_s.include?("Student")}.count
|
|
|
end
|
|
|
|
|
|
def none_register_students
|
|
|
student_ids = UserExtensions.where(:user_id => @course.student.map(&:student_id)).map{|ue| ue.student_id if ue.student_id.present?}
|
|
|
student_ids = student_ids.empty? ? "(-1)" : "(" + student_ids.compact.join(",") + ")"
|
|
|
@import_users = @course.import_course_users.where("school_id = #{@course.teacher.try(:user_extensions).try(:school_id)} and user_student_id not in #{student_ids}")
|
|
|
@curr_page = '尚未注册学生列表'
|
|
|
render :layout => "base_edu_course"
|
|
|
end
|
|
|
|
|
|
def readData(xlsx)
|
|
|
doc = SimpleXlsxReader.open(xlsx)
|
|
|
sheet = doc.sheets.first
|
|
|
return sheet.rows
|
|
|
# sheet.rows.inject([]) { |l, row|
|
|
|
# if row.size >= 3 && row[1] && row[2]
|
|
|
# l << [row[1], row[2]]
|
|
|
# else
|
|
|
# l
|
|
|
# end
|
|
|
# }
|
|
|
end
|
|
|
|
|
|
# 邀请码停用/启用
|
|
|
def set_invite_code_halt
|
|
|
if User.current.allowed_to?(:as_teacher, @course) || User.current.admin?
|
|
|
@course.update_attribute('invite_code_halt', @course.invite_code_halt == 0 ? 1 : 0)
|
|
|
@course_group = @course.course_groups.where(:id => params[:group_id]).first if params[:group_id]
|
|
|
end
|
|
|
end
|
|
|
|
|
|
#查找组织
|
|
|
def search_public_orgs_not_in_course
|
|
|
condition = '%%'
|
|
|
if !params[:name].nil?
|
|
|
condition = "%#{params[:name].strip}%".gsub(" ","")
|
|
|
end
|
|
|
limit = 15
|
|
|
course_org_ids = OrgCourse.find_by_sql("select distinct organization_id from org_courses where course_id = #{params[:id]}").map(&:organization_id)
|
|
|
#@orgs_not_in_course = User.current.organizations.where("organizations.id not in (#{course_org_ids.join(',')}) and organizations.name like ?", condition).page(params[:page].to_i || 1).per(limit)
|
|
|
#@org_count = User.current.organizations.where("organizations.id not in (#{course_org_ids.join(',')}) and organizations.name like ?", condition).count
|
|
|
if course_org_ids.empty?
|
|
|
@orgs_not_in_course = User.current.organizations.where("name like ?",condition).page((params[:page].to_i || 1)).per(limit)
|
|
|
@org_count = @orgs_not_in_course.count
|
|
|
else
|
|
|
course_org_ids = "(" + course_org_ids.join(',') + ")"
|
|
|
@orgs_not_in_course = User.current.organizations.where("organizations.id not in #{course_org_ids} and organizations.name like ?", condition).page((params[:page].to_i || 1)).per(limit)
|
|
|
@org_count = @orgs_not_in_course.empty? ? 0 : @orgs_not_in_course.count
|
|
|
end
|
|
|
@course_count = Project.course_entities.visible.like(params[:name]).page(params[:page]).count
|
|
|
@orgs_page = Paginator.new @org_count, limit,params[:page]
|
|
|
@hint_flag = params[:hint_flag]
|
|
|
#render :json => {:orgs => @orgs_not_in_course, :count => @org_count}.to_json
|
|
|
respond_to do |format|
|
|
|
format.js
|
|
|
end
|
|
|
end
|
|
|
|
|
|
def join
|
|
|
if User.current.logged?
|
|
|
cs = CoursesService.new
|
|
|
@user = User.current
|
|
|
join = cs.join_course params,@user
|
|
|
@state = join[:state]
|
|
|
@course = join[:course]
|
|
|
# else
|
|
|
# @course = Course.find_by_id params[:object_id]
|
|
|
# CourseMessage.create(:user_id => @course.tea_id, :course_id => @course.id, :viewed => false,:content=> params[:role],:course_message_id=>User.current.id,:course_message_type=>'JoinCourseRequest')
|
|
|
# @state = 6
|
|
|
# end
|
|
|
else
|
|
|
@state = 5 #未登录
|
|
|
end
|
|
|
@object_id = @course.id if @course
|
|
|
respond_to do |format|
|
|
|
format.js #{ render :partial => 'set_join', :locals => {:user => @user, :course => @course, :object_id => params[:object_id]} }
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
def join_course_multi_role
|
|
|
=begin
|
|
|
if Redmine::Configuration['gitlab_address'].include?("test")
|
|
|
User.current = User.find(12)
|
|
|
end
|
|
|
=end
|
|
|
if User.current.logged?
|
|
|
cs = CoursesService.new
|
|
|
@user = User.current
|
|
|
join = cs.join_course_roles params,@user
|
|
|
@state = join[:state]
|
|
|
@course = join[:course]
|
|
|
if @state == 6 || @state == 13
|
|
|
# 给课堂老师发留言
|
|
|
if params[:role].include?("7") || params[:role].include?("9")
|
|
|
# notes = @user.show_real_name.to_s + " 申请以#{params[:role].include?('7') ? '教辅' : '教师'}的身份加入班级:<a target='_blank' href='#{members_course_path(@course)}'>#{@course.name}</a>"
|
|
|
@course.course_teachers.each do |mem|
|
|
|
Tiding.create(:user_id => mem.user_id, :trigger_user_id => User.current.id, :container_id => @course.id, :container_type => 'JoinCourse', :status => 0, :belong_container_id => @course.id, :belong_container_type => "Course", :tiding_type => "Apply", :extra => params[:role].include?("7") ? "7" : "9")
|
|
|
end
|
|
|
begin
|
|
|
user = User.where(:id => @course.tea_id).first
|
|
|
if user.phone.present?
|
|
|
status = Trustie::Sms.send(mobile: user.phone.to_s, send_type:'join_course_multi_role', user_name: user.show_name, name: @course.id)
|
|
|
end
|
|
|
rescue => e
|
|
|
Rails.logger.error "发送验证码出错: #{e}"
|
|
|
end
|
|
|
end
|
|
|
end
|
|
|
|
|
|
if @state == 0 || @state == 13
|
|
|
@course.course_teachers.each do |mem|
|
|
|
Tiding.create(:user_id => mem.user_id, :trigger_user_id => @user.id, :container_id => @course.id, :container_type => 'StudentJoinCourse', :belong_container_id => @course.id, :belong_container_type => "Course", :tiding_type => "System")
|
|
|
end
|
|
|
end
|
|
|
else
|
|
|
@state = 5 #未登录
|
|
|
end
|
|
|
@object_id = @course.id if @course
|
|
|
respond_to do |format|
|
|
|
format.js
|
|
|
format.json {
|
|
|
render json: {:state => @state, :course_id => @course.try(:id)}
|
|
|
}
|
|
|
end
|
|
|
end
|
|
|
|
|
|
def unjoin
|
|
|
if User.current.logged?
|
|
|
cs = CoursesService.new
|
|
|
cs.exit_course params,User.current
|
|
|
end
|
|
|
redirect_to user_path(User.current)
|
|
|
end
|
|
|
|
|
|
|
|
|
def join_private_courses
|
|
|
@invitation_code = params[:invitation_code]
|
|
|
respond_to do |format|
|
|
|
format.js
|
|
|
end
|
|
|
end
|
|
|
|
|
|
#更新课程信息
|
|
|
def update
|
|
|
cs = CoursesService.new
|
|
|
c = cs.edit_course params,@course,User.current
|
|
|
@course = c[:course]
|
|
|
if @course.errors.full_messages.count <= 0
|
|
|
respond_to do |format|
|
|
|
format.js
|
|
|
format.api { render_api_ok }
|
|
|
end
|
|
|
else
|
|
|
respond_to do |format|
|
|
|
format.js
|
|
|
format.api { render_validation_errors(@course) }
|
|
|
end
|
|
|
end
|
|
|
end
|
|
|
|
|
|
def new_join
|
|
|
@course = Course.find(params[:object_id])
|
|
|
respond_to do |format|
|
|
|
format.js
|
|
|
end
|
|
|
end
|
|
|
|
|
|
# 课程搜索
|
|
|
# add by nwb
|
|
|
def search
|
|
|
if params[:name].empty?
|
|
|
courses = Course.visible
|
|
|
@courses = paginateHelper courses,10
|
|
|
else
|
|
|
courses = Course.visible.where("LOWER(name) like '%#{params[:name].to_s.downcase}%'").order("time desc, created_at desc")
|
|
|
@courses = paginateHelper courses,10
|
|
|
end
|
|
|
@name = params[:name]
|
|
|
@type = 'courses'
|
|
|
respond_to do |format|
|
|
|
format.html {
|
|
|
render :layout => 'course_base'
|
|
|
}
|
|
|
format.atom {
|
|
|
courses = Course.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all
|
|
|
render_feed(courses, :title => "#{Setting.app_title}: #{l(:label_course_latest)}")
|
|
|
}
|
|
|
end
|
|
|
|
|
|
rescue Exception => e
|
|
|
if e.message == 'sumbit empty'
|
|
|
(redirect_to courses_url, :notice => l(:label_sumbit_empty);return)
|
|
|
end
|
|
|
end
|
|
|
|
|
|
def searchmembers
|
|
|
@subPage_title = l :label_student_list
|
|
|
@canShowCode = User.current.allowed_to?(:as_teacher,@course) && params[:role] != '1'
|
|
|
# @is_remote = true
|
|
|
@sort_type = 'score'
|
|
|
@score_sort_by = "desc"
|
|
|
@search_name = "#{params[:name].strip}"
|
|
|
q = "#{params[:name].strip}"
|
|
|
if params[:incourse]
|
|
|
results = searchmember_by_name(student_homework_score(0,0,0,"desc"), q)
|
|
|
elsif params[:ingroup]
|
|
|
if params[:search_group_id] == "-1"
|
|
|
@group = -1
|
|
|
results = searchmember_by_name(student_homework_score(-1,0,0,"desc"), q)
|
|
|
else
|
|
|
@group = CourseGroup.find(params[:search_group_id])
|
|
|
results = searchmember_by_name(student_homework_score(@group.id,0,0,"desc"), q)
|
|
|
end
|
|
|
end
|
|
|
@is_remote = true
|
|
|
#@result_count = results.count
|
|
|
#@results = paginateHelper results, 10
|
|
|
@results = results
|
|
|
@search_name = q
|
|
|
@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 addgroups
|
|
|
data = {:result=>1}
|
|
|
@subPage_title = l :label_student_list
|
|
|
if params[:group_name]
|
|
|
if @course.course_groups.where(:name => params[:group_name]).count > 0
|
|
|
data[:result] = 0
|
|
|
else
|
|
|
group = CourseGroup.new
|
|
|
group.name = params[:group_name]
|
|
|
group.course_id = @course.id
|
|
|
group.save
|
|
|
end
|
|
|
end
|
|
|
render :json => data
|
|
|
end
|
|
|
|
|
|
def deletegroup
|
|
|
data = {:result=>1}
|
|
|
group = CourseGroup.find params[:group_id]
|
|
|
if group
|
|
|
if group.members.count == 0
|
|
|
group.destroy
|
|
|
else
|
|
|
group.members.update_all(:course_group_id => 0)
|
|
|
group.destroy
|
|
|
end
|
|
|
end
|
|
|
render :json => data
|
|
|
end
|
|
|
|
|
|
def updategroupname
|
|
|
data = {:result=>1}
|
|
|
@subPage_title = l :label_student_list
|
|
|
if params[:group_name] && params[:group_id]
|
|
|
group = CourseGroup.find(params[:group_id])
|
|
|
if @course.course_groups.where("name = '#{params[:group_name]}' and id != #{params[:group_id]}").count > 0
|
|
|
data[:result] = 0
|
|
|
else
|
|
|
group.name = params[:group_name]
|
|
|
group.save
|
|
|
end
|
|
|
end
|
|
|
render :json => data
|
|
|
end
|
|
|
|
|
|
def choose_group_allow
|
|
|
@course.update_attributes(:choose_group_allow => !@course.choose_group_allow)
|
|
|
end
|
|
|
|
|
|
# 显示/隐藏课程"开源检索"的入口
|
|
|
def open_or_close_os_interface
|
|
|
os_status = @course.os_allow == 0 ? 1 : 0
|
|
|
@course.update_attribute(:os_allow, os_status)
|
|
|
respond_to do |format|
|
|
|
format.js
|
|
|
end
|
|
|
end
|
|
|
|
|
|
def valid_ajax
|
|
|
req = Hash.new(false)
|
|
|
req[:message] = ''
|
|
|
|
|
|
valid_attr = params[:valid]
|
|
|
valid_value = params[:value]
|
|
|
group_id = params[:group_id]
|
|
|
# faker = CourseGroup.new
|
|
|
|
|
|
if valid_attr.eql?('name')
|
|
|
course = Course.find params[:course_id]
|
|
|
group_names = course.course_groups.map{|group| group.name unless group.id.to_s == group_id}.select{|group| !group.nil?}
|
|
|
if group_names.include?(valid_value)
|
|
|
req[:valid] = false
|
|
|
req[:message] = l(:modal_valid_unpassing)
|
|
|
else
|
|
|
req[:valid] = true
|
|
|
req[:message] = l(:modal_valid_passing)
|
|
|
end
|
|
|
# faker.name = valid_value
|
|
|
# faker.course_id = params[:course_id]
|
|
|
# faker.valid?
|
|
|
# req[:valid] = faker.errors[:name].blank?
|
|
|
# req[:message] = faker.errors[:name]
|
|
|
end
|
|
|
# req[:message] = l(:modal_valid_passing) if req[:message].blank?
|
|
|
render :json => req
|
|
|
end
|
|
|
|
|
|
def delete_course_students
|
|
|
if params[:member_ids]
|
|
|
params[:member_ids].split(",").each do |member_id|
|
|
|
member = Member.find member_id
|
|
|
if member
|
|
|
ActiveRecord::Base.transaction do
|
|
|
if member.member_roles.count == 1
|
|
|
StudentsForCourse.where('student_id = ? and course_id = ?', member.user_id,@course.id).destroy_all
|
|
|
member.destroy
|
|
|
else
|
|
|
member.member_roles.where("role_id = 10").destroy_all
|
|
|
StudentsForCourse.where('student_id = ? and course_id = ?', member.user_id,@course.id).destroy_all
|
|
|
member.update_attributes(:course_group_id => 0)
|
|
|
member_role = member.member_roles.where("role_id = 7 or role_id = 9 or role_id = 3").first
|
|
|
member_role.update_attributes(:is_current => 1) if member_role.present?
|
|
|
end
|
|
|
end
|
|
|
end
|
|
|
end
|
|
|
end
|
|
|
respond_to do |format|
|
|
|
format.js
|
|
|
end
|
|
|
end
|
|
|
|
|
|
def teacher_assign_group
|
|
|
if params[:course_group_id] == '0'
|
|
|
@group = 0
|
|
|
else
|
|
|
@group = @course.course_groups.where(:id => params[:course_group_id].to_i).first
|
|
|
end
|
|
|
if params[:member_ids] && @group
|
|
|
params[:member_ids].each do |member_id|
|
|
|
member = Member.find member_id
|
|
|
@old_group = member.course_group
|
|
|
member.update_attributes(:course_group_id => params[:course_group_id].to_i) if member
|
|
|
end
|
|
|
end
|
|
|
respond_to do |format|
|
|
|
format.js
|
|
|
end
|
|
|
end
|
|
|
|
|
|
def join_group
|
|
|
group = CourseGroup.find(params[:group_id])
|
|
|
member = Member.where(:course_id => @course.id, :user_id => User.current.id).first
|
|
|
member.course_group_id = group.id
|
|
|
member.save
|
|
|
@group = group
|
|
|
|
|
|
respond_to do |format|
|
|
|
format.js
|
|
|
end
|
|
|
#@course_groups = @course.course_groups
|
|
|
#@no_group_count = @course.student.count - @course.members.where("course_group_id != 0").count
|
|
|
# redirect_to has_group_student_list_course_path(@course, :group_id => @group.id)
|
|
|
#search_group_members group
|
|
|
end
|
|
|
|
|
|
def change_manager
|
|
|
if params[:chooseteacher]
|
|
|
man_member = Member.where(:course_id => @course.id, :user_id => @course.tea_id).first
|
|
|
cha_member = Member.find params[:chooseteacher]
|
|
|
if man_member && cha_member
|
|
|
cha_member.member_roles.where("role_id = 9 || role_id = 7").first.update_attributes(:role_id => 3, :is_current => 1)
|
|
|
if cha_member.member_roles.where("role_id = 10").count > 0
|
|
|
cha_member.member_roles.where("role_id = 10").first.destroy
|
|
|
StudentsForCourse.where(:course_id => @course.id, :student_id => cha_member.user_id).destroy_all
|
|
|
end
|
|
|
@course.update_attributes(:tea_id => cha_member.user_id)
|
|
|
man_member.member_roles.first.update_attributes(:role_id => 9)
|
|
|
course_act = CourseActivity.where(:course_id => @course.id, :course_act_id => @course.id, :course_act_type => 'Course').first
|
|
|
course_act.update_column('user_id', cha_member.user_id)
|
|
|
UserActivity.where(:act_id => @course.id, :container_type => 'Course', :act_type => 'Course', :container_id => @course.id).first.update_column('user_id', cha_member.user_id)
|
|
|
=begin
|
|
|
ws = WechatService.new
|
|
|
title = "您已成为班级管理员"
|
|
|
ws.create_class_notice cha_member.user_id, "create_course_notice", @course.id,title, @course.name, man_member.user.show_name, @course.members.count, "点击查看班级详情。"
|
|
|
=end
|
|
|
end
|
|
|
end
|
|
|
end
|
|
|
|
|
|
def choose_graduation_group
|
|
|
if User.current.allowed_to?(:as_teacher, @course)
|
|
|
@member_ids = params[:member_ids]
|
|
|
@graduation_groups = @course.graduation_groups
|
|
|
@default_group_name = @graduation_groups.count == 0 ? "分组1" : "分组#{(@graduation_groups.count+1)}"
|
|
|
@page = params[:page]
|
|
|
else
|
|
|
render_403
|
|
|
end
|
|
|
end
|
|
|
|
|
|
def teacher_graduation_group
|
|
|
if User.current.admin? || User.current.allowed_to?(:as_teacher, @course)
|
|
|
if params[:graduation_group_name].strip != ""
|
|
|
graduation_group = @course.graduation_groups.where(:name => params[:graduation_group_name].strip).first
|
|
|
unless graduation_group.present?
|
|
|
graduation_group = @course.graduation_groups.new(:name => params[:graduation_group_name].strip, :user_id => User.current.id)
|
|
|
graduation_group.save
|
|
|
end
|
|
|
Member.where(:course_id => @course.id, :id => params[:member_ids].split(",")).update_all(:graduation_group_id => graduation_group.id)
|
|
|
end
|
|
|
redirect_to teachers_course_path(@course, :page => params[:page])
|
|
|
else
|
|
|
render_403
|
|
|
end
|
|
|
end
|
|
|
|
|
|
def switch_teacher_role
|
|
|
if User.current.admin? || User.current.has_teacher_role(@course)
|
|
|
member = @course.members.where(:id => params[:member_id]).first
|
|
|
if member.present?
|
|
|
member.member_roles.where(:role_id => params[:role].to_i == 7 ? 9 : 7).update_all(:role_id => params[:role])
|
|
|
end
|
|
|
redirect_to teachers_course_path(@course)
|
|
|
else
|
|
|
render_403
|
|
|
end
|
|
|
end
|
|
|
|
|
|
# 给教师分配管理权限
|
|
|
def assign_teacher_groups
|
|
|
status = 0
|
|
|
if params[:member_id] && params[:group_id] && params[:check]
|
|
|
member = @course.members.where(:id => params[:member_id]).first
|
|
|
course_group = @course.course_groups.where(:id => params[:group_id]).first
|
|
|
if member.present? && course_group.present?
|
|
|
teacher_group = member.teacher_course_groups.where(:course_group_id => params[:group_id])
|
|
|
if params[:check].to_i == 1
|
|
|
if teacher_group.count == 0
|
|
|
member.teacher_course_groups << TeacherCourseGroup.new(:user_id => member.user_id, :course_id => @course.id, :course_group_id => params[:group_id])
|
|
|
end
|
|
|
status = 1
|
|
|
elsif params[:check].to_i == 0
|
|
|
teacher_group.destroy_all
|
|
|
status = 1
|
|
|
end
|
|
|
end
|
|
|
end
|
|
|
render :json => {status: status}
|
|
|
end
|
|
|
|
|
|
def import_course_group
|
|
|
attachments = params[:attachments]
|
|
|
attachments.each do |attachment|
|
|
|
attachment = Attachment.find_by_token_only(attachment[1]['token'])
|
|
|
if attachment.present?
|
|
|
attachment.container_id = @course.id
|
|
|
attachment.container_type = "ImportCourseGroup"
|
|
|
attachment.save
|
|
|
end
|
|
|
end
|
|
|
|
|
|
new_atta = Attachment.where(:container_id => @course.id, :container_type => "ImportCourseGroup").last
|
|
|
if new_atta.present?
|
|
|
|
|
|
path = new_atta.disk_directory
|
|
|
name = new_atta.disk_filename
|
|
|
if name.split(".").last == "xls"
|
|
|
begin
|
|
|
xls = Roo::Spreadsheet.open("files/#{path}/#{name}",extension: :xls)
|
|
|
worksheet = xls.sheet(0)
|
|
|
rows = worksheet.last_row #最后一行数
|
|
|
if rows < 2
|
|
|
@status = 0
|
|
|
@message = "请按照模板格式导入"
|
|
|
else
|
|
|
group_count = 0
|
|
|
for row in 2 .. rows do
|
|
|
name = worksheet.cell(row, 1).to_s
|
|
|
# Rails.logger.info("-----user_id #{worksheet.cell(row, 1)}-------------group_name #{name}")
|
|
|
|
|
|
if @course.course_groups.where(:name => name).count == 0
|
|
|
@course.course_groups << CourseGroup.new(:name => name)
|
|
|
group_count += 1
|
|
|
end
|
|
|
end
|
|
|
@status = 1
|
|
|
@message = "已导入#{group_count}个分班"
|
|
|
end
|
|
|
rescue
|
|
|
@status = 0
|
|
|
@message = "无法完成导入,原因:文件内容无法读取"
|
|
|
end
|
|
|
else
|
|
|
@status = 0
|
|
|
@message = "无法完成导入,原因:文件类型错误(只支持.xls文件)"
|
|
|
end
|
|
|
new_atta.destroy
|
|
|
else
|
|
|
@status = 0
|
|
|
@message = "无法完成导入,原因:文件不存在"
|
|
|
end
|
|
|
end
|
|
|
|
|
|
def teachers
|
|
|
@search = params[:search]
|
|
|
q = params[:search] ? "#{params[:search].strip.downcase}" : ""
|
|
|
|
|
|
if @course.try(:id) != 1309 || User.current.admin? || User.current.try(:id) == 15582
|
|
|
@teachers = @course.members.includes(:roles, :user).where("roles.id in (3, 7, 9) and LOWER(concat(users.lastname, users.firstname)) LIKE '%#{q}%'")
|
|
|
else
|
|
|
@teachers = @course.members.includes(:roles, :user).where("(roles.id in (3, 7) or (members.user_id = #{User.current.id} and roles.id = 9)) and LOWER(concat(users.lastname, users.firstname)) LIKE '%#{q}%'")
|
|
|
end
|
|
|
|
|
|
@apply_users = CourseMessage.where(:course_id => @course.id,:course_message_type => 'JoinCourseRequest', :status => 0)
|
|
|
|
|
|
@is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin?
|
|
|
|
|
|
@has_graduation = @course.course_modules.where(:module_type => "graduation").first.try(:hidden).to_i == 0
|
|
|
|
|
|
@teachers_count = @teachers.size
|
|
|
@limit = 20
|
|
|
@page = params[:page] ? params[:page].to_i : 1
|
|
|
@teachers = paginateHelper @teachers, @limit
|
|
|
|
|
|
respond_to do |format|
|
|
|
format.js
|
|
|
format.html { render :layout => 'base_courses' }
|
|
|
end
|
|
|
end
|
|
|
|
|
|
def students
|
|
|
@order, @r_sort = params[:order] || "student_id", params[:sort] || "asc"
|
|
|
@sort = @r_sort == "desc" ? "asc" : "desc"
|
|
|
|
|
|
@is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin?
|
|
|
@search = params[:search]
|
|
|
q = params[:search] ? "#{params[:search].strip.downcase}" : ""
|
|
|
|
|
|
@group = params[:group_id].to_i if params[:group_id].present? && params[:group_id] != "undefined"
|
|
|
if @group
|
|
|
group_ids = "(#{params[:group_id]})"
|
|
|
else
|
|
|
group_ids = "(#{@course.course_groups.blank? ? 0 : @course.course_groups.map(&:id).join(",") + ",0"})"
|
|
|
end
|
|
|
=begin
|
|
|
if q.nil? || q == ""
|
|
|
@members = Member.find_by_sql("SELECT members.*,
|
|
|
(SELECT SUM(student_works.work_score)
|
|
|
FROM student_works,homework_commons
|
|
|
WHERE student_works.homework_common_id = homework_commons.id
|
|
|
AND homework_commons.homework_type IN (1, 3, 4)
|
|
|
AND homework_commons.course_id = #{@course.id}
|
|
|
AND student_works.user_id = members.user_id
|
|
|
) AS score,
|
|
|
(SELECT SUM(gw.work_score) FROM graduation_works gw,graduation_tasks gt WHERE gw.graduation_task_id = gt.id
|
|
|
AND gt.course_id = #{@course.id} AND gw.user_id = members.user_id) AS graduation_score,
|
|
|
(SELECT SUM(exercise_users.score) FROM exercise_users,exercises WHERE exercise_users.exercise_id = exercises.id
|
|
|
AND exercises.course_id = #{@course.id} AND exercise_users.user_id = members.user_id) AS ex_score,
|
|
|
(SELECT max(message_num) FROM course_contributor_scores AS ccs WHERE ccs.course_id = #{@course.id} AND ccs.user_id = members.user_id) AS message_num,
|
|
|
(SELECT max(message_reply_num) FROM course_contributor_scores AS ccs WHERE ccs.course_id = #{@course.id} AND ccs.user_id = members.user_id) AS message_reply_num,
|
|
|
(SELECT max(resource_num) FROM course_contributor_scores AS ccs WHERE ccs.course_id = #{@course.id} AND ccs.user_id = members.user_id) AS resource_num,
|
|
|
(SELECT max(homework_journal_num) FROM course_contributor_scores AS ccs WHERE ccs.course_id = #{@course.id} AND ccs.user_id = members.user_id) AS homework_journal_num,
|
|
|
(SELECT COUNT(gw.id) FROM graduation_works AS gw, graduation_tasks AS gt WHERE gw.graduation_task_id = gt.id AND gt.course_id = #{@course.id} AND gw.work_status != 0 AND gw.user_id = members.user_id) AS graduation_num,
|
|
|
(SELECT COUNT(ss.id) FROM student_works AS ss ,homework_commons AS hc WHERE ss.homework_common_id = hc.id AND hc.course_id = #{@course.id} AND ss.work_status != 0 AND ss.user_id = members.user_id) AS homework_num,
|
|
|
(SELECT COUNT(eu.id) FROM exercise_users AS eu,exercises WHERE eu.exercise_id = exercises.id AND exercises.course_id = #{@course.id} AND eu.commit_status = 1 AND eu.user_id = members.user_id) AS exercise_num,
|
|
|
(SELECT COUNT(pu.id) FROM poll_users AS pu, polls WHERE pu.poll_id = polls.id AND polls.course_id = #{@course.id} AND pu.commit_status = 1 AND pu.user_id = members.user_id) AS poll_num,
|
|
|
ue.student_id, CONCAT(u.lastname,u.firstname) AS username
|
|
|
FROM members, users u, user_extensions ue, students_for_courses sfc
|
|
|
WHERE sfc.student_id = members.user_id AND sfc.course_id = members.course_id AND members.`user_id`= u.id AND u.id = ue.user_id
|
|
|
AND members.course_id = #{@course.id} and members.course_group_id in #{group_ids}")
|
|
|
else
|
|
|
@members = Member.find_by_sql("SELECT members.*,
|
|
|
(SELECT SUM(student_works.work_score)
|
|
|
FROM student_works,homework_commons
|
|
|
WHERE student_works.homework_common_id = homework_commons.id
|
|
|
AND homework_commons.homework_type IN (1, 3, 4)
|
|
|
AND homework_commons.course_id = #{@course.id}
|
|
|
AND student_works.user_id = members.user_id
|
|
|
) AS score,
|
|
|
(SELECT SUM(gw.work_score) FROM graduation_works gw,graduation_tasks gt WHERE gw.graduation_task_id = gt.id
|
|
|
AND gt.course_id = #{@course.id} AND gw.user_id = members.user_id) AS graduation_score,
|
|
|
(SELECT SUM(exercise_users.score) FROM exercise_users,exercises WHERE exercise_users.exercise_id = exercises.id
|
|
|
AND exercises.course_id = #{@course.id} AND exercise_users.user_id = members.user_id) AS ex_score,
|
|
|
(SELECT max(message_num) FROM course_contributor_scores AS ccs WHERE ccs.course_id = #{@course.id} AND ccs.user_id = members.user_id) AS message_num,
|
|
|
(SELECT max(message_reply_num) FROM course_contributor_scores AS ccs WHERE ccs.course_id = #{@course.id} AND ccs.user_id = members.user_id) AS message_reply_num,
|
|
|
(SELECT max(resource_num) FROM course_contributor_scores AS ccs WHERE ccs.course_id = #{@course.id} AND ccs.user_id = members.user_id) AS resource_num,
|
|
|
(SELECT max(homework_journal_num) FROM course_contributor_scores AS ccs WHERE ccs.course_id = #{@course.id} AND ccs.user_id = members.user_id) AS homework_journal_num,
|
|
|
(SELECT COUNT(gw.id) FROM graduation_works AS gw, graduation_tasks AS gt WHERE gw.graduation_task_id = gt.id AND gt.course_id = #{@course.id} AND gw.work_status != 0 AND gw.user_id = members.user_id) AS graduation_num,
|
|
|
(SELECT COUNT(ss.id) FROM student_works AS ss ,homework_commons AS hc WHERE ss.homework_common_id = hc.id AND hc.course_id = #{@course.id} AND ss.work_status != 0 AND ss.user_id = members.user_id) AS homework_num,
|
|
|
(SELECT COUNT(eu.id) FROM exercise_users AS eu,exercises WHERE eu.exercise_id = exercises.id AND exercises.course_id = #{@course.id} AND eu.commit_status = 1 AND eu.user_id = members.user_id) AS exercise_num,
|
|
|
(SELECT COUNT(pu.id) FROM poll_users AS pu, polls WHERE pu.poll_id = polls.id AND polls.course_id = #{@course.id} AND pu.commit_status = 1 AND pu.user_id = members.user_id) AS poll_num,
|
|
|
ue.student_id, CONCAT(u.lastname,u.firstname) AS username
|
|
|
FROM members, users u, user_extensions ue, students_for_courses sfc
|
|
|
WHERE sfc.student_id = members.user_id AND sfc.course_id = members.course_id AND members.`user_id`= u.id AND u.id = ue.user_id
|
|
|
AND members.course_id = #{@course.id} and (ue.student_id like '%#{q}%' OR LOWER(CONCAT(u.lastname,u.firstname)) LIKE '%#{q}%')
|
|
|
and members.course_group_id in #{group_ids}")
|
|
|
end
|
|
|
@members.each do |member|
|
|
|
member[:course_score] = (member.score.nil? ? 0 : member.score) + (member.graduation_score.nil? ? 0 : member.graduation_score) + (member.ex_score.nil? ? 0 : member.ex_score)
|
|
|
end
|
|
|
=end
|
|
|
=begin
|
|
|
if @order == "student_id"
|
|
|
@r_sort == "desc" ? @members.sort! {|x,y| y[:student_id].to_s <=> x[:student_id].to_s} : @members.sort! {|x,y| x[:student_id].to_s <=> y[:student_id].to_s}
|
|
|
else
|
|
|
@r_sort == "desc" ? @members = @members.sort{|x,y| y[:course_score] <=> x[:course_score] } : @members = @members.sort{|x,y| x[:course_score] <=> y[:course_score] }
|
|
|
end
|
|
|
=end
|
|
|
@members = @course.members.where(:user_id => @course.student.pluck(:student_id)
|
|
|
).where("course_group_id in #{group_ids}").includes(:user => [:user_extensions]).
|
|
|
where("user_extensions.student_id like '%#{q}%' OR LOWER(CONCAT(users.lastname,users.firstname)) LIKE '%#{q}%'").reorder("user_extensions.student_id #{@r_sort}")
|
|
|
#分页
|
|
|
@member_count = @members.count
|
|
|
@all_member_ids = @members.map(&:id).join(",")
|
|
|
@limit = 20
|
|
|
@is_remote = true
|
|
|
@page = (params['page'] || 1).to_i
|
|
|
@member_pages = Paginator.new @member_count, @limit, @page
|
|
|
@offset ||= @member_pages.offset
|
|
|
@members = paginateHelper @members,@limit
|
|
|
|
|
|
@import_attachments = Attachment.where(:container_id => @course.id, :container_type => "ImportStudent") # 统计上传的Excel数量
|
|
|
if !@group.present?
|
|
|
@left_nav_type = 8
|
|
|
@group_name = @course.student_list
|
|
|
else
|
|
|
@left_nav_type = @group == 0 ? 9 : 10
|
|
|
if @group == 0
|
|
|
@group_name = "未分班"
|
|
|
else
|
|
|
@course_group = @course.course_groups.where(:id => @group).first
|
|
|
@group_name = @course_group.try(:name)
|
|
|
end
|
|
|
end
|
|
|
respond_to do |format|
|
|
|
format.js
|
|
|
format.html{render :layout => 'base_courses'}
|
|
|
end
|
|
|
end
|
|
|
|
|
|
def no_group_student_list
|
|
|
@order, @r_sort = params[:order] || "student_id", params[:sort] || "asc"
|
|
|
@sort = @r_sort == "desc" ? "asc" : "desc"
|
|
|
@is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin?
|
|
|
|
|
|
@search = params[:search]
|
|
|
q = params[:search] ? "#{params[:search].strip}" : ""
|
|
|
@members = Member.find_by_sql("SELECT members.*,(
|
|
|
SELECT SUM(student_works.work_score)
|
|
|
FROM student_works,homework_commons
|
|
|
WHERE student_works.homework_common_id = homework_commons.id
|
|
|
AND homework_commons.homework_type in (1, 3, 4)
|
|
|
AND homework_commons.course_id = #{@course.id}
|
|
|
AND student_works.user_id = members.user_id
|
|
|
) AS score,(SELECT SUM(exercise_users.score) FROM exercise_users,exercises WHERE exercise_users.exercise_id = exercises.id
|
|
|
AND exercises.course_id = #{@course.id} AND exercise_users.user_id = members.user_id) AS ex_score
|
|
|
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} AND members.course_group_id = 0")
|
|
|
# if @order == "student_id"
|
|
|
# @members = @course.members.where(:course_group_id => 0).joins("join user_extensions on members.user_id = user_extensions.user_id").order("student_id #{@sort}").select{|m| m.roles.to_s.include?("Student")}
|
|
|
# else
|
|
|
# @members = @course.members.where(:course_group_id => 0).joins("join users on members.user_id = users.id").order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@sort}, login #{@b_sort}").select{|m| m.roles.to_s.include?("Student")}
|
|
|
# end
|
|
|
if q.nil? || q == ""
|
|
|
else
|
|
|
members = []
|
|
|
@members.each do |m|
|
|
|
username = m.user[:lastname].to_s.downcase + m.user[:firstname].to_s.downcase
|
|
|
if m && m.user && (m.user.user_extensions[:student_id].to_s.downcase.include?(q) || username.include?(q))
|
|
|
members << m
|
|
|
end
|
|
|
end
|
|
|
@members = members
|
|
|
end
|
|
|
@members.each do |member|
|
|
|
member[:course_score] = (member.score.nil? ? 0 : member.score) + (member.ex_score.nil? ? 0 : member.ex_score)
|
|
|
end
|
|
|
@members = @members.sort{|x,y| y[:course_score] <=> x[:course_score] }
|
|
|
#分页
|
|
|
@member_count = @members.count
|
|
|
@all_member_ids = @members.map(&:id).join(",")
|
|
|
@limit = 20
|
|
|
@is_remote = true
|
|
|
@page = (params['page'] || 1).to_i
|
|
|
@member_pages = Paginator.new @member_count, @limit, params['page'] || 1
|
|
|
@offset ||= @member_pages.offset
|
|
|
@members = paginateHelper @members,@limit
|
|
|
|
|
|
# @teacher_count = TeacherAndAssistantCount @course
|
|
|
if @course.try(:id) != 1309 || User.current.admin? || User.current.try(:id) == 15582
|
|
|
@teacher_count = @course.members.includes(:roles, :user).where("roles.id" => [3,7,9]).count
|
|
|
else
|
|
|
@teacher_count = @course.members.includes(:roles, :user).where("roles.id" => [3,7]).count
|
|
|
end
|
|
|
@student_count = studentCount(@course)
|
|
|
@no_group_count = @course.members.where(:course_group_id => 0).select{|m| m.roles.to_s.include?("Student")}.count
|
|
|
@left_nav_type = 9
|
|
|
respond_to do |format|
|
|
|
format.js
|
|
|
format.html{render :layout => 'base_courses'}
|
|
|
end
|
|
|
end
|
|
|
|
|
|
def has_group_student_list
|
|
|
#@order, @r_sort = params[:order] || "student_id", params[:sort] || "asc"
|
|
|
#@sort = @r_sort == "desc" ? "asc" : "desc"
|
|
|
|
|
|
@search = params[:search]
|
|
|
q = params[:search] ? "#{params[:search].strip}" : ""
|
|
|
@group = @course.course_groups.find params[:group_id]
|
|
|
@members = Member.find_by_sql("SELECT members.*,(
|
|
|
SELECT SUM(student_works.work_score)
|
|
|
FROM student_works,homework_commons
|
|
|
WHERE student_works.homework_common_id = homework_commons.id
|
|
|
AND homework_commons.homework_type in (1, 3, 4)
|
|
|
AND homework_commons.course_id = #{@course.id}
|
|
|
AND student_works.user_id = members.user_id
|
|
|
) AS score,(SELECT SUM(exercise_users.score) FROM exercise_users,exercises WHERE exercise_users.exercise_id = exercises.id
|
|
|
AND exercises.course_id = #{@course.id} AND exercise_users.user_id = members.user_id) AS ex_score
|
|
|
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} AND members.course_group_id = #{@group.id}")
|
|
|
# if @order == "student_id"
|
|
|
# @members = @course.members.where(:course_group_id => @group.id).joins("join user_extensions on members.user_id = user_extensions.user_id").select{|m| m.roles.to_s.include?("Student")}.reorder("student_id #{@sort}")
|
|
|
# else
|
|
|
# @members = @course.members.where(:course_group_id => @group.id).joins("join users on members.user_id = users.id").select{|m| m.roles.to_s.include?("Student")}.reorder("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@sort}, login #{@b_sort}")
|
|
|
# end
|
|
|
if q.nil? || q == ""
|
|
|
else
|
|
|
members = []
|
|
|
@members.each do |m|
|
|
|
username = m.user[:lastname].to_s.downcase + m.user[:firstname].to_s.downcase
|
|
|
if m && m.user && (m.user.user_extensions[:student_id].to_s.downcase.include?(q) || username.include?(q))
|
|
|
members << m
|
|
|
end
|
|
|
end
|
|
|
@members = members
|
|
|
end
|
|
|
@members.each do |member|
|
|
|
member[:course_score] = (member.score.nil? ? 0 : member.score) + (member.ex_score.nil? ? 0 : member.ex_score)
|
|
|
end
|
|
|
@members = @members.sort{|x,y| y[:course_score] <=> x[:course_score] }
|
|
|
@is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin?
|
|
|
#分页
|
|
|
@member_count = @members.count
|
|
|
@all_member_ids = @members.map(&:id).join(",")
|
|
|
@limit = 20
|
|
|
@is_remote = true
|
|
|
@page = (params['page'] || 1).to_i
|
|
|
@member_pages = Paginator.new @member_count, @limit, params['page'] || 1
|
|
|
@offset ||= @member_pages.offset
|
|
|
@members = paginateHelper @members,@limit
|
|
|
|
|
|
# @teacher_count = TeacherAndAssistantCount @course
|
|
|
if @course.try(:id) != 1309 || User.current.admin? || User.current.try(:id) == 15582
|
|
|
@teacher_count = @course.members.includes(:roles, :user).where("roles.id" => [3,7,9]).count
|
|
|
else
|
|
|
@teacher_count = @course.members.includes(:roles, :user).where("roles.id" => [3,7]).count
|
|
|
end
|
|
|
@student_count = studentCount(@course)
|
|
|
@no_group_count = @course.members.where(:course_group_id => 0).select{|m| m.roles.to_s.include?("Student")}.count
|
|
|
@left_nav_type = 10
|
|
|
|
|
|
respond_to do |format|
|
|
|
format.js
|
|
|
format.html{render :layout => 'base_courses'}
|
|
|
end
|
|
|
end
|
|
|
|
|
|
def choose_course_group
|
|
|
@member_ids = params[:member_ids].split(",")
|
|
|
if params[:group_id]
|
|
|
@groups = @course.course_groups.where("id != #{params[:group_id]}").order("name asc")
|
|
|
else
|
|
|
@groups = @course.course_groups.order("name asc")
|
|
|
end
|
|
|
@group_id = params[:group_id]
|
|
|
respond_to do |format|
|
|
|
format.js
|
|
|
end
|
|
|
end
|
|
|
|
|
|
def search_course_teacher_list
|
|
|
q = params[:search] ? "#{params[:search].strip}" : ""
|
|
|
@members = searchTeacherAndAssistantNoManager(@course)
|
|
|
if q.nil? || q == ""
|
|
|
else
|
|
|
members = []
|
|
|
@members.each do |m|
|
|
|
username = m.user[:lastname].to_s.downcase + m.user[:firstname].to_s.downcase
|
|
|
if m && m.user && (m.user[:login].to_s.downcase.include?(q) || m.user[:mail].to_s.downcase.include?(q) || username.include?(q))
|
|
|
members << m
|
|
|
end
|
|
|
end
|
|
|
@members = members
|
|
|
end
|
|
|
end
|
|
|
|
|
|
#查找未分班的学生
|
|
|
def search_not_group_member
|
|
|
@group = CourseGroup.find params[:group_id]
|
|
|
@search = params[:search]
|
|
|
q = params[:search] ? "#{params[:search].strip}" : ""
|
|
|
@members = []
|
|
|
@members = @course.members.where("course_group_id = 0").joins("join user_extensions on members.user_id = user_extensions.user_id").order("student_id asc").select{|m| m.roles.to_s.include?("Student")}
|
|
|
if q.nil? || q == ""
|
|
|
else
|
|
|
members = []
|
|
|
@members.each do |m|
|
|
|
username = m.user[:lastname].to_s.downcase + m.user[:firstname].to_s.downcase
|
|
|
if m && m.user && (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
|
|
|
@members = members
|
|
|
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[:group_id])
|
|
|
member = Member.find params[:member]
|
|
|
@user = member.user
|
|
|
member.course_group_id = 0
|
|
|
member.save
|
|
|
@group = group
|
|
|
@course = @group.course
|
|
|
@teacher_count = searchTeacherAndAssistant(@course).count
|
|
|
@student_count = @course.student.count
|
|
|
@no_group_count = @course.members.where("course_group_id = 0").select{|m| m.roles.to_s.include?("Student")}.count
|
|
|
end
|
|
|
|
|
|
def searchgroupmembers
|
|
|
@subPage_title = l :label_student_list
|
|
|
@render_file = 'new_member_list'
|
|
|
@canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1'
|
|
|
@is_remote = true
|
|
|
@sort_type = 'score'
|
|
|
@score_sort_by = "desc"
|
|
|
@search_name = ""
|
|
|
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")
|
|
|
# @results = paginateHelper @results, 10
|
|
|
elsif params[:group_id] && params[:group_id] == "-1"
|
|
|
@group = -1
|
|
|
@results = student_homework_score(-1, 0, 10,"desc")
|
|
|
else
|
|
|
page_from = params[:page].nil? ? 0 : (params[:page].to_i - 1)
|
|
|
@results = student_homework_score(0,page_from, 10,"desc")
|
|
|
end
|
|
|
@no_group_count = @course.members.where(:course_group_id => 0).select{|m| m.roles.to_s.include?("Student")}.count
|
|
|
@course_groups = @course.course_groups
|
|
|
@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 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.member_of_course?(@course) || User.current.admin?
|
|
|
# 当前用户查看班级消息时,设置消息为已读
|
|
|
update_messsages_to_viewed("CourseMessage", @course)
|
|
|
## 有角色参数的才是课程,没有的就是项目
|
|
|
@order, @r_sort = params[:order] || "student_id", params[:sort] || "asc"
|
|
|
@sort = @r_sort == "desc" ? "asc" : "desc"
|
|
|
|
|
|
@search = params[:search]
|
|
|
q = params[:search] ? "#{params[:search].strip}" : ""
|
|
|
if params[:role] == 't'
|
|
|
@members = searchTeacherAndAssistant(@course)
|
|
|
elsif params[:role] == 'as'
|
|
|
if @order == "student_id"
|
|
|
@members = @course.members.joins("join user_extensions on members.user_id = user_extensions.user_id").order("student_id #{@sort}").select{|m| m.roles.to_s.include?("Student")}
|
|
|
else
|
|
|
@members = @course.members.joins("join users on members.user_id = users.id").order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@sort}, login #{@b_sort}").select{|m| m.roles.to_s.include?("Student")}
|
|
|
end
|
|
|
elsif params[:role] == 'ns'
|
|
|
if @order == "student_id"
|
|
|
@members = @course.members.where(:course_group_id => 0).joins("join user_extensions on members.user_id = user_extensions.user_id").order("student_id #{@sort}").select{|m| m.roles.to_s.include?("Student")}
|
|
|
else
|
|
|
@members = @course.members.where(:course_group_id => 0).joins("join users on members.user_id = users.id").order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@sort}, login #{@b_sort}").select{|m| m.roles.to_s.include?("Student")}
|
|
|
end
|
|
|
else
|
|
|
@group = @course.course_groups.find params[:role]
|
|
|
if @order == "student_id"
|
|
|
@members = @course.members.where(:course_group_id => @group.id).joins("join user_extensions on members.user_id = user_extensions.user_id").order("student_id #{@sort}").select{|m| m.roles.to_s.include?("Student")}
|
|
|
else
|
|
|
@members = @course.members.where(:course_group_id => @group.id).joins("join users on members.user_id = users.id").order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@sort}, login #{@b_sort}").select{|m| m.roles.to_s.include?("Student")}
|
|
|
end
|
|
|
end
|
|
|
|
|
|
if q.nil? || q == ""
|
|
|
else
|
|
|
members = []
|
|
|
@members.each do |m|
|
|
|
username = m.user[:lastname].to_s.downcase + m.user[:firstname].to_s.downcase
|
|
|
if m && m.user && (m.user.user_extensions[:student_id].to_s.downcase.include?(q) || username.include?(q))
|
|
|
members << m
|
|
|
end
|
|
|
end
|
|
|
@members = members
|
|
|
end
|
|
|
#分页
|
|
|
@member_count = @members.count
|
|
|
@limit = 20
|
|
|
@is_remote = true
|
|
|
@page = (params['page'] || 1).to_i
|
|
|
@member_pages = Paginator.new @member_count, @limit, params['page'] || 1
|
|
|
@offset ||= @member_pages.offset
|
|
|
@members = paginateHelper @members,@limit
|
|
|
|
|
|
@teacher_count = TeacherAndAssistantCount @course
|
|
|
@student_count = studentCount(@course)
|
|
|
@no_group_count = @course.members.where(:course_group_id => 0).select{|m| m.roles.to_s.include?("Student")}.count
|
|
|
|
|
|
respond_to do |format|
|
|
|
if @search
|
|
|
format.js
|
|
|
else
|
|
|
format.html {render :layout => 'base_edu'}
|
|
|
format.js
|
|
|
end
|
|
|
end
|
|
|
else
|
|
|
render_403
|
|
|
end
|
|
|
end
|
|
|
|
|
|
def export_course_member_excel
|
|
|
q = params[:name] ? "#{params[:name].strip}" : ""
|
|
|
filename="#{@course.teacher.show_real_name.to_s }_#{@course.name}_#{l(:excel_member_list)}";
|
|
|
if params[:group_id] && params[:group_id] != "0" && params[:group_id] != "-1"
|
|
|
group = CourseGroup.find params[:group_id]
|
|
|
unless group.nil?
|
|
|
@all_members = searchmember_by_name(student_homework_score(group.id,0,0,"desc"), q)
|
|
|
filename="#{@course.teacher.show_real_name.to_s }_#{@course.name}_#{group.name}_#{l(:excel_member_list)}"
|
|
|
end
|
|
|
elsif params[:group_id] && params[:group_id] == "0"
|
|
|
@all_members = searchmember_by_name(student_homework_score(-1, 0, 10,"desc"), q)
|
|
|
filename="#{@course.teacher.show_real_name.to_s }_#{@course.name}_未分班_#{l(:excel_member_list)}"
|
|
|
else
|
|
|
@all_members = searchmember_by_name(student_homework_score(0, 0, 10,"desc"), q)
|
|
|
end
|
|
|
|
|
|
@homeworks = @course.homework_commons.where("publish_time <= '#{Time.now}'").order("publish_time asc, created_at asc")
|
|
|
@exercises = @course.exercises.where("publish_time <= '#{Time.now}'").order("publish_time asc, created_at asc")
|
|
|
@tasks = @course.graduation_tasks.where("publish_time <= '#{Time.now}'").order("publish_time asc, created_at asc")
|
|
|
|
|
|
@homeworks.where(:homework_type => 4).each do |homework|
|
|
|
items = homework.student_works.where("work_status != 0")
|
|
|
if items.count == 0 && homework.publish_time < Time.now && !@course.is_end
|
|
|
update_shixun_work_status homework
|
|
|
end
|
|
|
end
|
|
|
|
|
|
respond_to do |format|
|
|
|
format.xls {
|
|
|
send_data(member_to_xls(@homeworks, @exercises, @tasks, @course,@all_members,@course.course_groups), :type => "text/excel;charset=utf-8; header=present",
|
|
|
:filename => filename_for_content_disposition("#{filename}.xls"))
|
|
|
}
|
|
|
end
|
|
|
end
|
|
|
|
|
|
def member_score_sort
|
|
|
@canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1'
|
|
|
@subPage_title = l :label_student_list
|
|
|
@render_file = 'new_member_list'
|
|
|
@is_remote = true
|
|
|
@sort_type = params[:sort_type] if params[:sort_type]
|
|
|
@score_sort_by = params[:sort_by] if params[:sort_by]
|
|
|
@search_name = params[:search_name] if params[:search_name]
|
|
|
group_id = params[:group_id]
|
|
|
if !@search_name.nil?
|
|
|
if group_id == '0'
|
|
|
#page = params[:page].nil? ? 0 : (params['page'].to_i - 1)
|
|
|
@results = searchmember_by_name(student_homework_score(0,0,0,@score_sort_by,@sort_type), @search_name)
|
|
|
# @results = paginateHelper @results, 10
|
|
|
elsif group_id == '-1'
|
|
|
@group = -1
|
|
|
@results = searchmember_by_name(student_homework_score(-1,0,0,@score_sort_by,@sort_type), @search_name)
|
|
|
else
|
|
|
@group = CourseGroup.find(group_id)
|
|
|
@results = searchmember_by_name(student_homework_score(group_id, 0, 0,@score_sort_by,@sort_type),@search_name)
|
|
|
# @results = paginateHelper @results, 10
|
|
|
end
|
|
|
else
|
|
|
if group_id == '0'
|
|
|
page = params[:page].nil? ? 0 : (params['page'].to_i - 1)
|
|
|
@results = student_homework_score(0,page, 10,@score_sort_by,@sort_type)
|
|
|
elsif group_id == '-1'
|
|
|
@group = -1
|
|
|
@results = student_homework_score(-1,0, 10,@score_sort_by,@sort_type)
|
|
|
else
|
|
|
@group = CourseGroup.find(group_id)
|
|
|
@results = student_homework_score(group_id, 0, 0,@score_sort_by,@sort_type)
|
|
|
end
|
|
|
end
|
|
|
@limit = 50
|
|
|
@page = params[:page].nil? ? 1 : params['page'].to_i
|
|
|
@members_count = @results.count
|
|
|
@no_group_count = @course.members.where(:course_group_id => 0).select{|m| m.roles.to_s.include?("Student")}.count
|
|
|
@mem_pages = Paginator.new @members_count, @limit, @page
|
|
|
@results = paginateHelper @results, @limit
|
|
|
end
|
|
|
# 显示每个学生的作业评分详情
|
|
|
def show_member_score
|
|
|
@member_score = Member.find(params[:member_id]) if params[:member_id]
|
|
|
respond_to do |format|
|
|
|
format.html {render :layout => 'course_base'}
|
|
|
format.js
|
|
|
end
|
|
|
end
|
|
|
|
|
|
# 显示每个学生的作业评分详情
|
|
|
def show_member_act_score
|
|
|
@member = Member.find(params[:member_id]) if params[:member_id]
|
|
|
respond_to do |format|
|
|
|
format.html {render :layout => 'course_base'}
|
|
|
format.js
|
|
|
end
|
|
|
end
|
|
|
|
|
|
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
|
|
|
|
|
|
joined = StudentsForCourse.where('student_id = ? and course_id = ?', member.user_id,@course.id)
|
|
|
joined.destroy_all
|
|
|
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
|
|
|
|
|
|
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
|
|
|
#移出课程发送消息
|
|
|
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.members.where(:course_group_id => 0).select{|m| m.roles.to_s.include?("Student")}.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=[]
|
|
|
i=0;
|
|
|
courses.each do |course|
|
|
|
course_array[i]=course
|
|
|
i=i+1
|
|
|
end
|
|
|
courses=desc_sort_course_by_avtivity(course_activity_count_array, course_array)
|
|
|
return courses
|
|
|
end
|
|
|
|
|
|
def settings
|
|
|
if User.current.allowed_to?(:as_teacher,@course)
|
|
|
@board = @course.boards.where(:parent_id => 0).first
|
|
|
@course_boards = @board.children.reorder("position asc")
|
|
|
@tab = params[:tab] ? params[:tab].to_i : 1
|
|
|
@curr_page = "设置"
|
|
|
respond_to do |format|
|
|
|
format.html { render :layout => 'base_edu_course' }
|
|
|
format.api { render_validation_errors(@course) }
|
|
|
end
|
|
|
else
|
|
|
render_403
|
|
|
end
|
|
|
end
|
|
|
|
|
|
def update_course_module
|
|
|
|
|
|
course_modules = @course.course_modules
|
|
|
course_modules.where(:module_type => 'activity').first.update_attributes(:module_name => params[:name][0])
|
|
|
|
|
|
for i in 1..9
|
|
|
course_module = course_modules.where(:module_type => params[:position][i]).first
|
|
|
if course_module.present?
|
|
|
course_module.update_attributes(:position => i+1, :module_name => params[:name][i] == "" ? course_module.default_module_name : params[:name][i])
|
|
|
end
|
|
|
end
|
|
|
|
|
|
# params[:message] 有值 就更行字段: 0为不隐藏,1为隐藏
|
|
|
type = ["shixun_homework", "common_homework", "group_homework", "graduation", "exercise", "poll", "attachment", "board", "course_group"]
|
|
|
|
|
|
hidden = type - params[:message]
|
|
|
course_modules.where(:module_type => params[:message]).update_all(:hidden => 0)
|
|
|
course_modules.where(:module_type => hidden).update_all(:hidden => 1)
|
|
|
|
|
|
if params[:teacher_list] && params[:teacher_list].strip != ""
|
|
|
@course.update_attributes(:teacher_list => params[:teacher_list].strip)
|
|
|
end
|
|
|
if params[:student_list] && params[:student_list].strip != ""
|
|
|
@course.update_attributes(:student_list => params[:student_list].strip)
|
|
|
end
|
|
|
|
|
|
respond_to do |format|
|
|
|
format.js
|
|
|
end
|
|
|
end
|
|
|
|
|
|
def private_or_public
|
|
|
if @course.is_public == 0
|
|
|
@course.update_attributes(:is_public => 1)
|
|
|
else
|
|
|
@course.update_attributes(:is_public => 0)
|
|
|
end
|
|
|
if @course.is_public == 0
|
|
|
course_status = CourseStatus.find_by_course_id(@course.id)
|
|
|
course_status.destroy if course_status
|
|
|
elsif @course.is_public == 1
|
|
|
course_status = CourseStatus.find_by_course_id(@course.id)
|
|
|
course_status.destroy if course_status
|
|
|
course_status = CourseStatus.create(:course_id => @course.id, :grade => 0)
|
|
|
end
|
|
|
@syllabus = @course.syllabus
|
|
|
respond_to do |format|
|
|
|
format.js
|
|
|
end
|
|
|
end
|
|
|
|
|
|
def search_member
|
|
|
if User.current.allowed_to?(:as_teacher,@course) || User.current.admin
|
|
|
q = "#{params[:name].strip}"
|
|
|
@roles = Role.givable.all[3..5]
|
|
|
if q.nil? || q == ""
|
|
|
@members = @course.member_principals.includes(:roles, :principal).all.sort
|
|
|
else
|
|
|
@members = searchmember_by_name(@course.member_principals.includes(:roles, :principal).all.sort,q)
|
|
|
end
|
|
|
|
|
|
else
|
|
|
render_403
|
|
|
end
|
|
|
end
|
|
|
|
|
|
def create
|
|
|
cs = CoursesService.new
|
|
|
@course = cs.create_course(params,User.current)[:course]
|
|
|
|
|
|
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
|
|
|
respond_to do |format|
|
|
|
flash[:notice] = l(:notice_successful_create)
|
|
|
format.html {redirect_to course_url(@course)}
|
|
|
format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'courses', :action => 'show', :id => @course.id) }
|
|
|
end
|
|
|
else
|
|
|
respond_to do |format|
|
|
|
flash[:notice] = l(:notice_create_failed)
|
|
|
# @course = Course.new
|
|
|
format.html { redirect_to new_course_path } #Added by young
|
|
|
format.api { render_validation_errors(@course) }
|
|
|
end
|
|
|
end
|
|
|
end
|
|
|
|
|
|
def course
|
|
|
@school_id = params[:school_id]
|
|
|
per_page_option = 10
|
|
|
if @school_id == "0" or @school_id.nil?
|
|
|
@courses_all = Course.active.visible.
|
|
|
joins("LEFT JOIN #{CourseStatus.table_name} ON #{Course.table_name}.id = #{CourseStatus.table_name}.course_id")
|
|
|
else
|
|
|
@courses_all = Course.active.visible.
|
|
|
joins("LEFT JOIN #{CourseStatus.table_name} ON #{Course.table_name}.id = #{CourseStatus.table_name}.course_id").
|
|
|
joins(:course_extra).
|
|
|
where("#{Course.table_name}.school_id = ?", @school_id)
|
|
|
end
|
|
|
|
|
|
@course_count = @courses_all.count
|
|
|
@course_pages = Paginator.new @course_count, per_page_option, params['page']
|
|
|
@course_activity_count=Hash.new
|
|
|
@courses_all.each do |course|
|
|
|
@course_activity_count[course.id]=0
|
|
|
end
|
|
|
case params[:course_sort_type]
|
|
|
when '0'
|
|
|
@courses = @courses_all.order("created_on desc")
|
|
|
@s_type = 0
|
|
|
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
|
|
|
@course_activity_count=get_course_activity @courses,@course_activity_count
|
|
|
when '1'
|
|
|
@courses = @courses_all.order("course_ac_para desc")
|
|
|
@s_type = 1
|
|
|
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
|
|
|
@course_activity_count=get_course_activity @courses,@course_activity_count
|
|
|
when '2'
|
|
|
@courses = @courses_all.order("watchers_count desc")
|
|
|
@s_type = 2
|
|
|
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
|
|
|
@course_activity_count=get_course_activity @courses,@course_activity_count
|
|
|
when '3'
|
|
|
@course_activity_count=get_course_activity @courses_all,@course_activity_count
|
|
|
@courses=handle_course @courses_all,@course_activity_count
|
|
|
@s_type = 3
|
|
|
@courses = @courses[@course_pages.offset, @course_pages.per_page]
|
|
|
else
|
|
|
@s_type = 0
|
|
|
@courses = @courses_all.order("created_on desc")
|
|
|
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
|
|
|
@course_activity_count=get_course_activity @courses,@course_activity_count
|
|
|
end
|
|
|
|
|
|
respond_to do |format|
|
|
|
format.html {
|
|
|
render :layout => 'new_base'
|
|
|
}
|
|
|
format.api {
|
|
|
}
|
|
|
format.atom {
|
|
|
courses = Course.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all
|
|
|
render_feed(courses, :title => "#{Setting.app_title}: #{l(:label_course_latest)}")
|
|
|
}
|
|
|
end
|
|
|
end
|
|
|
|
|
|
def new
|
|
|
if User.current.login?
|
|
|
if User.current.user_extensions.try(:identity) == 1
|
|
|
render_403
|
|
|
else
|
|
|
@course = Course.new
|
|
|
@course.safe_attributes = params[:course]
|
|
|
# month = Time.now.month
|
|
|
render :layout => 'base_edu'
|
|
|
end
|
|
|
else
|
|
|
redirect_to signin_url
|
|
|
end
|
|
|
end
|
|
|
|
|
|
def search_course_list
|
|
|
data = {courses: []}
|
|
|
search = params[:search] ? "%#{params[:search].strip}%" : "%%"
|
|
|
CourseList.where("name like '#{search}'").each do |course|
|
|
|
option = []
|
|
|
option << course.name.to_s
|
|
|
option << course.id
|
|
|
data[:courses] << option
|
|
|
end
|
|
|
render :json => data
|
|
|
end
|
|
|
|
|
|
def desc_sort_course_by_avtivity(activity_count, courses)
|
|
|
return courses if activity_count.size<2
|
|
|
(activity_count.size-2).downto(0) do |i|
|
|
|
(0..i).each do |j|
|
|
|
if activity_count[j]<activity_count[j+1]
|
|
|
courses[j], courses[j+1]=courses[j+1], courses[j]
|
|
|
activity_count[j], activity_count[j+1]=activity_count[j+1], activity_count[j]
|
|
|
end
|
|
|
end
|
|
|
end
|
|
|
return courses
|
|
|
end
|
|
|
|
|
|
# 创建实训作业目录
|
|
|
def create_homework_category
|
|
|
if params[:category_name]
|
|
|
@course.course_homework_categories << CourseHomeworkCategory.new(:name => params[:category_name])
|
|
|
end
|
|
|
# redirect_to homework_common_index_path(:course => @course.id, :homework_type => 4)
|
|
|
end
|
|
|
|
|
|
# 重命名实训作业目录
|
|
|
def rename_homework_category
|
|
|
if request.get?
|
|
|
@category = @course.course_homework_categories.where(:id => params[:category_id]).first
|
|
|
else
|
|
|
category = @course.course_homework_categories.where(:id => params[:category_id]).first
|
|
|
if category.present?
|
|
|
category.update_attributes(:name => params[:category_name])
|
|
|
end
|
|
|
redirect_to homework_common_index_path(:course => @course.id, :homework_type => 4, :category => params[:category_id])
|
|
|
end
|
|
|
end
|
|
|
|
|
|
# 删除实训作业子目录
|
|
|
def delete_homework_category
|
|
|
category = @course.course_homework_categories.where(:id => params[:category_id]).first
|
|
|
if category.present?
|
|
|
category.homework_commons.update_all(:course_homework_category_id => nil)
|
|
|
category.destroy
|
|
|
end
|
|
|
redirect_to homework_common_index_path(:course => @course.id, :homework_type => 4)
|
|
|
end
|
|
|
|
|
|
def toggleCourse
|
|
|
@course_prefs = Course.find_by_extra(@course.extra)
|
|
|
unless (User.current.allowed_to?(:as_teacher,@course_prefs) || User.current.admin?)
|
|
|
render_403
|
|
|
end
|
|
|
end
|
|
|
|
|
|
def is_deleted
|
|
|
if @course.is_delete == 1 and !User.current.admin?
|
|
|
render_404
|
|
|
return
|
|
|
end
|
|
|
end
|
|
|
|
|
|
def get_courses
|
|
|
@user = User.current
|
|
|
membership = @user.coursememberships.all
|
|
|
membership.sort! {|older, newer| newer.created_on <=> older.created_on }
|
|
|
@memberships = []
|
|
|
membership.collect { |e|
|
|
|
@memberships.push(e)
|
|
|
}
|
|
|
@memberships_doing = []
|
|
|
@memberships_done = []
|
|
|
now_time = Time.now.year
|
|
|
@memberships.map { |e|
|
|
|
end_time = e.course.get_time.year
|
|
|
isDone = course_endTime_timeout?(e.course)
|
|
|
if isDone
|
|
|
@memberships_done.push e
|
|
|
else
|
|
|
@memberships_doing.push e
|
|
|
end
|
|
|
}
|
|
|
end
|
|
|
|
|
|
def finishcourse
|
|
|
yesterday = Date.today.prev_day.to_time
|
|
|
@course_prefs.endup_time = yesterday
|
|
|
@save_flag = @course_prefs.save
|
|
|
get_courses
|
|
|
|
|
|
respond_to do |format|
|
|
|
format.js
|
|
|
end
|
|
|
end
|
|
|
|
|
|
|
|
|
def restartcourse
|
|
|
day = Time.parse("3000-01-01")
|
|
|
|
|
|
@course_prefs.endup_time = day
|
|
|
@save_flag = @course_prefs.save
|
|
|
get_courses
|
|
|
|
|
|
respond_to do |format|
|
|
|
format.js {
|
|
|
render action:'finishcourse'
|
|
|
}
|
|
|
end
|
|
|
end
|
|
|
|
|
|
def course_activity
|
|
|
redirect_to course_url(@course, type: params[:type], page: params[:page])
|
|
|
end
|
|
|
|
|
|
def show
|
|
|
if LocalSetting.first.try(:exam) && !User.current.admin?
|
|
|
else
|
|
|
# 被删除的课程只有超级管理员才能看到,is_delete为1的时候,标记课程被删除
|
|
|
# if @course.is_delete == 1 && !User.current.admin?
|
|
|
# render_403
|
|
|
# return
|
|
|
# end
|
|
|
#更新创建课程消息状态
|
|
|
# course_request_messages = CourseMessage.where(:user_id => User.current.id, :course_id => @course.id, :course_message_type => ["CourseRequestDealResult", "Course"], :viewed => false)
|
|
|
# course_request_messages.update_all(:viewed => true)
|
|
|
|
|
|
# create_course_messages = @course.course_messages.where("user_id =? and course_message_type =? and course_id =? and viewed =?", User.current.id, 'Course', @course.id, 0)
|
|
|
# create_course_messages.update_all(:viewed => true)
|
|
|
|
|
|
#更新申请结果反馈消息的状态
|
|
|
# course_request_messages = CourseMessage.where("user_id =? and course_id =? and course_message_type =? and viewed =?", User.current.id, @course.id, 'CourseRequestDealResult', false)
|
|
|
# course_request_messages.update_all(:viewed => true)
|
|
|
|
|
|
@course_modules = @course.course_modules.where(:hidden => 0)
|
|
|
course_module_type = @course_modules.map(&:module_type)
|
|
|
@is_teacher = User.current.allowed_to?(:as_teacher, @course) || User.current.admin?
|
|
|
if User.current.member_of_course?(@course) && !@is_teacher
|
|
|
member = @course.members.where(:user_id => User.current.id).first
|
|
|
if member.try(:course_group_id).to_i == 0
|
|
|
common_homework_ids = @course.homework_commons.where("homework_type = 1 and unified_setting = 1")
|
|
|
shixun_homework_ids = @course.homework_commons.where("homework_type = 4 and unified_setting = 1")
|
|
|
group_homework_ids = @course.homework_commons.where("homework_type = 3 and unified_setting = 1")
|
|
|
exercise_ids = @course.exercises.where("unified_setting = 1")
|
|
|
poll_ids = @course.polls.where("unified_setting = 1")
|
|
|
atta_ids = @course.attachments.where("unified_setting = 1")
|
|
|
else
|
|
|
not_homework_ids = @course.homework_group_settings.where("course_group_id = #{member.try(:course_group_id)} and (publish_time > '#{Time.now}' or publish_time is null)")
|
|
|
not_homework_ids = not_homework_ids.blank? ? "(-1)" : "(" + not_homework_ids.map(&:homework_common_id).join(",") + ")"
|
|
|
common_homework_ids = @course.homework_commons.where("homework_type = 1 and id not in #{not_homework_ids}")
|
|
|
shixun_homework_ids = @course.homework_commons.where("homework_type = 4 and id not in #{not_homework_ids}")
|
|
|
group_homework_ids = @course.homework_commons.where("homework_type = 3 and id not in #{not_homework_ids}")
|
|
|
not_exercise_ids = @course.exercise_group_settings.where("course_group_id = #{member.try(:course_group_id)} and (publish_time > '#{Time.now}' or publish_time is null)")
|
|
|
not_exercise_ids = not_exercise_ids.blank? ? "(-1)" : "(" + not_exercise_ids.map(&:exercise_id).join(",") + ")"
|
|
|
exercise_ids = @course.exercises.where("id not in #{not_exercise_ids}")
|
|
|
not_poll_ids = @course.poll_group_settings.where("course_group_id = #{member.try(:course_group_id)} and (publish_time > '#{Time.now}' or publish_time is null)")
|
|
|
not_poll_ids = not_poll_ids.blank? ? "(-1)" : "(" + not_poll_ids.map(&:poll_id).join(",") + ")"
|
|
|
poll_ids = @course.polls.where("id not in #{not_poll_ids}")
|
|
|
not_atta_ids = @course.attachment_group_settings.where("course_group_id = #{member.try(:course_group_id)} and publish_time > '#{Time.now}'")
|
|
|
not_atta_ids = not_atta_ids.blank? ? "(-1)" : "(" + not_atta_ids.map(&:attachment_id).join(",") + ")"
|
|
|
atta_ids = @course.attachments.where("id not in #{not_atta_ids}")
|
|
|
end
|
|
|
else
|
|
|
common_homework_ids = @course.homework_commons.where("homework_type = 1")
|
|
|
shixun_homework_ids = @course.homework_commons.where("homework_type = 4")
|
|
|
group_homework_ids = @course.homework_commons.where("homework_type = 3")
|
|
|
exercise_ids = @course.exercises
|
|
|
poll_ids = @course.polls
|
|
|
atta_ids = @course.attachments
|
|
|
end
|
|
|
common_homework_ids = common_homework_ids.blank? ? "(-1)" : "(" + common_homework_ids.map(&:id).join(",") + ")"
|
|
|
shixun_homework_ids = shixun_homework_ids.blank? ? "(-1)" : "(" + shixun_homework_ids.map(&:id).join(",") + ")"
|
|
|
group_homework_ids = group_homework_ids.blank? ? "(-1)" : "(" + group_homework_ids.map(&:id).join(",") + ")"
|
|
|
exercise_ids = exercise_ids.blank? ? "(-1)" : "(" + exercise_ids.map(&:id).join(",") + ")"
|
|
|
poll_ids = poll_ids.blank? ? "(-1)" : "(" + poll_ids.map(&:id).join(",") + ")"
|
|
|
atta_ids = atta_ids.blank? ? "(-1)" : "(" + atta_ids.map(&:id).join(",") + ")"
|
|
|
if @is_teacher && course_module_type.include?('board')
|
|
|
course_act_type = "('Message', 'JoinCourse')"
|
|
|
elsif @is_teacher
|
|
|
course_act_type = "('JoinCourse')"
|
|
|
elsif course_module_type.include?('board')
|
|
|
course_act_type = "('Message')"
|
|
|
else
|
|
|
course_act_type = "('0')"
|
|
|
end
|
|
|
sql_str = "course_act_type in #{course_act_type}"
|
|
|
@course_modules.each do |course_module|
|
|
|
case course_module.module_type
|
|
|
when "shixun_homework"
|
|
|
sql_str += " or (course_act_type = 'HomeworkCommon' && course_act_id in #{shixun_homework_ids})"
|
|
|
when "common_homework"
|
|
|
sql_str += " or (course_act_type = 'HomeworkCommon' && course_act_id in #{common_homework_ids})"
|
|
|
when "group_homework"
|
|
|
sql_str += " or (course_act_type = 'HomeworkCommon' && course_act_id in #{group_homework_ids})"
|
|
|
when "graduation"
|
|
|
sql_str += " or (course_act_type = 'GraduationTopic' or course_act_type = 'GraduationTask')"
|
|
|
when "exercise"
|
|
|
sql_str += " or (course_act_type = 'Exercise' && course_act_id in #{exercise_ids})"
|
|
|
when "poll"
|
|
|
sql_str += " or (course_act_type = 'Poll' && course_act_id in #{poll_ids})"
|
|
|
when "attachment"
|
|
|
sql_str += " or (course_act_type = 'Attachment' && course_act_id in #{atta_ids})"
|
|
|
end
|
|
|
end
|
|
|
@page = params[:page] ? params[:page].to_i + 1 : 0
|
|
|
if params[:type].present?
|
|
|
case params[:type]
|
|
|
when "common_homework"
|
|
|
# homework_ids = @course.homework_commons.where("homework_type = 1 and id in #{homework_ids}")
|
|
|
@course_activities = @course.course_activities.where("course_act_type = 'HomeworkCommon' and course_act_id in #{common_homework_ids}").order('updated_at desc')
|
|
|
when "shixun_homework"
|
|
|
# homework_ids = @course.homework_commons.where("homework_type = 4 and id in #{homework_ids}")
|
|
|
@course_activities = @course.course_activities.where("course_act_type = 'HomeworkCommon' and course_act_id in #{shixun_homework_ids}").order('updated_at desc')
|
|
|
when "group_homework"
|
|
|
# homework_ids = @course.homework_commons.where("homework_type = 3 and id in #{homework_ids}")
|
|
|
@course_activities = @course.course_activities.where("course_act_type = 'HomeworkCommon' and course_act_id in #{group_homework_ids}").order('updated_at desc')
|
|
|
when "graduation_topic"
|
|
|
@course_activities = @course.course_activities.where("course_act_type = 'GraduationTopic'").order('updated_at desc')
|
|
|
when "graduation_task"
|
|
|
@course_activities = @course.course_activities.where("course_act_type = 'GraduationTask'").order('updated_at desc')
|
|
|
when "news"
|
|
|
@course_activities = @course.course_activities.where("course_act_type = 'News'").order('updated_at desc')
|
|
|
when "message"
|
|
|
@course_activities = @course.course_activities.where("course_act_type = 'Message'").order('updated_at desc')
|
|
|
when "poll"
|
|
|
@course_activities = @course.course_activities.where("course_act_type = 'Poll' && course_act_id in #{poll_ids}").order('updated_at desc')
|
|
|
when "exercise"
|
|
|
@course_activities = @course.course_activities.where("course_act_type = 'Exercise' && course_act_id in #{exercise_ids}").order('updated_at desc')
|
|
|
when "attachment"
|
|
|
@course_activities = @course.course_activities.where("course_act_type = 'Attachment' && course_act_id in #{atta_ids}").order('updated_at desc')
|
|
|
when 'JoinCourse'
|
|
|
@course_activities = @course.course_activities.where("course_act_type = 'JoinCourse'").order('updated_at desc')
|
|
|
when "journalsForMessage"
|
|
|
@course_activities = @course.course_activities.where("course_act_type = 'JournalsForMessage'").order('updated_at desc')
|
|
|
else
|
|
|
@course_activities = @course.course_activities.where("#{sql_str}").order('updated_at desc')
|
|
|
end
|
|
|
else
|
|
|
@course_activities = @course.course_activities.where("#{sql_str}").order('updated_at desc')
|
|
|
end
|
|
|
@course_activities_count = @course_activities.size
|
|
|
@course_activities = @course_activities.limit(10).offset(@page * 10)
|
|
|
@type = params[:type]
|
|
|
|
|
|
@left_nav_type = 1
|
|
|
@show_page = true
|
|
|
end
|
|
|
respond_to do |format|
|
|
|
format.js
|
|
|
format.html{render :layout => 'base_courses'}
|
|
|
format.api
|
|
|
end
|
|
|
end
|
|
|
|
|
|
#判断指定用户是否为课程教师
|
|
|
def isCourseTeacher(id,course)
|
|
|
result = false
|
|
|
user = User.find(id)
|
|
|
if !user.nil? && user.allowed_to?(:as_teacher,course)
|
|
|
result = true
|
|
|
end
|
|
|
result
|
|
|
end
|
|
|
|
|
|
def feedback
|
|
|
CourseMessage.where("user_id = ? and course_id = ?", User.current, @course.id).update_all(:viewed => true)
|
|
|
|
|
|
if (User.current.admin? || @course.is_public == 1 || (@course.is_public == 0 && User.current.member_of_course?(@course)))
|
|
|
page = params[:page]
|
|
|
# Find the page of the requested reply
|
|
|
@jours = @course.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC')
|
|
|
@jour_count = @jours.count
|
|
|
@limit = 10
|
|
|
if params[:r] && page.nil?
|
|
|
offset = @jours.count(:conditions => ["#{JournalsForMessage.table_name}.id > ?", params[:r].to_i])
|
|
|
page = 1 + offset / @limit
|
|
|
end
|
|
|
@jour = paginateHelper @jours,10
|
|
|
@state = false
|
|
|
@left_nav_type = 6
|
|
|
respond_to do |format|
|
|
|
format.html{render :layout => 'base_courses'}
|
|
|
format.api
|
|
|
end
|
|
|
else
|
|
|
render_403
|
|
|
end
|
|
|
end
|
|
|
|
|
|
def search_homework_member homeworks,name
|
|
|
if name == ""
|
|
|
select_homework = homeworks
|
|
|
else
|
|
|
name = name.downcase
|
|
|
select_homework = homeworks.select{ |homework|
|
|
|
homework.user[:login].to_s.downcase.include?(name) || homework.user.user_extensions[:student_id].to_s.downcase.include?(name) || (homework.user[:lastname].to_s.downcase + homework.user[:firstname].to_s.downcase).include?(name)
|
|
|
}
|
|
|
end
|
|
|
select_homework
|
|
|
end
|
|
|
|
|
|
# 作业查重
|
|
|
def code_repeat
|
|
|
#代码查重新加的
|
|
|
@index = params[:index]
|
|
|
@order,@b_sort,@name,@group = params[:order] || "score",params[:sort] || "desc",params[:name] || "",params[:group]
|
|
|
|
|
|
@is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin?
|
|
|
|
|
|
if !@is_teacher
|
|
|
render_403
|
|
|
return
|
|
|
end
|
|
|
|
|
|
@homework = HomeworkCommon.find params[:homework]
|
|
|
#order("#{@order} #{@b_sort}"
|
|
|
@student_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").order("simi_value desc").has_committed,@name
|
|
|
|
|
|
@works_hash = {}
|
|
|
|
|
|
@student_works.each do |tmpwork|
|
|
|
@works_hash[tmpwork.id] = tmpwork
|
|
|
puts tmpwork.id
|
|
|
end
|
|
|
|
|
|
respond_to do |format|
|
|
|
format.html {render :layout => 'base_edu'}
|
|
|
end
|
|
|
end
|
|
|
|
|
|
def show_comparecode
|
|
|
@index = params[:index]
|
|
|
src_id = params[:src_id]
|
|
|
dst_id = params[:dst_id]
|
|
|
|
|
|
@is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin?
|
|
|
|
|
|
if !@is_teacher
|
|
|
render_403
|
|
|
return
|
|
|
end
|
|
|
|
|
|
src_work = StudentWork.where("id =?", src_id).first
|
|
|
|
|
|
@homework = HomeworkCommon.find params[:homework_id]
|
|
|
|
|
|
@simi_value = src_work.simi_value.to_i
|
|
|
|
|
|
@src_code = src_work.description
|
|
|
src_user = User.where("id =?", src_work.user_id).first
|
|
|
|
|
|
@src_username = src_user.try(:realname) != " " ? src_user.lastname + src_user.firstname : src_user.try(:login)
|
|
|
|
|
|
#descriotion user name
|
|
|
|
|
|
dst_work = StudentWork.where("id =?", dst_id).first
|
|
|
@dst_code = dst_work.description
|
|
|
dst_user = User.where("id =?", dst_work.user_id).first
|
|
|
|
|
|
@dst_username = dst_user.try(:realname) != " " ? dst_user.lastname + dst_user.firstname : dst_user.try(:login)
|
|
|
|
|
|
respond_to do |format|
|
|
|
format.html{render :layout => 'base_edu'}
|
|
|
end
|
|
|
end
|
|
|
|
|
|
# 判断非本课堂成员的老师是否有权限复制课堂
|
|
|
def validate_copy_permission
|
|
|
status = 0
|
|
|
if User.current.professional_certification && User.current.user_extensions.identity == 0
|
|
|
status = 1
|
|
|
end
|
|
|
render :json => {:status => status}
|
|
|
end
|
|
|
|
|
|
#根据已有课程复制课程
|
|
|
#param id:已有课程ID
|
|
|
def copy_course
|
|
|
unless User.current.logged?
|
|
|
return render_403
|
|
|
end
|
|
|
cs = CoursesService.new
|
|
|
course = cs.copy_a_course(@course)[:course]
|
|
|
if course
|
|
|
redirect_to course_path(course)
|
|
|
end
|
|
|
end
|
|
|
|
|
|
#从课程创建的老师那里选择课程大纲
|
|
|
def course_outline
|
|
|
@teacher = User.find(@course.tea_id)
|
|
|
@blog_articles = @teacher.blog.articles
|
|
|
@is_in_show_outline_page = params[:is_in_show_outline_page]
|
|
|
respond_to do |format|
|
|
|
format.js
|
|
|
end
|
|
|
end
|
|
|
|
|
|
#根据关键字搜索,查找方法一样的,但返回内容不一样
|
|
|
def search_course_outline
|
|
|
@article_title = params[:title]
|
|
|
@teacher = User.find(@course.tea_id)
|
|
|
@blog_articles = @teacher.blog.articles.like(@article_title)
|
|
|
render :json=>@blog_articles.to_json
|
|
|
end
|
|
|
|
|
|
#设置或者更改课程的大纲
|
|
|
def set_course_outline
|
|
|
@course.outline = params[:outline_id]
|
|
|
@course.save
|
|
|
@is_in_show_outline_page = params[:is_in_show_outline_page]
|
|
|
respond_to do |format|
|
|
|
format.js
|
|
|
end
|
|
|
end
|
|
|
|
|
|
#显示课程大纲
|
|
|
def syllabus
|
|
|
@article = BlogComment.find(@course.outline)
|
|
|
respond_to do |format|
|
|
|
format.html {render :layout => 'base_courses'}
|
|
|
end
|
|
|
end
|
|
|
|
|
|
#删除课程
|
|
|
#删除课程只是将课程的is_deleted状态改为false,is_deleted为false状态的课程只有管理员可以看到
|
|
|
def destroy
|
|
|
@course_id = @course.id
|
|
|
syllabus = @course.syllabus
|
|
|
@course.delete!
|
|
|
respond_to do |format|
|
|
|
format.js
|
|
|
format.html{redirect_to courses_path()}
|
|
|
end
|
|
|
|
|
|
# redirect_to :back
|
|
|
end
|
|
|
|
|
|
#归档班级
|
|
|
def archive_course
|
|
|
if params[:source] == "1"
|
|
|
@syllabus = @course.syllabus
|
|
|
end
|
|
|
if params[:type] == "0"
|
|
|
@course.delete!
|
|
|
else
|
|
|
@course.update_attribute(:is_delete, false)
|
|
|
end
|
|
|
respond_to do |format|
|
|
|
format.js
|
|
|
end
|
|
|
end
|
|
|
|
|
|
# 恢复已删除的课程
|
|
|
def renew
|
|
|
if User.current.admin?
|
|
|
@course.update_attributes(:is_delete => false)
|
|
|
redirect_to course_path(@course)
|
|
|
else
|
|
|
return 404
|
|
|
end
|
|
|
end
|
|
|
#搜索作业
|
|
|
def homework_search
|
|
|
@search = "%#{params[:search].strip.downcase}%"
|
|
|
@is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course))
|
|
|
@page = params[:page] ? params[:page].to_i + 1 : 0
|
|
|
if @is_teacher
|
|
|
@homeworks = @course.homework_commons.where("name like '%#{@search}%'").order("created_at desc").limit(10).offset(@page * 10)
|
|
|
else
|
|
|
@homeworks = @course.homework_commons.where("name like '%#{@search}%' and publish_time <= '#{Time.now}'").order("created_at desc").limit(10).offset(@page * 10)
|
|
|
end
|
|
|
end
|
|
|
|
|
|
#统计
|
|
|
def course_statistics
|
|
|
@left_nav_type = 10
|
|
|
@order = params[:order] ? params[:order] : 'desc'
|
|
|
@tab = params[:tab] ? params[:tab].to_i : nil
|
|
|
if !params[:tab] || params[:tab] == "1"
|
|
|
@type = params[:type] ? params[:type] : 'act_score'
|
|
|
sql = "SELECT (message_num*2 + message_reply_num*1 + news_reply_num*1 + news_num*1 + resource_num*5 + journal_num*1 + homework_journal_num*1) AS act_score,
|
|
|
message_num, message_reply_num, news_reply_num, news_num, resource_num, journal_num, homework_journal_num, ccs.user_id FROM course_contributor_scores ccs
|
|
|
JOIN students_for_courses ON students_for_courses.course_id = ccs.course_id AND students_for_courses.student_id = ccs.user_id
|
|
|
WHERE ccs.course_id = #{@course.id} ORDER BY #{@type} #{@order}, act_score #{@order}"
|
|
|
@members = CourseContributorScore.find_by_sql(sql)
|
|
|
|
|
|
elsif params[:tab] == "2"
|
|
|
@type = params[:type] ? params[:type] : 'total_score'
|
|
|
@members = @course.course_homework_statisticss.reorder("#{@type} #{@order}, total_score #{@order}")
|
|
|
|
|
|
elsif params[:tab] == "3"
|
|
|
@homework_id = params[:homework_id] ? params[:homework_id].to_i : 0
|
|
|
@type = params[:type] ? params[:type] : 'project_act_score'
|
|
|
if @homework_id == 0
|
|
|
sql = "SELECT (IFNULL(changeset_num, 0)*4 + issue_num*4 + issue_journal_num*1 + attach_num*5 + board_num*2 + board_message_num*1) AS project_act_score,
|
|
|
changeset_num, issue_num, issue_journal_num, attach_num, board_num, board_message_num, pss.project_id FROM project_scores pss
|
|
|
JOIN student_work_projects ON student_work_projects.project_id = pss.project_id AND student_work_projects.course_id = #{@course.id}
|
|
|
GROUP BY pss.project_id ORDER BY #{@type} #{@order}, project_act_score #{@order}"
|
|
|
else
|
|
|
sql = "SELECT (IFNULL(changeset_num, 0)*4 + issue_num*4 + issue_journal_num*1 + attach_num*5 + board_num*2 + board_message_num*1) AS project_act_score,
|
|
|
changeset_num, issue_num, issue_journal_num, attach_num, board_num, board_message_num, pss.project_id FROM project_scores pss
|
|
|
JOIN student_work_projects ON student_work_projects.project_id = pss.project_id AND student_work_projects.course_id = #{@course.id} AND student_work_projects.homework_common_id = #{@homework_id}
|
|
|
GROUP BY pss.project_id ORDER BY #{@type} #{@order}, project_act_score #{@order}"
|
|
|
end
|
|
|
@members = ProjectScore.find_by_sql(sql)
|
|
|
end
|
|
|
|
|
|
@limit = 20
|
|
|
@page = params[:page].nil? ? 1 : params['page'].to_i
|
|
|
@members_count = @members.count
|
|
|
@mem_pages = Paginator.new @members_count, @limit, @page
|
|
|
@members = paginateHelper @members, @limit
|
|
|
respond_to do |format|
|
|
|
format.js
|
|
|
format.html {render :layout => 'base_courses'}
|
|
|
end
|
|
|
end
|
|
|
|
|
|
#切换身份
|
|
|
def switch_role
|
|
|
members = @course.members.where("user_id = #{params[:user_id]}")
|
|
|
unless members.blank?
|
|
|
#role = MemberRole.where("member_id = #{members.first.id} and role_id = #{params[:role]}").first
|
|
|
curr_role = MemberRole.find_by_member_id_and_role_id(members.first.id, params[:curr_role])
|
|
|
tar_role = MemberRole.find_by_member_id_and_role_id(members.first.id, params[:tar_role])
|
|
|
unless (curr_role.nil? || tar_role.nil?)
|
|
|
curr_role.update_column('is_current', 0)
|
|
|
tar_role.update_column('is_current', 1)
|
|
|
end
|
|
|
end
|
|
|
redirect_to course_path(@course)
|
|
|
end
|
|
|
|
|
|
def search_not_teachers
|
|
|
# members = searchTeacherAndAssistant @course
|
|
|
member_ids = Member.find_by_sql("SELECT user_id from members where id in (SELECT member_id FROM `member_roles` where role_id in (3,7,9)
|
|
|
and member_id in (select id from members where course_id=#{@course.id}))")
|
|
|
member_ids = "(" + member_ids.map(&:user_id).join(',') + ")"
|
|
|
condition = "%#{params[:search]}%".gsub(" ","")
|
|
|
@school = params[:school] || @course.teacher.school_name
|
|
|
if @school != ""
|
|
|
school_s = "%#{@school}%".gsub(" ","")
|
|
|
school_ids = School.where("name like '#{school_s}'").blank? ? "(-1)" : "(" + School.where("name like '#{school_s}'").map(&:id).join(",") + ")"
|
|
|
@users = User.joins(:user_extensions).where("users.id not in #{member_ids} and status = 1 and LOWER(concat(lastname, firstname)) LIKE '#{condition}' and user_extensions.school_id in #{school_ids}")
|
|
|
else
|
|
|
@users = User.where("id not in #{member_ids} and status = 1 and LOWER(concat(lastname, firstname)) LIKE '#{condition}'").includes(:user_extensions)
|
|
|
end
|
|
|
@role = params[:role].to_i
|
|
|
@user_ids = @users.map(&:id).join(",")
|
|
|
@limit = 10
|
|
|
@page = params[:page].nil? ? 1 : params['page'].to_i
|
|
|
@users_count = @users.count
|
|
|
@total_pages = (@users_count / 10.0).ceil
|
|
|
@users_pages = Paginator.new @users_count, @limit, @page
|
|
|
@users = paginateHelper @users, @limit
|
|
|
respond_to do |format|
|
|
|
format.js
|
|
|
format.json {
|
|
|
render json: search_teacher_json_data(@users)
|
|
|
}
|
|
|
end
|
|
|
end
|
|
|
|
|
|
def search_not_students
|
|
|
members = @course.members.select{|m| m.roles.to_s.include?("Student")}
|
|
|
member_ids = members.empty? ? "(-1)" : "(" + members.map(&:user_id).join(',') + ")"
|
|
|
condition = "%#{params[:search]}%".gsub(" ","")
|
|
|
@school = params[:school] || @course.teacher.school_name
|
|
|
if @school != ""
|
|
|
school_s = "%#{@school}%".gsub(" ","")
|
|
|
school_ids = School.where("name like '#{school_s}'").blank? ? "(-1)" : "(" + School.where("name like '#{school_s}'").map(&:id).join(",") + ")"
|
|
|
@users = User.joins(:user_extensions).where("users.id not in #{member_ids} and status = 1 and user_extensions.school_id in #{school_ids} and (LOWER(concat(lastname, firstname)) LIKE '#{condition}' or user_extensions.student_id LIKE '#{condition}')")
|
|
|
else
|
|
|
@users = User.joins(:user_extensions).where("users.id not in #{member_ids} and status = 1 and (LOWER(concat(lastname, firstname)) LIKE '#{condition}' or user_extensions.student_id LIKE '#{condition}')")
|
|
|
end
|
|
|
|
|
|
@user_ids = @users.map(&:id).join(",")
|
|
|
@limit = 8
|
|
|
@page = params[:page].nil? ? 1 : params['page'].to_i
|
|
|
@users_count = @users.count
|
|
|
@total_pages = (@users_count / 10.0).ceil
|
|
|
@users_pages = Paginator.new @users_count, @limit, @page
|
|
|
@users = paginateHelper @users, @limit
|
|
|
respond_to do |format|
|
|
|
format.js
|
|
|
format.json {
|
|
|
render json: search_student_json_data(@users)
|
|
|
}
|
|
|
end
|
|
|
end
|
|
|
|
|
|
private
|
|
|
|
|
|
def allow_join course
|
|
|
if course_endTime_timeout? course
|
|
|
respond_to do |format|
|
|
|
format.js {
|
|
|
@state = 2
|
|
|
render :partial => 'set_join',
|
|
|
:locals => {:user => User.current,
|
|
|
:course => Course.find(params[:object_id]),
|
|
|
:object_id => params[:object_id]
|
|
|
}
|
|
|
}
|
|
|
end
|
|
|
end
|
|
|
end
|
|
|
|
|
|
#验证是否显示课程
|
|
|
def can_show_course
|
|
|
@first_page = FirstPage.find_by_page_type('project')
|
|
|
if @first_page.try(:show_course) == 2
|
|
|
render_404
|
|
|
end
|
|
|
end
|
|
|
|
|
|
def student_homework_score(groupid,start_from, nums, score_sort_by, sort_type = 'score')
|
|
|
start_from = start_from * nums
|
|
|
if groupid == 0
|
|
|
sql_select = "SELECT members.*,(
|
|
|
SELECT SUM(student_works.work_score)
|
|
|
FROM student_works,homework_commons
|
|
|
WHERE student_works.homework_common_id = homework_commons.id
|
|
|
AND homework_commons.course_id = #{@course.id}
|
|
|
AND student_works.user_id = members.user_id
|
|
|
) AS score,
|
|
|
(SELECT SUM(gw.work_score) FROM graduation_works gw,graduation_tasks gt WHERE gw.graduation_task_id = gt.id
|
|
|
AND gt.course_id = #{@course.id} AND gw.user_id = members.user_id) AS graduation_score,
|
|
|
(SELECT SUM(exercise_users.score) FROM exercise_users,exercises WHERE exercise_users.exercise_id = exercises.id
|
|
|
AND exercises.course_id = #{@course.id} AND exercise_users.user_id = members.user_id) AS ex_score,
|
|
|
(SELECT max(student_id) FROM user_extensions WHERE user_extensions.user_id = members.user_id) AS student_id,
|
|
|
(SELECT max(message_num) FROM course_contributor_scores AS ccs WHERE ccs.course_id = #{@course.id} AND ccs.user_id = members.user_id) AS message_num,
|
|
|
(SELECT max(message_reply_num) FROM course_contributor_scores AS ccs WHERE ccs.course_id = #{@course.id} AND ccs.user_id = members.user_id) AS message_reply_num,
|
|
|
(SELECT max(resource_num) FROM course_contributor_scores AS ccs WHERE ccs.course_id = #{@course.id} AND ccs.user_id = members.user_id) AS resource_num,
|
|
|
(SELECT max(homework_journal_num) FROM course_contributor_scores AS ccs WHERE ccs.course_id = #{@course.id} AND ccs.user_id = members.user_id) AS homework_journal_num,
|
|
|
(SELECT COUNT(gw.id) FROM graduation_works AS gw, graduation_tasks AS gt WHERE gw.graduation_task_id = gt.id AND gt.course_id = #{@course.id} AND gw.work_status != 0 AND gw.user_id = members.user_id) AS graduation_num,
|
|
|
(SELECT COUNT(ss.id) FROM student_works AS ss ,homework_commons AS hc WHERE ss.homework_common_id = hc.id AND hc.course_id = #{@course.id} AND ss.work_status != 0 AND ss.user_id = members.user_id) AS homework_num,
|
|
|
(SELECT COUNT(eu.id) FROM exercise_users AS eu,exercises WHERE eu.exercise_id = exercises.id AND exercises.course_id = #{@course.id} AND eu.commit_status = 1 AND eu.user_id = members.user_id) AS exercise_num,
|
|
|
(SELECT COUNT(pu.id) FROM poll_users AS pu, polls WHERE pu.poll_id = polls.id AND polls.course_id = #{@course.id} AND pu.commit_status = 1 AND pu.user_id = members.user_id) AS poll_num
|
|
|
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 #{sort_type} #{score_sort_by}"
|
|
|
elsif groupid == -1
|
|
|
sql_select = "SELECT members.*,(
|
|
|
SELECT SUM(student_works.work_score)
|
|
|
FROM student_works,homework_commons
|
|
|
WHERE student_works.homework_common_id = homework_commons.id
|
|
|
AND homework_commons.course_id = #{@course.id}
|
|
|
AND student_works.user_id = members.user_id
|
|
|
) AS score,
|
|
|
(SELECT SUM(gw.work_score) FROM graduation_works gw,graduation_tasks gt WHERE gw.graduation_task_id = gt.id
|
|
|
AND gt.course_id = #{@course.id} AND gw.user_id = members.user_id) AS graduation_score,
|
|
|
(SELECT SUM(exercise_users.score) FROM exercise_users,exercises WHERE exercise_users.exercise_id = exercises.id
|
|
|
AND exercises.course_id = #{@course.id} AND exercise_users.user_id = members.user_id) AS ex_score,
|
|
|
(SELECT max(student_id) FROM user_extensions WHERE user_extensions.user_id = members.user_id) AS student_id,
|
|
|
(SELECT max(message_num) FROM course_contributor_scores AS ccs WHERE ccs.course_id = #{@course.id} AND ccs.user_id = members.user_id) AS message_num,
|
|
|
(SELECT max(message_reply_num) FROM course_contributor_scores AS ccs WHERE ccs.course_id = #{@course.id} AND ccs.user_id = members.user_id) AS message_reply_num,
|
|
|
(SELECT max(resource_num) FROM course_contributor_scores AS ccs WHERE ccs.course_id = #{@course.id} AND ccs.user_id = members.user_id) AS resource_num,
|
|
|
(SELECT max(homework_journal_num) FROM course_contributor_scores AS ccs WHERE ccs.course_id = #{@course.id} AND ccs.user_id = members.user_id) AS homework_journal_num,
|
|
|
(SELECT COUNT(gw.id) FROM graduation_works AS gw, graduation_tasks AS gt WHERE gw.graduation_task_id = gt.id AND gt.course_id = #{@course.id} AND gw.work_status != 0 AND gw.user_id = members.user_id) AS graduation_num,
|
|
|
(SELECT COUNT(ss.id) FROM student_works AS ss ,homework_commons AS hc WHERE ss.homework_common_id = hc.id AND hc.course_id = #{@course.id} AND ss.work_status != 0 AND ss.user_id = members.user_id) AS homework_num,
|
|
|
(SELECT COUNT(eu.id) FROM exercise_users AS eu,exercises WHERE eu.exercise_id = exercises.id AND exercises.course_id = #{@course.id} AND eu.commit_status = 1 AND eu.user_id = members.user_id) AS exercise_num,
|
|
|
(SELECT COUNT(pu.id) FROM poll_users AS pu, polls WHERE pu.poll_id = polls.id AND polls.course_id = #{@course.id} AND pu.commit_status = 1 AND pu.user_id = members.user_id) AS poll_num
|
|
|
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} AND members.course_group_id = 0 ORDER BY #{sort_type} #{score_sort_by}"
|
|
|
else
|
|
|
sql_select = "SELECT members.*,(
|
|
|
SELECT SUM(student_works.work_score)
|
|
|
FROM student_works,homework_commons
|
|
|
WHERE student_works.homework_common_id = homework_commons.id
|
|
|
AND homework_commons.course_id = #{@course.id}
|
|
|
AND student_works.user_id = members.user_id
|
|
|
) AS score,
|
|
|
(SELECT SUM(gw.work_score) FROM graduation_works gw,graduation_tasks gt WHERE gw.graduation_task_id = gt.id
|
|
|
AND gt.course_id = #{@course.id} AND gw.user_id = members.user_id) AS graduation_score,
|
|
|
(SELECT SUM(exercise_users.score) FROM exercise_users,exercises WHERE exercise_users.exercise_id = exercises.id
|
|
|
AND exercises.course_id = #{@course.id} AND exercise_users.user_id = members.user_id) AS ex_score,
|
|
|
(SELECT max(student_id) FROM user_extensions WHERE user_extensions.user_id = members.user_id) AS student_id,
|
|
|
(SELECT max(message_num) FROM course_contributor_scores AS ccs WHERE ccs.course_id = #{@course.id} AND ccs.user_id = members.user_id) AS message_num,
|
|
|
(SELECT max(message_reply_num) FROM course_contributor_scores AS ccs WHERE ccs.course_id = #{@course.id} AND ccs.user_id = members.user_id) AS message_reply_num,
|
|
|
(SELECT max(resource_num) FROM course_contributor_scores AS ccs WHERE ccs.course_id = #{@course.id} AND ccs.user_id = members.user_id) AS resource_num,
|
|
|
(SELECT max(homework_journal_num) FROM course_contributor_scores AS ccs WHERE ccs.course_id = #{@course.id} AND ccs.user_id = members.user_id) AS homework_journal_num,
|
|
|
(SELECT COUNT(gw.id) FROM graduation_works AS gw, graduation_tasks AS gt WHERE gw.graduation_task_id = gt.id AND gt.course_id = #{@course.id} AND gw.work_status != 0 AND gw.user_id = members.user_id) AS graduation_num,
|
|
|
(SELECT COUNT(ss.id) FROM student_works AS ss ,homework_commons AS hc WHERE ss.homework_common_id = hc.id AND hc.course_id = #{@course.id} AND ss.work_status != 0 AND ss.user_id = members.user_id) AS homework_num,
|
|
|
(SELECT COUNT(eu.id) FROM exercise_users AS eu,exercises WHERE eu.exercise_id = exercises.id AND exercises.course_id = #{@course.id} AND eu.commit_status = 1 AND eu.user_id = members.user_id) AS exercise_num,
|
|
|
(SELECT COUNT(pu.id) FROM poll_users AS pu, polls WHERE pu.poll_id = polls.id AND polls.course_id = #{@course.id} AND pu.commit_status = 1 AND pu.user_id = members.user_id) AS poll_num
|
|
|
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} AND members.course_group_id = #{groupid} ORDER BY #{sort_type} #{score_sort_by}"
|
|
|
end
|
|
|
sql = ActiveRecord::Base.connection()
|
|
|
homework_scores = Member.find_by_sql(sql_select)
|
|
|
sql.close()
|
|
|
|
|
|
homework_scores
|
|
|
end
|
|
|
#获取课程的老师列表
|
|
|
def find_course_teachers course
|
|
|
searchTeacherAndAssistant(course).map{|teacher| teacher.user_id}.join(",")
|
|
|
end
|
|
|
|
|
|
#当加入,退出分班时查询分班的学生
|
|
|
def search_group_members group
|
|
|
@render_file = 'new_member_list'
|
|
|
@canShowCode = isCourseTeacher(User.current.id,@course)
|
|
|
@is_remote = true
|
|
|
@score_sort_by = "desc"
|
|
|
@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 shixun_xls homeworks, course
|
|
|
xls_report = StringIO.new
|
|
|
book = Spreadsheet::Workbook.new
|
|
|
blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10
|
|
|
black = Spreadsheet::Format.new :color => :black, :weight => :bold, :size => 10
|
|
|
current_row = 0
|
|
|
sheet = book.create_worksheet :name => "学员统计"
|
|
|
sheet.row(0).default_format = blue
|
|
|
sheet.row(0).concat(["学生id","学生姓名","作业编号","作业/实训名称","关卡"," 经验值","金币","评测历史","评测时间","评测结果"])
|
|
|
course.student.each_with_index do |course, i|
|
|
|
# 总统计
|
|
|
count_exp_score = 0
|
|
|
count_gold_score = 0
|
|
|
count_test = 0
|
|
|
count_time = 0
|
|
|
game_count = 0
|
|
|
# end
|
|
|
user = course.student
|
|
|
current_row += 1
|
|
|
sheet[current_row, 0] = user.login
|
|
|
sheet[current_row, 1] = user.show_real_name
|
|
|
homeworks.each_with_index do |homework, j|
|
|
|
# 关卡统计
|
|
|
count_game_exp_score = 0
|
|
|
count_game_gold_score = 0
|
|
|
count_game_test = 0
|
|
|
count_game_time = 0
|
|
|
# end
|
|
|
sheet[current_row, 2] = "# #{get_hw_index(homework, true, 4)}"
|
|
|
sheet[current_row, 3] = homework.name
|
|
|
shixun = homework.homework_commons_shixuns.shixun if homework.homework_commons_shixuns
|
|
|
if shixun
|
|
|
shixun.challenges.each_with_index do |challenge, k|
|
|
|
sheet[current_row, 4] = "第#{k+1}关"
|
|
|
games = Game.where(:challenge_id => challenge.id, :user_id => user.id)
|
|
|
game_count = game_count + games.count
|
|
|
if games.count > 0
|
|
|
games.each do |game|
|
|
|
sheet[current_row, 5] = game.final_score ? "+#{game.final_score.to_s}" : "--"
|
|
|
sheet[current_row, 6] = game.final_score ? (game.answer_open? ? "#{-challenge.score.to_i}" : "+#{game.final_score.to_i}") : "--"
|
|
|
count_exp_score += (game.final_score ? game.final_score.to_i : 0)
|
|
|
count_gold_score += (game.final_score ? (game.answer_open? ? -challenge.score.to_i : game.final_score.to_i) : 0)
|
|
|
count_game_exp_score += (game.final_score ? game.final_score.to_i : 0)
|
|
|
count_game_gold_score += (game.final_score ? (game.answer_open? ? -challenge.score.to_i : game.final_score.to_i) : 0)
|
|
|
count = game.outputs.count
|
|
|
if count > 0
|
|
|
outputs = game.outputs.where(:test_set_position => 1).reorder("created_at asc")
|
|
|
outputs.each_with_index do |output, k|
|
|
|
count_test += 1
|
|
|
count_game_test += 1
|
|
|
sheet[current_row, 7] = "第#{k+1}次评测"
|
|
|
sheet[current_row, 8] = k == 0 ? game_spend_time((output.created_at - game.created_at).to_i) : game_spend_time((output.created_at - outputs[k-1].created_at).to_i)
|
|
|
count_time = count_time + (k == 0 ? (output.created_at - game.created_at).to_i : (output.created_at - outputs[k-1].created_at).to_i)
|
|
|
count_game_time += (k == 0 ? (output.created_at - game.created_at).to_i : (output.created_at - outputs[k-1].created_at).to_i)
|
|
|
sheet[current_row, 9] = game.outputs.where(:query_index => output.query_index).select{|ou| ou.result == false}.count > 0 ? "失败" : "成功"
|
|
|
current_row += 1
|
|
|
end
|
|
|
else
|
|
|
current_row += 1
|
|
|
end
|
|
|
end
|
|
|
else
|
|
|
current_row += 1
|
|
|
end
|
|
|
end
|
|
|
end
|
|
|
sheet[current_row,4] = "合计"
|
|
|
sheet[current_row,5] = count_game_exp_score >= 0 ? "+#{count_game_exp_score}" : "-#{count_game_exp_score}"
|
|
|
sheet[current_row,6] = count_game_gold_score >= 0 ? "+#{count_game_gold_score}" : "#{count_game_gold_score}"
|
|
|
sheet[current_row,7] = "共#{count_game_test}次评测"
|
|
|
sheet[current_row,8] = game_spend_time((count_game_time == 0 ? 0 : (count_game_time / count_test)).to_i)+"/次"
|
|
|
sheet.row(current_row).default_format = black
|
|
|
#current_row += 1
|
|
|
end
|
|
|
# sheet[current_row,2] = "合计"
|
|
|
# sheet[current_row,4] = "共#{game_count}"
|
|
|
# sheet[current_row,5] = count_exp_score >= 0 ? "+#{count_exp_score}" : "-#{count_exp_score}"
|
|
|
# sheet[current_row,6] = count_gold_score >= 0 ? "+#{count_gold_score}" : "#{count_gold_score}"
|
|
|
# sheet[current_row,7] = "共#{count_test}次评测"
|
|
|
# sheet[current_row,8] = game_spend_time((count_time == 0 ? 0 : (count_time / count_test)).to_i)+"/次"
|
|
|
# sheet.row(current_row).default_format = black
|
|
|
end
|
|
|
|
|
|
homeworks.each_with_index do |homework, i|
|
|
|
sheet = book.create_worksheet :name => "关卡统计"
|
|
|
sheet.row(0).default_format = blue
|
|
|
sheet[0,0] = "课堂编号"
|
|
|
sheet[0,1] = "主讲老师"
|
|
|
sheet[0,2] = "课堂名称"
|
|
|
sheet[0,3] = "作业编号"
|
|
|
sheet[0,4] = "作业/实训名称"
|
|
|
sheet[0,5] = "关卡"
|
|
|
sheet[0,6] = "学生id"
|
|
|
sheet[0,7] = "学生姓名"
|
|
|
sheet[0,8] = "经验值"
|
|
|
sheet[0,9] = "金币"
|
|
|
sheet[0,10] = "评测历史"
|
|
|
sheet[0,11] = "评测时间"
|
|
|
sheet[0,12] = "评测结果"
|
|
|
sheet[1,0] = course.id
|
|
|
sheet[1,1] = course.teacher.show_real_name
|
|
|
sheet[1,2] = course.name
|
|
|
sheet[1,3] = "# #{get_hw_index(homework, true, 4)}"
|
|
|
sheet[1,4] = homework.name
|
|
|
current_row = 1
|
|
|
shixun = homework.homework_commons_shixuns.shixun if homework.homework_commons_shixuns
|
|
|
if shixun
|
|
|
shixun.challenges.each_with_index do |challenge, j|
|
|
|
sheet[current_row,5] = "第#{j+1}关"
|
|
|
games = Game.where(:challenge_id => challenge.id, :user_id => homework.student_works.where("work_status != 0").map(&:user_id))
|
|
|
count_exp_score = 0
|
|
|
count_gold_score = 0
|
|
|
count_test = 0
|
|
|
count_time = 0
|
|
|
if games.count > 0
|
|
|
games.each do |game|
|
|
|
user = game.user
|
|
|
sheet[current_row,6] = user.login
|
|
|
sheet[current_row,7] = user.show_real_name
|
|
|
sheet[current_row,8] = game.final_score ? "+#{game.final_score.to_s}" : "--"
|
|
|
count_exp_score = count_exp_score + (game.final_score ? game.final_score.to_i : 0)
|
|
|
sheet[current_row,9] = game.final_score ? (game.answer_open? ? "#{-challenge.score.to_i}" : "+#{game.final_score.to_i}") : "--"
|
|
|
count_gold_score = count_gold_score + (game.final_score ? (game.answer_open? ? -challenge.score.to_i : game.final_score.to_i) : 0)
|
|
|
|
|
|
count = game.outputs.count
|
|
|
if count > 0
|
|
|
outputs = game.outputs.where(:test_set_position => 1).reorder("created_at asc")
|
|
|
outputs.each_with_index do |output, k|
|
|
|
count_test = count_test + 1
|
|
|
sheet[current_row,10] = "第#{k+1}次评测"
|
|
|
sheet[current_row,11] = k == 0 ? game_spend_time((output.created_at - game.created_at).to_i) : game_spend_time((output.created_at - outputs[k-1].created_at).to_i)
|
|
|
count_time = count_time + (k == 0 ? (output.created_at - game.created_at).to_i : (output.created_at - outputs[k-1].created_at).to_i)
|
|
|
sheet[current_row,12] = game.outputs.where(:query_index => output.query_index).select{|ou| ou.result == false}.count > 0 ? "失败" : "成功"
|
|
|
current_row = current_row + 1
|
|
|
end
|
|
|
else
|
|
|
current_row = current_row + 1
|
|
|
end
|
|
|
end
|
|
|
else
|
|
|
current_row = current_row + 1
|
|
|
end
|
|
|
|
|
|
sheet[current_row,6] = "合计"
|
|
|
sheet[current_row,7] = games.count.to_s + "人"
|
|
|
sheet[current_row,8] = count_exp_score >= 0 ? "+#{count_exp_score}" : "-#{count_exp_score}"
|
|
|
sheet[current_row,9] = count_gold_score >= 0 ? "+#{count_gold_score}" : "#{count_gold_score}"
|
|
|
sheet[current_row,10] = "共#{count_test}次评测"
|
|
|
sheet[current_row,11] = game_spend_time((count_time == 0 ? 0 : (count_time / count_test)).to_i)+"/次"
|
|
|
sheet.row(current_row).default_format = black
|
|
|
current_row = current_row + 1
|
|
|
end
|
|
|
end
|
|
|
end
|
|
|
book.write xls_report
|
|
|
xls_report.string
|
|
|
end
|
|
|
|
|
|
def member_to_xls homeworks, exercises, tasks, course, members, groups
|
|
|
xls_report = StringIO.new
|
|
|
book = Spreadsheet::Workbook.new
|
|
|
sheet1 = book.create_worksheet :name => "总成绩"
|
|
|
blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10
|
|
|
#sheet1.row(0).default_format = blue
|
|
|
#sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),l(:excel_class),l(:excel_f_score),l(:excel_commit_time)])
|
|
|
sheet1[0,0] = "课程编号"
|
|
|
sheet1[0,1] = course.id
|
|
|
sheet1[1,0] = "课程名称"
|
|
|
sheet1[1,1] = course.name
|
|
|
sheet1[2,0] = "教师团队"
|
|
|
sheet1[2,1] = (searchTeacherAndAssistant course).map{|member| member.user.show_real_name}.join('、')
|
|
|
sheet1[3,0] = "主讲教师"
|
|
|
sheet1[3,1] = course.teacher.show_real_name
|
|
|
sheet1[4,0] = "排名"
|
|
|
sheet1[4,1] = "学生姓名"
|
|
|
sheet1[4,2] = "昵称"
|
|
|
sheet1[4,3] = "学号"
|
|
|
sheet1[4,4] = "分班"
|
|
|
current_col = 4
|
|
|
homeworks.where(:homework_type => 4).each do |homework|
|
|
|
sheet1[4,current_col+=1] = "#{homework.name}"
|
|
|
end
|
|
|
for i in 0 ... homeworks.where(:homework_type => 1).count
|
|
|
sheet1[4,current_col+=1] = "普通作业第"+(i+1).to_s+"次"
|
|
|
end
|
|
|
for i in 0 ... homeworks.where(:homework_type => 3).count
|
|
|
sheet1[4,current_col+=1] = "分组作业第"+(i+1).to_s+"次"
|
|
|
end
|
|
|
for i in 0 ... exercises.count
|
|
|
sheet1[4,current_col+=1] = "试卷第"+(i+1).to_s+"次"
|
|
|
end
|
|
|
for i in 0 ... tasks.count
|
|
|
sheet1[4,current_col+=1] = "毕设任务第"+(i+1).to_s+"次"
|
|
|
end
|
|
|
|
|
|
sheet1[4,current_col+=1] = "实训作业总得分"
|
|
|
sheet1[4,current_col+=1] = "普通作业总得分"
|
|
|
sheet1[4,current_col+=1] = "分组作业总得分"
|
|
|
sheet1[4,current_col+=1] = "试卷总得分"
|
|
|
if tasks.count > 0
|
|
|
sheet1[4,current_col+=1] = "毕设任务总得分"
|
|
|
end
|
|
|
#sheet1[6,homeworks.count+6] = "社区得分"
|
|
|
sheet1[4,current_col+=1] = "总得分"
|
|
|
count_row = 5
|
|
|
members.each_with_index do |member, i|
|
|
|
column = 0
|
|
|
sheet1[count_row,column]= i+1
|
|
|
sheet1[count_row,column+=1] = member.user.show_real_name
|
|
|
sheet1[count_row,column+=1] = member.user.login
|
|
|
sheet1[count_row,column+=1] = member.user.user_extensions.student_id
|
|
|
sheet1[count_row,column+=1] = member.course_group_id == 0 ? "暂无" : member.course_group.name
|
|
|
# current_col = 5
|
|
|
shixun_score = 0
|
|
|
homeworks.where(:homework_type => 4).includes(:student_works).each do |homework|
|
|
|
student_works = homework.student_works.where("user_id = #{member.user.id}")
|
|
|
if student_works.empty?
|
|
|
sheet1[count_row,column+=1] = 0
|
|
|
else
|
|
|
work_score = student_works.first.work_score.nil? ? 0 : student_works.first.work_score
|
|
|
sheet1[count_row,column+=1] = work_score < 0 ? 0 : work_score.round(1)
|
|
|
shixun_score += work_score < 0 ? 0 : work_score.round(1)
|
|
|
end
|
|
|
# current_col += 1
|
|
|
end
|
|
|
common_score = 0
|
|
|
homeworks.where(:homework_type => 1).includes(:student_works).each do |homework|
|
|
|
student_works = homework.student_works.where("user_id = #{member.user.id}")
|
|
|
if student_works.empty?
|
|
|
sheet1[count_row,column+=1] = 0
|
|
|
else
|
|
|
work_score = student_works.first.work_score.nil? ? 0 : student_works.first.work_score
|
|
|
sheet1[count_row,column+=1] = work_score < 0 ? 0 : work_score.round(1)
|
|
|
common_score += work_score < 0 ? 0 : work_score.round(1)
|
|
|
end
|
|
|
# current_col += 1
|
|
|
end
|
|
|
group_score = 0
|
|
|
homeworks.where(:homework_type => 3).includes(:student_works).each do |homework|
|
|
|
student_works = homework.student_works.where("user_id = #{member.user.id}")
|
|
|
if student_works.empty?
|
|
|
sheet1[count_row,column+=1] = 0
|
|
|
else
|
|
|
work_score = student_works.first.work_score.nil? ? 0 : student_works.first.work_score
|
|
|
sheet1[count_row,column+=1] = work_score < 0 ? 0 : work_score.round(1)
|
|
|
group_score += work_score < 0 ? 0 : work_score.round(1)
|
|
|
end
|
|
|
# current_col += 1
|
|
|
end
|
|
|
exercise_score = 0
|
|
|
exercises.includes(:exercise_users).each do |exercise|
|
|
|
exercise_user = exercise.exercise_users.where("user_id = #{member.user.id}")
|
|
|
if exercise_user.empty?
|
|
|
sheet1[count_row,column+=1] = 0
|
|
|
else
|
|
|
work_score = exercise_user.first.score.nil? ? 0 : exercise_user.first.score
|
|
|
sheet1[count_row,column+=1] = work_score < 0 ? 0 : work_score.round(1)
|
|
|
exercise_score += work_score < 0 ? 0 : work_score.round(1)
|
|
|
end
|
|
|
# current_col += 1
|
|
|
end
|
|
|
|
|
|
graduation_score = 0
|
|
|
tasks.includes(:graduation_works).each do |task|
|
|
|
graduation_works = task.graduation_works.where("user_id = #{member.user.id}")
|
|
|
if graduation_works.empty?
|
|
|
sheet1[count_row,column+=1] = 0
|
|
|
else
|
|
|
work_score = graduation_works.first.work_score.nil? ? 0 : graduation_works.first.work_score
|
|
|
sheet1[count_row,column+=1] = work_score < 0 ? 0 : work_score.round(1)
|
|
|
graduation_score += work_score < 0 ? 0 : work_score.round(1)
|
|
|
end
|
|
|
# current_col += 1
|
|
|
end
|
|
|
|
|
|
sum = shixun_score + common_score + group_score + exercise_score + graduation_score
|
|
|
sheet1[count_row,column+=1] = shixun_score
|
|
|
sheet1[count_row,column+=1] = common_score
|
|
|
sheet1[count_row,column+=1] = group_score
|
|
|
sheet1[count_row,column+=1] = exercise_score
|
|
|
if tasks.count > 0
|
|
|
sheet1[count_row,column+=1] = graduation_score
|
|
|
end
|
|
|
sheet1[count_row,column+=1] = sum.round(1)
|
|
|
count_row += 1
|
|
|
end
|
|
|
|
|
|
if course.course_groups.count > 0
|
|
|
sheet = book.create_worksheet :name => "分班信息"
|
|
|
sheet.row(0).concat(["课程编号", course.id])
|
|
|
sheet.row(1).concat(["课程名称", course.name])
|
|
|
sheet.row(2).concat(["教师团队", (searchTeacherAndAssistant course).map{|member| member.user.show_real_name}.join('、')])
|
|
|
sheet.row(3).concat(["主讲教师", course.teacher.show_real_name])
|
|
|
sheet.row(4).concat(["序号", "分班名称", "邀请码", "学生数量"])
|
|
|
current_row = 5
|
|
|
course.course_groups.each do |course_group|
|
|
|
sheet[current_row,0]= current_row - 4
|
|
|
sheet[current_row,1]= course_group.name
|
|
|
sheet[current_row,2]= course_group.invite_code
|
|
|
sheet[current_row,3]= course_group.members.count
|
|
|
current_row += 1
|
|
|
end
|
|
|
end
|
|
|
|
|
|
sheet2 = book.create_worksheet :name => "活跃度"
|
|
|
sheet2[0,0] = "课程编号"
|
|
|
sheet2[0,1] = course.id
|
|
|
sheet2[1,0] = "课程名称"
|
|
|
sheet2[1,1] = course.name
|
|
|
sheet2[2,0] = "教师团队"
|
|
|
sheet2[2,1] = (searchTeacherAndAssistant course).map{|member| member.user.show_real_name}.join('、')
|
|
|
sheet2[3,0] = "主讲教师"
|
|
|
sheet2[3,1] = course.teacher.show_real_name
|
|
|
sheet2.row(4).concat(["排名","学生姓名","昵称","学号","分班","作业完成数(*10)","试卷完成数(*10)","问卷完成数(*7)","资源发布数(*5)","帖子发布数(*2)","帖子回复数(*1)","作业回复数(*1)","活跃度"])
|
|
|
act_members = members
|
|
|
act_members.each do |member|
|
|
|
member[:act_score] = ((member.homework_num.to_i + member.graduation_num.to_i) * 10) + (member.exercise_num.to_i * 10) + (member.poll_num.to_i * 7) + (member.resource_num.to_i * 5) + (member.message_num.to_i * 2) + member.message_reply_num.to_i + member.homework_journal_num.to_i
|
|
|
end
|
|
|
act_members = act_members.sort do |a, b|
|
|
|
[b[:act_score]] <=> [a[:act_score]]
|
|
|
end
|
|
|
count_row = 5
|
|
|
act_members.each_with_index do |act_member, index|
|
|
|
sheet2[count_row,0]= index + 1
|
|
|
sheet2[count_row,1] = act_member.user.show_real_name
|
|
|
sheet2[count_row,2] = act_member.user.login
|
|
|
sheet2[count_row,3] = act_member.user.user_extensions.student_id
|
|
|
sheet2[count_row,4] = act_member.course_group_id == 0 ? "暂无" : act_member.course_group.name
|
|
|
sheet2[count_row,5]= act_member.homework_num.to_i + act_member.graduation_num.to_i
|
|
|
sheet2[count_row,6]= act_member.exercise_num
|
|
|
sheet2[count_row,7]= act_member.poll_num
|
|
|
sheet2[count_row,8]= act_member.resource_num
|
|
|
sheet2[count_row,9]= act_member.message_num
|
|
|
sheet2[count_row,10]= act_member.message_reply_num
|
|
|
sheet2[count_row,11]= act_member.homework_journal_num
|
|
|
sheet2[count_row,12]= act_member.act_score
|
|
|
count_row += 1
|
|
|
end
|
|
|
|
|
|
homeworks.where(:homework_type => 4).includes(:student_works).each_with_index do |home, i|
|
|
|
sheet = book.create_worksheet :name => "#{home.name}"
|
|
|
sheet[0,0] = "课程编号"
|
|
|
sheet[0,1] = course.id
|
|
|
sheet[1,0] = "课程名称"
|
|
|
sheet[1,1] = course.name
|
|
|
sheet[2,0] = "教师团队"
|
|
|
sheet[2,1] = (searchTeacherAndAssistant course).map{|member| member.user.show_real_name}.join('、')
|
|
|
sheet[3,0] = "主讲教师"
|
|
|
sheet[3,1] = course.teacher.show_real_name
|
|
|
sheet[3,0] = "作业批次"
|
|
|
sheet[3,1] = "第#{i+1}次"
|
|
|
sheet[3,0] = "作业名称"
|
|
|
sheet[3,1] = home.name
|
|
|
sheet.row(4).concat([l(:excel_rank),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_homework_des),l(:excel_l_penalty),l(:excel_f_score),l(:excel_commit_time)])
|
|
|
count_row = 5
|
|
|
items = home.student_works.where("work_status != 0").order("work_score desc")
|
|
|
if items.count == 0 && home.publish_time < Time.now && !course.is_end
|
|
|
update_shixun_work_status home
|
|
|
items = StudentWork.where("work_status != 0 and homework_common_id = #{home.id}").order("work_score desc")
|
|
|
end
|
|
|
items.each_with_index do |stu, j|
|
|
|
sheet[count_row,0]= j + 1
|
|
|
sheet[count_row,1] = stu.user.show_real_name
|
|
|
sheet[count_row,2] = stu.user.login
|
|
|
sheet[count_row,3] = stu.user.user_extensions.student_id
|
|
|
sheet[count_row,4] = strip_html stu.description
|
|
|
sheet[count_row,5] = stu.late_penalty
|
|
|
sheet[count_row,6] = stu.work_score.nil? ? l(:label_without_score) : stu.work_score.round(1)
|
|
|
sheet[count_row,7] = format_time(stu.commit_time)
|
|
|
count_row += 1
|
|
|
end
|
|
|
end
|
|
|
|
|
|
homeworks.where(:homework_type => 1).includes(:student_works).each_with_index do |home, i|
|
|
|
sheet = book.create_worksheet :name => "普通作业第#{i+1}次"
|
|
|
sheet[0,0] = "课程编号"
|
|
|
sheet[0,1] = course.id
|
|
|
sheet[1,0] = "课程名称"
|
|
|
sheet[1,1] = course.name
|
|
|
sheet[2,0] = "教师团队"
|
|
|
sheet[2,1] = (searchTeacherAndAssistant course).map{|member| member.user.show_real_name}.join('、')
|
|
|
sheet[3,0] = "主讲教师"
|
|
|
sheet[3,1] = course.teacher.show_real_name
|
|
|
sheet[3,0] = "作业批次"
|
|
|
sheet[3,1] = "第#{i+1}次"
|
|
|
sheet[3,0] = "作业名称"
|
|
|
sheet[3,1] = home.name
|
|
|
if home.anonymous_comment ==0
|
|
|
sheet.row(4).concat([l(:excel_rank),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_homework_des),
|
|
|
l(:excel_t_score),l(:excel_ta_score), l(:excel_n_score),l(:excel_a_penalty),l(:excel_l_penalty),l(:excel_f_score),l(:excel_commit_time)])
|
|
|
else
|
|
|
sheet.row(4).concat([l(:excel_rank),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_homework_des),
|
|
|
l(:excel_t_score),l(:excel_ta_score),l(:excel_l_penalty),l(:excel_f_score),l(:excel_commit_time)])
|
|
|
end
|
|
|
count_row = 5
|
|
|
items = home.student_works.where("work_status != 0").order("work_score desc")
|
|
|
items.each_with_index do |stu, j|
|
|
|
sheet[count_row,0]= j + 1
|
|
|
sheet[count_row,1] = stu.user.show_real_name
|
|
|
sheet[count_row,2] = stu.user.login
|
|
|
sheet[count_row,3] = stu.user.user_extensions.student_id
|
|
|
sheet[count_row,4] = strip_html stu.description
|
|
|
sheet[count_row,5] = stu.teacher_score.nil? ? l(:label_without_score) : stu.teacher_score.round(1)
|
|
|
sheet[count_row,6] = stu.teaching_asistant_score.nil? ? l(:label_without_score) : stu.teaching_asistant_score.round(1)
|
|
|
if home.anonymous_comment ==0
|
|
|
sheet[count_row,7] = stu.student_score.nil? ? l(:label_without_score) : stu.student_score.round(1)
|
|
|
sheet[count_row,8] = (home.teacher_priority == 1 && !stu.teacher_score.nil?) ? 0 : stu.absence_penalty
|
|
|
sheet[count_row,9] = (home.teacher_priority == 1 && !stu.teacher_score.nil?) ? 0 : stu.late_penalty
|
|
|
sheet[count_row,10] = stu.work_score.nil? ? l(:label_without_score) : stu.work_score.round(1)
|
|
|
sheet[count_row,11] = format_time(stu.commit_time)
|
|
|
else
|
|
|
sheet[count_row,7] = (home.teacher_priority == 1 && !stu.teacher_score.nil?) ? 0 : stu.late_penalty
|
|
|
sheet[count_row,8] = stu.work_score.nil? ? l(:label_without_score) : stu.work_score.round(1)
|
|
|
sheet[count_row,9] = format_time(stu.commit_time)
|
|
|
end
|
|
|
count_row += 1
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
homeworks.where(:homework_type => 3).includes(:student_works).each_with_index do |home, i|
|
|
|
sheet = book.create_worksheet :name => "分组作业第#{i+1}次"
|
|
|
sheet[0,0] = "课程编号"
|
|
|
sheet[0,1] = course.id
|
|
|
sheet[1,0] = "课程名称"
|
|
|
sheet[1,1] = course.name
|
|
|
sheet[2,0] = "教师团队"
|
|
|
sheet[2,1] = (searchTeacherAndAssistant course).map{|member| member.user.show_real_name}.join('、')
|
|
|
sheet[3,0] = "主讲教师"
|
|
|
sheet[3,1] = course.teacher.show_real_name
|
|
|
sheet[3,0] = "作业批次"
|
|
|
sheet[3,1] = "第#{i+1}次"
|
|
|
sheet[3,0] = "作业名称"
|
|
|
sheet[3,1] = home.name
|
|
|
|
|
|
if home.anonymous_comment ==0
|
|
|
sheet.row(4).concat([l(:excel_rank),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_group_member),l(:excel_homework_des),
|
|
|
l(:excel_t_score),l(:excel_ta_score),l(:excel_n_score),l(:excel_a_penalty),l(:excel_l_penalty),l(:excel_f_score),l(:excel_commit_time)])
|
|
|
else
|
|
|
sheet.row(4).concat([l(:excel_rank),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_group_member),l(:excel_homework_des),
|
|
|
l(:excel_t_score),l(:excel_ta_score),l(:excel_l_penalty),l(:excel_f_score),l(:excel_commit_time)])
|
|
|
end
|
|
|
count_row = 5
|
|
|
items = home.student_works.where("work_status != 0").order("work_score desc")
|
|
|
items.each_with_index do |stu, j|
|
|
|
sheet[count_row,0] = j + 1
|
|
|
sheet[count_row,1] = stu.user.show_real_name
|
|
|
sheet[count_row,2] = stu.user.login
|
|
|
sheet[count_row,3] = stu.user.user_extensions.student_id
|
|
|
sheet[count_row,4] = get_group_member_names home.student_works.where(:group_id => stu.group_id).pluck(:user_id)
|
|
|
sheet[count_row,5] = strip_html stu.description
|
|
|
sheet[count_row,6] = stu.teacher_score.nil? ? l(:label_without_score) : stu.teacher_score.round(1)
|
|
|
sheet[count_row,7] = stu.teaching_asistant_score.nil? ? l(:label_without_score) : stu.teaching_asistant_score.round(1)
|
|
|
if home.anonymous_comment ==0
|
|
|
sheet[count_row,8] = stu.student_score.nil? ? l(:label_without_score) : stu.student_score.round(1)
|
|
|
sheet[count_row,9] = (home.teacher_priority == 1 && !stu.teacher_score.nil?) ? 0 : stu.absence_penalty
|
|
|
sheet[count_row,10] = (home.teacher_priority == 1 && !stu.teacher_score.nil?) ? 0 : stu.late_penalty
|
|
|
sheet[count_row,11] = stu.work_score.nil? ? l(:label_without_score) : stu.work_score.round(1)
|
|
|
sheet[count_row,12] = format_time(stu.commit_time)
|
|
|
else
|
|
|
sheet[count_row,8] = (home.teacher_priority == 1 && !stu.teacher_score.nil?) ? 0 : stu.late_penalty
|
|
|
sheet[count_row,9] = stu.work_score.nil? ? l(:label_without_score) : stu.work_score.round(1)
|
|
|
sheet[count_row,10] = format_time(stu.commit_time)
|
|
|
end
|
|
|
count_row += 1
|
|
|
end
|
|
|
end
|
|
|
|
|
|
exercises.each_with_index do |exercise, i|
|
|
|
sheet = book.create_worksheet :name => "试卷第#{i+1}次"
|
|
|
sheet[0,0] = "课程编号"
|
|
|
sheet[0,1] = course.id
|
|
|
sheet[1,0] = "课程名称"
|
|
|
sheet[1,1] = course.name
|
|
|
sheet[3,0] = "教师团队"
|
|
|
sheet[3,1] = (searchTeacherAndAssistant course).map{|member| member.user.show_real_name}.join('、')
|
|
|
sheet[3,0] = "主讲教师"
|
|
|
sheet[3,1] = course.teacher.show_real_name
|
|
|
sheet[3,0] = "试卷批次"
|
|
|
sheet[3,1] = "第#{i+1}次"
|
|
|
sheet[3,0] = "试卷名称"
|
|
|
sheet[3,1] = exercise.exercise_name
|
|
|
|
|
|
sheet.row(4).concat([l(:excel_rank),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_objective_score),l(:excel_subjective_score),l(:excel_f_score),l(:excel_answer_time)])
|
|
|
count_row = 5
|
|
|
items = exercise.exercise_users.where("commit_status != 0").order("score desc")
|
|
|
items.each_with_index do |stu, j|
|
|
|
sheet[count_row,0] = j + 1
|
|
|
sheet[count_row,1] = stu.user.show_real_name
|
|
|
sheet[count_row,2] = stu.user.login
|
|
|
sheet[count_row,3] = stu.user.user_extensions.student_id
|
|
|
sheet[count_row,4] = stu.objective_score == -1 ? "0.0" : format("%.1f",stu.objective_score)
|
|
|
sheet[count_row,5] = stu.subjective_score == -1 ? "0.0" : format("%.1f",stu.subjective_score)
|
|
|
sheet[count_row,6] = stu.score.nil? ? '--' : stu.score.round(1)
|
|
|
sheet[count_row,7] = stu.commit_status == 0 ? l(:excel_no_answer) : format_time(stu.start_at)
|
|
|
count_row += 1
|
|
|
end
|
|
|
end
|
|
|
|
|
|
tasks.each_with_index do |task, i|
|
|
|
sheet = book.create_worksheet :name => "毕设任务第#{i+1}次"
|
|
|
sheet[0,0] = "课程编号"
|
|
|
sheet[0,1] = course.id
|
|
|
sheet[1,0] = "课程名称"
|
|
|
sheet[1,1] = course.name
|
|
|
sheet[2,0] = "教师团队"
|
|
|
sheet[2,1] = (searchTeacherAndAssistant course).map{|member| member.user.show_real_name}.join('、')
|
|
|
sheet[3,0] = "主讲教师"
|
|
|
sheet[3,1] = course.teacher.show_real_name
|
|
|
sheet[3,0] = "作业批次"
|
|
|
sheet[3,1] = "第#{i+1}次"
|
|
|
sheet[3,0] = "作业名称"
|
|
|
sheet[3,1] = task.name
|
|
|
sheet.row(4).concat([l(:excel_rank),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id)])
|
|
|
if task.task_type == 2
|
|
|
sheet.row(4).concat([l(:excel_group_member)])
|
|
|
end
|
|
|
sheet.row(4).concat([l(:excel_homework_des), l(:excel_t_score)])
|
|
|
if task.cross_comment
|
|
|
sheet.row(4).concat(["交叉评分"])
|
|
|
end
|
|
|
sheet.row(4).concat([l(:excel_l_penalty),l(:excel_f_score),l(:excel_commit_time)])
|
|
|
count_row = 5
|
|
|
items = task.graduation_works.where("work_status != 0").order("work_score desc")
|
|
|
items.each_with_index do |stu, j|
|
|
|
column = 0
|
|
|
sheet[count_row,column]= j + 1
|
|
|
sheet[count_row,column+=1] = stu.user.show_real_name
|
|
|
sheet[count_row,column+=1] = stu.user.login
|
|
|
sheet[count_row,column+=1] = stu.user.user_extensions.student_id
|
|
|
if task.task_type == 2
|
|
|
sheet[count_row,column+=1] = get_group_member_names task.graduation_works.where(:group_id => stu.group_id).pluck(:user_id)
|
|
|
end
|
|
|
sheet[count_row,column+=1] = strip_html stu.description
|
|
|
sheet[count_row,column+=1] = stu.teacher_score.nil? ? l(:label_without_score) : stu.teacher_score.round(1)
|
|
|
if task.cross_comment
|
|
|
sheet[count_row,column+=1] = stu.cross_score.nil? ? l(:label_without_score) : stu.cross_score.round(1)
|
|
|
end
|
|
|
sheet[count_row,column+=1] = stu.late_penalty
|
|
|
sheet[count_row,column+=1] = stu.work_score.nil? ? l(:label_without_score) : stu.work_score.round(1)
|
|
|
sheet[count_row,column+=1] = format_time(stu.commit_time)
|
|
|
count_row += 1
|
|
|
end
|
|
|
=begin
|
|
|
if task.task_type == 1
|
|
|
if task.cross_comment
|
|
|
sheet.row(4).concat([l(:excel_rank),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_homework_des),
|
|
|
l(:excel_t_score),"交叉评分",l(:excel_l_penalty),l(:excel_f_score),l(:excel_commit_time)])
|
|
|
else
|
|
|
sheet.row(4).concat([l(:excel_rank),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_homework_des),
|
|
|
l(:excel_t_score),l(:excel_l_penalty),l(:excel_f_score),l(:excel_commit_time)])
|
|
|
end
|
|
|
else
|
|
|
if task.cross_comment
|
|
|
sheet.row(4).concat([l(:excel_rank),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_group_member),l(:excel_homework_des),
|
|
|
l(:excel_t_score),"交叉评分",l(:excel_l_penalty),l(:excel_f_score),l(:excel_commit_time)])
|
|
|
else
|
|
|
sheet.row(4).concat([l(:excel_rank),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_group_member),l(:excel_homework_des),
|
|
|
l(:excel_t_score),l(:excel_l_penalty),l(:excel_f_score),l(:excel_commit_time)])
|
|
|
end
|
|
|
count_row = 5
|
|
|
items = task.graduation_works.order("work_score desc")
|
|
|
items.each_with_index do |stu, j|
|
|
|
column = 0
|
|
|
sheet[count_row,column]= j + 1
|
|
|
sheet[count_row,column+1] = stu.user.show_name
|
|
|
sheet[count_row,column+1] = stu.user.login
|
|
|
sheet[count_row,column+1] = stu.user.user_extensions.student_id
|
|
|
sheet[count_row,column+1] = strip_html stu.description
|
|
|
sheet[count_row,column+1] = stu.teacher_score.nil? ? l(:label_without_score) : stu.teacher_score.round(2)
|
|
|
if task.cross_comment
|
|
|
sheet[count_row,column+1] = stu.cross_score.nil? ? l(:label_without_score) : stu.cross_score.round(2)
|
|
|
end
|
|
|
sheet[count_row,column+1] = stu.late_penalty
|
|
|
sheet[count_row,column+1] = stu.work_score.nil? ? l(:label_without_score) : stu.work_score.round(2)
|
|
|
sheet[count_row,column+1] = format_time(stu.commit_time)
|
|
|
count_row += 1
|
|
|
end
|
|
|
end
|
|
|
=end
|
|
|
end
|
|
|
|
|
|
book.write xls_report
|
|
|
xls_report.string
|
|
|
end
|
|
|
|
|
|
end
|