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%> <% if is_student %> @@ -92,7 +92,8 @@ <% end %> - <% if (User.current == homework.user) || (!Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.nil? && (Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.roles&Role.where('id = ? or id = ? or id =?',3,7, 9)).size >0) %> + <% if (User.current == homework.user) || (!Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.nil? && + (Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.roles&Role.where('id = ? or id = ? or id =?',3,7, 9)).size >0) %> <%= link_to l(:button_edit), edit_homework_attach_path(homework) %> <%= link_to(l(:label_bid_respond_delete), homework, method: :delete, :confirm => l(:text_are_you_sure)) %> diff --git a/config/routes.rb b/config/routes.rb index 446c720a..91c2047b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -46,10 +46,13 @@ RedmineApp::Application.routes.draw do match 'showbug', via: [:get, :post] end end + + mount SeemsRateable::Engine => '/rateable', :as => :rateable namespace :zipdown do match 'assort' + match 'download_user_homework', :as => :download_user_homework end namespace :test do match 'courselist'