|
|
|
@ -37,9 +37,17 @@ 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
|
|
|
|
@ -81,15 +89,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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|