作业所有作品附件打包下载
This commit is contained in:
parent
a1e28bcd9e
commit
ff4dae56d1
|
@ -29,26 +29,25 @@ class ZipdownController < ApplicationController
|
|||
render file: 'public/no_file_found.html'
|
||||
return
|
||||
end
|
||||
elsif params[:obj_class] == "HomeworkCommon"
|
||||
homework = HomeworkCommon.find params[:obj_id]
|
||||
render_403 if User.current.allowed_to?(:as_teacher,homework.course)
|
||||
file_count = 0
|
||||
homework.student_works.map { |work| file_count += work.attachments.count}
|
||||
if file_count > 0
|
||||
zipfile = zip_homework_common homework
|
||||
else
|
||||
render file: 'public/no_file_found.html'
|
||||
return
|
||||
end
|
||||
else
|
||||
logger.error "[ZipDown#assort] ===> #{params[:obj_class]} unKown !!"
|
||||
end
|
||||
|
||||
# if zipfile
|
||||
# if zipfile.length > 1
|
||||
# @mut_down_files = zipfile #zipfile.each{|x| File.basename(x)}
|
||||
# else
|
||||
# send_file zipfile.first[:real_file], :filename => bid.name + ".zip", :type => detect_content_type(zipfile.first[:real_file])
|
||||
# return
|
||||
# end
|
||||
# end
|
||||
|
||||
respond_to do |format|
|
||||
format.json {
|
||||
render json: zipfile.to_json
|
||||
}
|
||||
end
|
||||
#rescue Exception => e
|
||||
# render file: 'public/no_file_found.html'
|
||||
end
|
||||
|
||||
#下载某一学生的作业的所有文件
|
||||
|
@ -98,29 +97,34 @@ class ZipdownController < ApplicationController
|
|||
digests << out_file.file_digest
|
||||
end
|
||||
end
|
||||
|
||||
homework_id = bid.id
|
||||
user_id = bid.author_id
|
||||
|
||||
|
||||
out_file = find_or_pack(homework_id, user_id, digests.sort){
|
||||
zipping("#{Time.now.to_i}_#{bid.name}.zip",
|
||||
bid_homework_path, OUTPUT_FOLDER)
|
||||
}
|
||||
[{files:[out_file.file_path], count: 1, index: 1,
|
||||
real_file: out_file.file_path, file: File.basename(out_file.file_path),
|
||||
size:(out_file.pack_size / 1024.0 / 1024.0).round(2)
|
||||
}]
|
||||
end
|
||||
|
||||
|
||||
# zips = split_pack_files(bid_homework_path, Setting.pack_attachment_max_size.to_i*1024)
|
||||
# x = 0
|
||||
#
|
||||
#
|
||||
# zips.each { |o|
|
||||
# x += 1
|
||||
# file = zipping "#{Time.now.to_i}_#{bid.name}_#{x}.zip", o[:files], OUTPUT_FOLDER
|
||||
# o[:real_file] = file
|
||||
# o[:file] = File.basename(file)
|
||||
# o[:size] = (File.size(file) / 1024.0 / 1024.0).round(2)
|
||||
# }
|
||||
|
||||
def zip_homework_common homework_common
|
||||
bid_homework_path = []
|
||||
digests = []
|
||||
homework_common.student_works.each do |work|
|
||||
unless work.attachments.empty?
|
||||
out_file = zip_student_work_by_user(work)
|
||||
bid_homework_path << out_file.file_path
|
||||
digests << out_file.file_digest
|
||||
end
|
||||
end
|
||||
homework_id = homework_common.id
|
||||
user_id = homework_common.user_id
|
||||
out_file = find_or_pack(homework_id, user_id, digests.sort){
|
||||
zipping("#{Time.now.to_i}_#{homework_common.name}.zip",
|
||||
bid_homework_path, OUTPUT_FOLDER)
|
||||
}
|
||||
[{files:[out_file.file_path], count: 1, index: 1,
|
||||
real_file: out_file.file_path, file: File.basename(out_file.file_path),
|
||||
size:(out_file.pack_size / 1024.0 / 1024.0).round(2)
|
||||
|
@ -131,8 +135,6 @@ class ZipdownController < ApplicationController
|
|||
homeworks_attach_path = []
|
||||
not_exist_file = []
|
||||
# 需要将所有homework.attachments遍历加入zip
|
||||
|
||||
|
||||
digests = []
|
||||
homework_attach.attachments.each do |attach|
|
||||
if File.exist?(attach.diskfile)
|
||||
|
@ -143,12 +145,30 @@ class ZipdownController < ApplicationController
|
|||
digests << 'not_exist_file'
|
||||
end
|
||||
end
|
||||
|
||||
out_file = find_or_pack(homework_attach.bid_id, homework_attach.user_id, digests.sort){
|
||||
zipping("#{homework_attach.user.lastname}#{homework_attach.user.firstname}_#{((homework_attach.user.user_extensions.nil? || homework_attach.user.user_extensions.student_id.nil?) ? "" : homework_attach.user.user_extensions.student_id)}_#{Time.now.to_i.to_s}.zip",
|
||||
homeworks_attach_path, OUTPUT_FOLDER, true, not_exist_file)
|
||||
}
|
||||
end
|
||||
|
||||
def zip_student_work_by_user work
|
||||
homeworks_attach_path = []
|
||||
not_exist_file = []
|
||||
# 需要将所有homework.attachments遍历加入zip
|
||||
digests = []
|
||||
work.attachments.each do |attach|
|
||||
if File.exist?(attach.diskfile)
|
||||
homeworks_attach_path << attach.diskfile
|
||||
digests << attach.digest
|
||||
else
|
||||
not_exist_file << attach.filename
|
||||
digests << 'not_exist_file'
|
||||
end
|
||||
end
|
||||
out_file = find_or_pack(work.homework_common_id, work.user_id, digests.sort){
|
||||
zipping("#{work.user.lastname}#{work.user.firstname}_#{((work.user.user_extensions.nil? || work.user.user_extensions.student_id.nil?) ? "" : work.user.user_extensions.student_id)}_#{Time.now.to_i.to_s}.zip",
|
||||
homeworks_attach_path, OUTPUT_FOLDER, true, not_exist_file)
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -38,7 +38,13 @@
|
|||
</span>
|
||||
<input type="text" value="<%= @name%>" placeholder="昵称、学号、姓名搜索" class="min_search ml10 fl" onkeypress="SearchByName($(this),'<%= student_work_index_path(:homework => @homework.id)%>',event);">
|
||||
<div class="fr">
|
||||
<a class="down_btn fr" href="javascript:void(0);">附件</a>
|
||||
<% if @homework.student_works.empty?%>
|
||||
<%= link_to "附件", "javascript:void(0)", class: "down_btn fr", :onclick => "alert('没有学生提交作业,无法下载附件')" %>
|
||||
<% else%>
|
||||
<%= link_to "附件", zipdown_assort_path(obj_class: @homework.class, obj_id: @homework, format: :json),
|
||||
remote: true, class: "down_btn fr" %>
|
||||
<% end%>
|
||||
|
||||
<a class="down_btn fr" href="javascript:void(0);">列表</a>
|
||||
<span class="mt3 fr " style="color:#136b3b;">导出全部:</span>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue