|
@@ -2010,39 +2010,9 @@ class ExamPdfExportService
|
|
|
|
|
|
|
|
// 构造视图需要的变量
|
|
// 构造视图需要的变量
|
|
|
$questions = ['choice' => [], 'fill' => [], 'answer' => []];
|
|
$questions = ['choice' => [], 'fill' => [], 'answer' => []];
|
|
|
- $questionBankIds = $paper->questions
|
|
|
|
|
- ->pluck('question_bank_id')
|
|
|
|
|
- ->filter()
|
|
|
|
|
- ->unique()
|
|
|
|
|
- ->values();
|
|
|
|
|
- $optionsByBankId = [];
|
|
|
|
|
- if ($questionBankIds->isNotEmpty()) {
|
|
|
|
|
- $optionsByBankId = Question::whereIn('id', $questionBankIds)
|
|
|
|
|
- ->pluck('options', 'id')
|
|
|
|
|
- ->toArray();
|
|
|
|
|
- }
|
|
|
|
|
foreach ($paper->questions as $pq) {
|
|
foreach ($paper->questions as $pq) {
|
|
|
$qType = $this->normalizeQuestionType($pq->question_type ?? 'answer');
|
|
$qType = $this->normalizeQuestionType($pq->question_type ?? 'answer');
|
|
|
- $normalizedQuestion = $this->normalizeAnswerFieldForPdf($pq);
|
|
|
|
|
-
|
|
|
|
|
- // 本地渲染链路下,paper_questions 通常不带 options,需要从题库回填选择题选项。
|
|
|
|
|
- if ($qType === 'choice') {
|
|
|
|
|
- $options = $normalizedQuestion->options ?? null;
|
|
|
|
|
- if (empty($options) && ! empty($normalizedQuestion->question_bank_id)) {
|
|
|
|
|
- $options = $optionsByBankId[$normalizedQuestion->question_bank_id] ?? null;
|
|
|
|
|
- }
|
|
|
|
|
- if (is_string($options)) {
|
|
|
|
|
- $decoded = json_decode($options, true);
|
|
|
|
|
- if (json_last_error() === JSON_ERROR_NONE) {
|
|
|
|
|
- $options = $decoded;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- if (is_array($options)) {
|
|
|
|
|
- $normalizedQuestion->options = $options;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- $questions[$qType][] = $normalizedQuestion;
|
|
|
|
|
|
|
+ $questions[$qType][] = $this->normalizeAnswerFieldForPdf($pq);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$studentModel = \App\Models\Student::find($paper->student_id);
|
|
$studentModel = \App\Models\Student::find($paper->student_id);
|