|
|
|
@ -21,6 +21,7 @@ class HomeworkAttachController < ApplicationController
|
|
|
|
|
|
|
|
|
|
#获取未批作业列表
|
|
|
|
|
def get_not_batch_homework
|
|
|
|
|
@not_batch_homework = true
|
|
|
|
|
sort, direction = params[:sort] || "s_socre", params[:direction] || "desc"
|
|
|
|
|
get_not_batch_homework_list sort,direction, @bid.id
|
|
|
|
|
@cur_page = params[:page] || 1
|
|
|
|
@ -28,12 +29,17 @@ class HomeworkAttachController < ApplicationController
|
|
|
|
|
@direction = direction == 'asc'? 'desc' : 'asc'
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.js
|
|
|
|
|
format.xls {
|
|
|
|
|
send_data(homework_to_xls(@all_homework_list), :type => "text/excel;charset=utf-8; header=present",
|
|
|
|
|
:filename => "not_rated_homework_#{Time.now.strftime("%Y%m%d")}.xls")
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#获取已评作业列表
|
|
|
|
|
def get_batch_homeworks
|
|
|
|
|
sort, direction = params[:sort] || "s_socre", params[:direction] || "desc"
|
|
|
|
|
@is_batch_homeworks = true
|
|
|
|
|
if sort == 't_socre'
|
|
|
|
|
order_by = "t_score #{direction}"
|
|
|
|
|
elsif sort == 's_socre'
|
|
|
|
@ -53,33 +59,18 @@ class HomeworkAttachController < ApplicationController
|
|
|
|
|
@direction = direction == 'asc'? 'desc' : 'asc'
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.js
|
|
|
|
|
format.csv {
|
|
|
|
|
send_data(homework_to_csv(all_homework_list), :type => 'text/csv; header=present', :filename => 'issues.csv')
|
|
|
|
|
format.xls {
|
|
|
|
|
send_data(homework_to_xls(all_homework_list), :type => "text/excel;charset=utf-8; header=present",
|
|
|
|
|
:filename => "been_rated_homework_#{Time.now.strftime("%Y%m%d")}.xls")
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def homework_to_csv items
|
|
|
|
|
encoding = l(:general_csv_encoding)
|
|
|
|
|
columns = ["student_id","user_name","login","student_num","mail","work_name","teacher_score","ni_score","commit_time"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv|
|
|
|
|
|
# csv header fields
|
|
|
|
|
csv << columns.collect {|c| Redmine::CodesetUtil.from_utf8(c, encoding) }
|
|
|
|
|
# csv lines
|
|
|
|
|
items.each do |homework|
|
|
|
|
|
csv << [homework.user.id,Redmine::CodesetUtil.from_utf8(homework.user.lastname.to_s + homework.user.firstname.to_s, encoding),Redmine::CodesetUtil.from_utf8(homework.user.login, encoding),
|
|
|
|
|
Redmine::CodesetUtil.from_utf8(homework.user.user_extensions.student_id, encoding),Redmine::CodesetUtil.from_utf8(homework.user.mail, encoding),Redmine::CodesetUtil.from_utf8(homework.name, encoding),
|
|
|
|
|
Redmine::CodesetUtil.from_utf8((homework.t_score.nil? || (homework.t_score && homework.t_score.to_i == 0)) ? l(:label_without_score) : format("%.2f",homework.t_score), encoding),
|
|
|
|
|
Redmine::CodesetUtil.from_utf8( homework.s_score.nil? ? l(:label_without_score) : format("%.2f",homework.s_score), encoding),Redmine::CodesetUtil.from_utf8(format_time(homework.created_at), encoding)]
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
export
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#获取所有作业列表
|
|
|
|
|
def get_homeworks
|
|
|
|
|
@is_all_homeworks = true
|
|
|
|
|
sort, direction = params[:sort] || "s_socre", params[:direction] || "desc"
|
|
|
|
|
if sort == 't_socre'
|
|
|
|
|
order_by = "t_score #{direction}"
|
|
|
|
@ -99,6 +90,10 @@ class HomeworkAttachController < ApplicationController
|
|
|
|
|
@direction = direction == 'asc'? 'desc' : 'asc'
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.js
|
|
|
|
|
format.xls {
|
|
|
|
|
send_data(homework_to_xls(all_homework_list), :type => "text/excel;charset=utf-8; header=present",
|
|
|
|
|
:filename => "all_homework_#{Time.now.strftime("%Y%m%d")}.xls")
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
@ -582,18 +577,65 @@ class HomeworkAttachController < ApplicationController
|
|
|
|
|
elsif sort == 'time'
|
|
|
|
|
order_by = "created_at #{direction}"
|
|
|
|
|
end
|
|
|
|
|
all_homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT * FROM (SELECT homework_attaches.*,
|
|
|
|
|
@all_homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT * FROM (SELECT homework_attaches.*,
|
|
|
|
|
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 1) AS t_score,
|
|
|
|
|
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) AS s_score
|
|
|
|
|
FROM homework_attaches WHERE bid_id = #{bid_id}
|
|
|
|
|
ORDER BY #{order_by}) AS table1
|
|
|
|
|
WHERE table1.t_score IS NULL")
|
|
|
|
|
@homework_list = paginateHelper all_homework_list,10
|
|
|
|
|
@homework_list = paginateHelper @all_homework_list,10
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#获取指定作业的所有成员
|
|
|
|
|
def users_for_homework homework
|
|
|
|
|
homework.nil? ? [] : (homework.users + [homework.user])
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def homework_to_csv items
|
|
|
|
|
encoding = l(:general_csv_encoding)
|
|
|
|
|
columns = ["student_id","user_name","login","student_num","mail","work_name","teacher_score","ni_score","commit_time"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv|
|
|
|
|
|
# csv header fields
|
|
|
|
|
csv << columns.collect {|c| Redmine::CodesetUtil.from_utf8(c, encoding) }
|
|
|
|
|
# csv lines
|
|
|
|
|
items.each do |homework|
|
|
|
|
|
csv << [homework.user.id,Redmine::CodesetUtil.from_utf8(homework.user.lastname.to_s + homework.user.firstname.to_s, encoding),Redmine::CodesetUtil.from_utf8(homework.user.login, encoding),
|
|
|
|
|
Redmine::CodesetUtil.from_utf8(homework.user.user_extensions.student_id, encoding),Redmine::CodesetUtil.from_utf8(homework.user.mail, encoding),Redmine::CodesetUtil.from_utf8(homework.name, encoding),
|
|
|
|
|
Redmine::CodesetUtil.from_utf8((homework.t_score.nil? || (homework.t_score && homework.t_score.to_i == 0)) ? l(:label_without_score) : format("%.2f",homework.t_score), encoding),
|
|
|
|
|
Redmine::CodesetUtil.from_utf8( homework.s_score.nil? ? l(:label_without_score) : format("%.2f",homework.s_score), encoding),Redmine::CodesetUtil.from_utf8(format_time(homework.created_at), encoding)]
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
export
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def homework_to_xls items
|
|
|
|
|
xls_report = StringIO.new
|
|
|
|
|
book = Spreadsheet::Workbook.new
|
|
|
|
|
sheet1 = book.create_worksheet :name => "homework"
|
|
|
|
|
|
|
|
|
|
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_homework_name),
|
|
|
|
|
l(:excel_t_score),l(:excel_n_score),l(:excel_commit_time)])
|
|
|
|
|
count_row = 1
|
|
|
|
|
items.each do |homework|
|
|
|
|
|
sheet1[count_row,0]=homework.user.id
|
|
|
|
|
sheet1[count_row,1] = homework.user.lastname.to_s + homework.user.firstname.to_s
|
|
|
|
|
sheet1[count_row,2] = homework.user.login
|
|
|
|
|
sheet1[count_row,3] = homework.user.user_extensions.student_id
|
|
|
|
|
sheet1[count_row,4] = homework.user.mail
|
|
|
|
|
sheet1[count_row,5] = homework.name
|
|
|
|
|
sheet1[count_row,6] =(homework.t_score.nil? || (homework.t_score && homework.t_score.to_i == 0)) ? l(:label_without_score) : format("%.2f",homework.t_score)
|
|
|
|
|
sheet1[count_row,7] = homework.s_score.nil? ? l(:label_without_score) : format("%.2f",homework.s_score)
|
|
|
|
|
sheet1[count_row,8] = format_time(homework.created_at)
|
|
|
|
|
count_row += 1
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
book.write xls_report
|
|
|
|
|
xls_report.string
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|