diff --git a/app/controllers/zipdown_controller.rb b/app/controllers/zipdown_controller.rb index 57078a43..5f5a2227 100644 --- a/app/controllers/zipdown_controller.rb +++ b/app/controllers/zipdown_controller.rb @@ -20,8 +20,36 @@ class ZipdownController < ApplicationController #@error = e end + #下载某一学生的作业的所有文件 + def download_user_homework + obj_class = params[:obj_class] + obj_id = params[:obj_id] + user_id = params[:user_id] + obj = obj_class.constantize.find(obj_id) + zipfile = nil + case obj.class.to_s.to_sym + when :Bid + zipfile = zip_user_bid obj,user_id + else + logger.error "[ZipDown#assort] ===> #{obj.class.to_s.to_sym} unKown !!" + end + send_file zipfile, :filename => obj.name, :type => detect_content_type(zipfile) if zipfile + end + private + def zip_user_bid(bid,user_id) + # Todo: User Access Controll + + homeattaches = bid.homeworks.where("user_id = ?",user_id) + # 得到每一个人所有文件打包的zip文件 + # 并将每一个人的zip打包为一个并返回路径 + user_zip_paths = homeattaches.map do |homeattach| + zip_homework_by_user homeattach + end + zipping "#{Time.now.to_i}_#{bid.name}.zip", user_zip_paths, OUTPUT_FOLDER + end + def zip_bid(bid) # Todo: User Access Controll diff --git a/app/views/bids/_homework_list.html.erb b/app/views/bids/_homework_list.html.erb index c8ed051e..fd4b0a93 100644 --- a/app/views/bids/_homework_list.html.erb +++ b/app/views/bids/_homework_list.html.erb @@ -50,10 +50,10 @@ <% end %> --> <% end %> - <%= homework_filename %> <% else %> - <%= homework.name %> + <% homework_filename = homework.name %> <% end %> + <%= link_to homework_filename, :controller => "zipdown", :action => "download_user_homework",:obj_class => @bid.class,:obj_id => @bid, :user_id =>homework.user%>