|
|
|
@ -37,12 +37,22 @@ class ZipdownController < ApplicationController
|
|
|
|
|
#下载某一学生的作业的所有文件
|
|
|
|
|
def download_user_homework
|
|
|
|
|
homework = HomeworkAttach.find params[:homework]
|
|
|
|
|
if homework != nil && (User.current.admin? || User.current.member_of_course?(homework.bid.courses.first))
|
|
|
|
|
zipfile = zip_homework_by_user homework
|
|
|
|
|
send_file zipfile, :filename => homework.name+".zip", :type => detect_content_type(zipfile) if zipfile
|
|
|
|
|
if User.current.admin? || User.current.member_of_course?(homework.bid.courses.first)
|
|
|
|
|
if homework != nil
|
|
|
|
|
if homework.attachments.count > 0
|
|
|
|
|
zipfile = zip_homework_by_user homework
|
|
|
|
|
send_file zipfile, :filename => homework.name+".zip", :type => detect_content_type(zipfile) if(zipfile)
|
|
|
|
|
else
|
|
|
|
|
render_403 :message => :no_file_dowmload
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
render_403 :message =>:notice_file_not_found
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
render_403 :message => :notice_not_authorized
|
|
|
|
|
end
|
|
|
|
|
rescue => e
|
|
|
|
|
render file: 'public/file_not_found.html'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
@ -67,7 +77,9 @@ class ZipdownController < ApplicationController
|
|
|
|
|
# 得到每一个人所有文件打包的zip文件
|
|
|
|
|
# 并将每一个人的zip打包为一个并返回路径
|
|
|
|
|
user_zip_paths = homeattaches.map do |homeattach|
|
|
|
|
|
zip_homework_by_user homeattach
|
|
|
|
|
if homeattach.attachments.count > 0
|
|
|
|
|
zip_homework_by_user homeattach
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
zipping "#{Time.now.to_i}_#{bid.name}.zip", user_zip_paths, OUTPUT_FOLDER
|
|
|
|
|
|
|
|
|
@ -81,15 +93,17 @@ class ZipdownController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def zip_homework_by_user(homeattach)
|
|
|
|
|
homeworks_attach_path = []
|
|
|
|
|
# 需要将所有homework.attachments遍历加入zip
|
|
|
|
|
# 并且返回zip路径
|
|
|
|
|
user_attaches_paths = homeattach.attachments.each do |attach|
|
|
|
|
|
#length = attach.storage_path.length
|
|
|
|
|
homeworks_attach_path << attach.diskfile#.to_s.slice((length+1)..-1)
|
|
|
|
|
end
|
|
|
|
|
zipping "#{homeattach.user.name.to_s}_#{Time.now.to_i}.zip", homeworks_attach_path, OUTPUT_FOLDER, true
|
|
|
|
|
#user_attaches_paths
|
|
|
|
|
#if homeattach.attachments.count > 0
|
|
|
|
|
homeworks_attach_path = []
|
|
|
|
|
# 需要将所有homework.attachments遍历加入zip
|
|
|
|
|
# 并且返回zip路径
|
|
|
|
|
user_attaches_paths = homeattach.attachments.each do |attach|
|
|
|
|
|
#length = attach.storage_path.length
|
|
|
|
|
homeworks_attach_path << attach.diskfile#.to_s.slice((length+1)..-1)
|
|
|
|
|
end
|
|
|
|
|
zipping("#{homeattach.user.name.to_s}_#{Time.now.to_i}.zip", homeworks_attach_path, OUTPUT_FOLDER, true)
|
|
|
|
|
#user_attaches_paths
|
|
|
|
|
#end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|