2013-08-12 17:30:31 +08:00
|
|
|
class TestController < ApplicationController
|
|
|
|
|
2014-04-14 17:36:23 +08:00
|
|
|
def zip
|
|
|
|
homeworks_attach_path = []
|
|
|
|
homework_id = params[:homework_id]
|
|
|
|
bid = Bid.find_by_id(homework_id)
|
|
|
|
|
|
|
|
bid.homeworks.each do |homeattach|
|
|
|
|
homeattach.attachments.each do |attach|
|
2014-04-14 21:59:32 +08:00
|
|
|
homeworks_attach_path << attach.disk_filename
|
2014-04-14 17:36:23 +08:00
|
|
|
end
|
2013-08-12 17:30:31 +08:00
|
|
|
end
|
2014-04-14 17:36:23 +08:00
|
|
|
@paths = homeworks_attach_path
|
|
|
|
zipfile = ziping homeworks_attach_path
|
|
|
|
send_file zipfile, :filename => bid.name,
|
|
|
|
:type => detect_content_type(zipfile)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def courselist
|
|
|
|
@courses = Project.course_entities
|
|
|
|
end
|
|
|
|
|
|
|
|
def ziping files_path
|
2014-04-14 21:59:32 +08:00
|
|
|
folder = "#{Rails.root}/files"
|
2014-04-14 17:36:23 +08:00
|
|
|
input_filename = files_path
|
2014-04-14 21:59:32 +08:00
|
|
|
zipfile_name = "#{Rails.root}/tmp/archive_#{Time.now.to_i}.zip"
|
2014-04-14 17:36:23 +08:00
|
|
|
|
|
|
|
Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile|
|
|
|
|
input_filename.each do |filename|
|
|
|
|
zipfile.add(filename, folder + '/' + filename)
|
|
|
|
end
|
|
|
|
zipfile.get_ouput_stream("ReadMe"){ |os|
|
2014-04-14 21:59:32 +08:00
|
|
|
os.write "Homeworks"
|
2014-04-14 17:36:23 +08:00
|
|
|
}
|
|
|
|
end
|
|
|
|
zipfile_name
|
|
|
|
end
|
|
|
|
|
|
|
|
def detect_content_type(name)
|
|
|
|
content_type = Redmine::MimeType.of(name)
|
|
|
|
content_type.to_s
|
|
|
|
end
|
2013-08-12 17:30:31 +08:00
|
|
|
end
|