@php
use Gomee\Html\Dom\HtmlDomParser;
$tidy = new \tidy();
$question_count = 0;
$alphabet = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'];
@endphp
{{-- thithuthptqg.vn --}}
{{-- --}}
{{-- --}}
{!! $exam->header !!}
@php
$question_count = 0;
$alphabet = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'];
@endphp
STT |
Nội dung câu hỏi |
Đáo án |
@php
$parseQuestionContent = function ($content, $type, $slug = 'any') use ($tidy) {
$cleanStyle = function ($element, $factory) {
if ($element->style) {
$element->style = str_replace(['"', '"'], "'", trim(trim($element->style), ';'));
}
if ($element->style) {
if (preg_match('/\;$/i', trim($element->style))) {
$element->style .= 'vertical-align: middle;font-size:11pt;';
} else {
$element->style .= ';vertical-align: middle;font-size:11pt;';
}
} else {
$element->style = 'vertical-align: middle;font-size:11pt;';
}
if ($element->face) {
if (!preg_match('/symbol/i', $element->face)) {
$element->face = '';
}
}
if (count($ch = $element->children())) {
foreach ($ch as $c) {
$factory($c, $factory);
}
}
};
$cleanTableHasOneTD = function ($self, $element, $tagConvertTo = 'div') {
if (count($children = $element->children())) {
foreach ($children as $child) {
$self($self, $child, $tagConvertTo);
}
}
if ($element->tag == 'table') {
if (count($tds = $element->find('td,th')) == 1) {
$td = $tds[0]->innertext;
$element->innertext = $td;
$element->tag = $tagConvertTo;
} else {
$c = 0;
$trs = $element->find('tr');
$innerText = '';
if ($trs) {
foreach ($trs as $tr) {
if (count($tdh = $tr->find('td,th')) == 1) {
$innerText .= '' . $tdh[0]->innertext . '
';
$c++;
}
}
}
if ($c == count($trs)) {
$element->tag = 'div';
$element->innertext = $innerText;
}
}
}
return $element;
};
$content = $tidy->repairString($content, []);
$htmlDom = HtmlDomParser::str_get_html($content);
$questionContents = $htmlDom->find('body > *');
$needParagraph = count($htmlDom->find('body > p')) < 1;
$hasParagraph = false;
foreach ($questionContents as $key => $item) {
if ($item->tag != 'p') {
if ($item->find('p')) {
$hasParagraph = true;
}
}
// else {
// if ($item->style) {
// if (preg_match('/\;$/i', trim($item->style))) {
// $item->style .= 'vertical-align: middle;font-size:11pt;';
// } else {
// $item->style .= ';vertical-align: middle;font-size:11pt;';
// }
// } else {
// $item->style = 'vertical-align: middle;font-size:11pt;';
// }
// }
$cleanStyle($item, $cleanStyle);
}
$questionHtml = '';
$i = 0;
$isset = false;
$canSet = true;
foreach ($questionContents as $index => $item) {
// $item->align = 'middle';
$questionImgs = $item->find('img');
if (count($questionImgs)) {
foreach ($questionImgs as $key => $img) {
$img->style .= 'vertical-align: middle;margin-bottom:-3pt;position:relative;';
$img->align = 'absmiddle';
}
}
if ($item->style) {
if (preg_match('/\;$/i', trim($item->style))) {
$item->style .= 'position:relative';
} else {
$item->style .= ';position:relative;';
}
} else {
$item->style = 'position:relative;';
}
if ($item->tag == 'font') {
$item->tag = 'span';
}
// $fonts = $item->find('font');
// if($fonts && count($fonts)){
// foreach ($fonts as $f) {
// if($f->tag == 'font') $f->tag = 'span';
// }
// }
$fonts = $item->find('*');
if ($fonts && count($fonts)) {
foreach ($fonts as $f) {
if ($f->tag != 'img') {
if ($f->style) {
if (preg_match('/\;$/i', trim($f->style))) {
$f->style .= 'padding-bottom:3pt;';
} else {
$f->style .= ';padding-bottom:3pt;';
}
} else {
$f->style = 'padding-bottom:3pt;';
}
}
}
}
if ($i == 0) {
if ($t = count($p = $item->find('p'))) {
$p[0]->align = 'left';
for ($ind = 1; $ind < $t; $ind++) {
$p[$ind]->align = null;
}
if ($p[0]->style) {
if (preg_match('/\;$/i', trim($p[0]->style))) {
} else {
$p[0]->style .= ';';
}
if (preg_match('/text\-align\:\s*center/i', $p[0]->style)) {
$p[0]->style = preg_replace('/text\-align\:\s*center/i', 'text-align: left', $p[0]->style);
} else {
$p[0]->style .= 'text-align: left;';
}
$p[0]->style .= 'line-height: 155%;';
} else {
$p[0]->style = 'text-align: left;line-height: 155%;';
}
} else {
}
}
if ($item->tag == 'img') {
$canSet = false;
}
// if ($type != 'group' && !$isset && $canSet) {
// $lastParent = htmlGetLastParent($item);
// if ($parentText = str_slug(trim(strip_tags($lastParent->innertext(), ['img'])))) {
// $lastParent->innertext = "" . ($slug == 'TA' ? '' : 'Câu') . " {$question_count}. " . $lastParent->innertext;
// $isset = true;
// }
// }
$cleanTableHasOneTD($cleanTableHasOneTD, $item);
$currenthtml = $item->outertext();
// preg_match_all('/\]*src=(\'[^\']+\'|\"[^\"]+\")\s[^>]*\>/i', $currenthtml, $matches);
// if ($matches[0]) {
// foreach ($matches[0] as $tag) {
// // $currenthtml = str_replace($tag, ''.$tag.' ', $currenthtml);
// }
// }
$questionHtml .= $currenthtml;
$questionHtml = str_replace('align="justify"', '', $questionHtml);
$i++;
}
// if ($type != 'group' && !$isset) {
// $questionHtml = "" . ($slug == 'TA' ? '' : 'Câu') . " {$question_count}." . $questionHtml;
// }
return $questionHtml;
};
@endphp
@if ($t = count($questionListMap))
@foreach ($questionListMap as $questionMap)
@php
$mapType = $questionMap['type'] ?? '';
$slug = $questionMap['subject']->slug;
$points = to_number($questionMap['points'] ?? 0);
$title = $questionMap['title'] ?? null;
@endphp
@if ($mapType == 'subject-topic')
@if ($questionMap['topics'] && count($questionMap['topics']))
@foreach ($questionMap['topics'] as $topicData)
@if ($topicData['questions'] && count($topicData['questions']))
@foreach ($topicData['questions'] as $question)
@php
$question_count++;
$content = $parseQuestionContent($question->content, $question->type, $slug);
@endphp
@if ($question->type != 'group')
{{ $question_count }} |
{!! $content !!} |
@foreach ($question->answers as $answer)
@if ($question->answer_uuid == $answer->uuid)
{{ $alphabet[$loop->index] }}
@endif
@endforeach
|
@else
@php
$question_count--;
@endphp
@if ($question->children && count($question->children))
@foreach ($question->children as $child)
@php
$question_count++;
$content = $parseQuestionContent($child->content, $question->type, $slug);
@endphp
{{ $question_count }} |
{!! $content !!} |
@foreach ($child->answers as $answer)
@if ($child->answer_uuid == $answer->uuid)
{{ $alphabet[$loop->index] }}
@endif
@endforeach
|
@endforeach
@endif
@endif
@endforeach
@endif
@endforeach
@endif
@elseif($mapType == 'topic')
@if ($questionMap['questions'] && count($tquestionMap['questions']))
@foreach ($questionMap['questions'] as $question)
@php
$question_count++;
@endphp
@if ($question->type != 'group')
{{ $question_count }} |
{!! $question->content !!} |
@foreach ($question->answers as $answer)
@if ($question->answer_uuid == $answer->uuid)
{{ $alphabet[$loop->index] }}
@endif
@endforeach
|
@else
@php
$question_count--;
@endphp
@if ($question->children && count($question->children))
@foreach ($question->children as $child)
@php
$question_count++;
@endphp
{{ $question_count }} |
{!! $child->content !!} |
@foreach ($child->answers as $answer)
@if ($child->answer_uuid == $answer->uuid)
{{ $alphabet[$loop->index] }}
@endif
@endforeach
|
@endforeach
@endif
@endif
@endforeach
@endif
@endif
@endforeach
@endif