dev_forum
SylorHuang 5 years ago
parent c3087d7b4e
commit 733e782723

@ -17,7 +17,7 @@ class ZipsController < ApplicationController
end end
def export_exercises def export_exercises
exercises = ExportExercisesService.new(@exercise,@ex_users,@request_url) exercises = ExportExercisesService.new(@exercise,@ex_users)
file_name = filename_for_content_disposition(exercises.filename) file_name = filename_for_content_disposition(exercises.filename)
send_file exercises.ex_zip, filename: file_name, type: 'application/zip' send_file exercises.ex_zip, filename: file_name, type: 'application/zip'
@ -41,7 +41,6 @@ class ZipsController < ApplicationController
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
begin begin
@exercise = Exercise.includes(:exercise_users,:exercise_questions).find_by(id:params[:exercise_id]) @exercise = Exercise.includes(:exercise_users,:exercise_questions).find_by(id:params[:exercise_id])
@request_url = request.base_url
group_id = params[:exercise_group_id] group_id = params[:exercise_group_id]
if @exercise.blank? if @exercise.blank?
normal_status(-1,"试卷不存在") normal_status(-1,"试卷不存在")

@ -334,6 +334,7 @@ module ApplicationHelper
raw arr.join('') raw arr.join('')
end end
# 导出pdf时转化markdown为html
def to_markdown(text) def to_markdown(text)
request_url = request.base_url request_url = request.base_url

@ -5,10 +5,9 @@ class ExerciseUserPdfService
attr_reader :exercise, :ex_user attr_reader :exercise, :ex_user
def initialize(exercise, ex_user,request_url) def initialize(exercise, ex_user)
@exercise = exercise @exercise = exercise
@ex_user = ex_user @ex_user = ex_user
@request_url = request_url
@ex_user_user = @ex_user.user @ex_user_user = @ex_user.user
@course = @exercise.course @course = @exercise.course
end end

@ -3,10 +3,9 @@ class ExportExercisesService
include StudentWorksHelper include StudentWorksHelper
attr_reader :exercise, :ex_users attr_reader :exercise, :ex_users
def initialize(exercise, ex_users,request_url) def initialize(exercise, ex_users)
@exercise = exercise @exercise = exercise
@ex_users = ex_users @ex_users = ex_users
@request_url = request_url
end end
def filename def filename
@ -19,7 +18,7 @@ class ExportExercisesService
pdfs = [] pdfs = []
Zip::File.open(zip_file.path, Zip::File::CREATE) do |zip| Zip::File.open(zip_file.path, Zip::File::CREATE) do |zip|
ex_users.each do |ex_user| ex_users.each do |ex_user|
export = ExerciseUserPdfService.new(exercise, ex_user,@request_url) export = ExerciseUserPdfService.new(exercise, ex_user)
pdf = export.ex_pdf pdf = export.ex_pdf
pdfs << pdf pdfs << pdf
begin begin

Loading…
Cancel
Save