@php use Gomee\Html\Dom\HtmlDomParser; $tidy = new \tidy(); $question_count = 0; $alphabet = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J']; @endphp @php $parseQuestionContent = function ($content, $type, $question_count, $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 { // } $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; }; $parseAnswerContent = function ($content, $label) use ($tidy) { $cleanStyle = function ($element, $factory) { if ($element->style) { $element->style = str_replace(['"', '"'], "'", trim(trim($element->style), ';')); } if ($element->face) { if (!preg_match('/symbol/i', $element->face)) { $element->face = ''; } } if (count($ch = $element->children())) { foreach ($ch as $c) { $factory($c, $factory); } } }; $answerContent = $tidy->repairString($content, []); $a = trim($answerContent); if (preg_match('/<\/*[A-z]+$/is', $a)) { $answerContent .= '>'; } $answerDom = HtmlDomParser::str_get_html($answerContent); $answerContent = ''; $answerContents = $answerDom->find('body > *'); $icm = 0; $isset = false; foreach ($answerContents as $key => $ansItem) { $answerImgs = $ansItem->find('img'); if (count($answerImgs)) { foreach ($answerImgs as $img) { $img->style .= 'vertical-align: middle;'; $img->align = 'middle'; } } $answerContent .= $ansItem->outertext(); } $answerContent = $tidy->repairString($answerContent, []); $answerDom = HtmlDomParser::str_get_html($answerContent); $answerContent = ''; $answerContents = $answerDom->find('body > *'); $icm = 0; $isset = false; foreach ($answerContents as $key => $ansItem) { $cleanStyle($ansItem, $cleanStyle); if (!$isset && $ansItem->tag != 'img' && $icm == 0) { if ($ansItem->tag == 'p') { $text = $ansItem->innertext; $ansItem->innertext = "$label. " . $text; $isset = true; } elseif (count($p = $ansItem->find('p'))) { $text = $p[0]->innertext; $p[0]->innertext = "$label. " . $p[0]->innertext; $isset = true; } elseif ($ansItem->tag == 'div') { $text = $ansItem->innertext; $ansItem->innertext = "$label. " . $text; $isset = true; } } if ($ansItem->style) { if (preg_match('/\;$/i', trim($ansItem->style))) { $ansItem->style .= 'vertical-align: middle;font-size:11pt;'; } else { $ansItem->style .= ';vertical-align: middle;font-size:11pt;'; } } else { $ansItem->style = 'vertical-align: middle;font-size:11pt;'; } $answerContent .= $ansItem->outertext(); $icm++; } if (!$isset) { $answerContent = "$label. " . $answerContent; } return $answerContent; }; $inssetEndOfFirst = function ($content, $label) use ($tidy) { $answerContent = $tidy->repairString($content, []); $answerDom = HtmlDomParser::str_get_html($answerContent); $answerContent = ''; $answerContents = $answerDom->find('body > *'); $icm = 0; $isset = false; foreach ($answerContents as $key => $ansItem) { if ($key == 0) { if ($lastParent = htmlGetLastParent($ansItem)) { $lastParent->innertext .= $label; } } } return $answerContents->outertext(); }; @endphp {{-- thithuthptqg.vn --}} {{-- --}} {{-- --}} {{-- --}} {{-- --}}
{!! $exam->header !!}
@if ($t = count($questionListMap)) @foreach ($questionListMap as $questionMap) @php $mapType = $questionMap['type'] ?? ''; $slug = 'aby'; @endphp @if ($mapType == 'subject-topic') @if ($questionMap['subject'] ?? []) @php $slug = $questionMap['subject']->slug; $points = to_number($questionMap['points'] ?? 0); $title = $questionMap['title'] ?? null; @endphp @if ($title)
{!! $title !!}
@endif @endif @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, $question_count, $slug); @endphp @if ($question->type != 'group')
{!! $content !!}
@php $answerIndex = 0; $lastItemIndex = count($question->answers) - 1; @endphp @foreach ($question->answers as $answer) @if ($answerIndex == 0 || $answerIndex % 2 == 0) @endif @php $answerContent = $parseAnswerContent($answer->content, $alphabet[$answerIndex]); @endphp @if ($answerIndex == $lastItemIndex && $answerIndex % 2 == 0) @endif @if ($answerIndex == $lastItemIndex || $answerIndex % 2 == 1) @endif @php $answerIndex++; @endphp @endforeach

{!! $answerContent !!}



@else

@if ($slug == 'TA') Choose the option A, B, C or D to answer the following questions based on the information provided in the text. Then write the correct answer on the answer sheet. @else Đọc thông tin sau và trả lời các câu hỏi @endif

{!! $content !!}
@php $question_count--; @endphp @if ($question->children && count($question->children)) @foreach ($question->children as $child) @php $question_count++; $content = $parseQuestionContent($child->content, $child->type, $question_count, $slug); @endphp
{!! $content !!}
@php $answerIndex = 0; $lastItemIndex = count($question->answers) - 1; @endphp @foreach ($child->answers as $answer) @if ($answerIndex == 0 || $answerIndex % 2 == 0) @endif @php $answerContent = $parseAnswerContent($answer->content, $alphabet[$answerIndex]); @endphp @if ($answerIndex == $lastItemIndex && $answerIndex % 2 == 0) @endif @if ($answerIndex == $lastItemIndex || $answerIndex % 2 == 1) @endif @php $answerIndex++; @endphp @endforeach

{!! $answerContent !!}



@endforeach @endif @endif @endforeach @endif @endforeach @endif @elseif($mapType == 'topic') @if ($questionMap['questions'] && count($tquestionMap['questions'])) @foreach ($questionMap['questions'] as $question) {{-- --}} @php $question_count++; // $content = preg_replace('/
[\r\n\t\s]*

/i', 'content, $question->type, $question_count, $slug); @endphp @if ($question->type != 'group')

{!! $content !!}
@php $answerIndex = 0; $lastItemIndex = count($question->answers) - 1; @endphp @foreach ($question->answers as $answer) @if ($answerIndex == 0 || $answerIndex % 2 == 0) @endif @php $answerContent = $parseAnswerContent($answer->content, $alphabet[$answerIndex]); @endphp @if ($answerIndex == $lastItemIndex && $answerIndex % 2 == 0) @endif @if ($answerIndex == $lastItemIndex || $answerIndex % 2 == 1) @endif @php $answerIndex++; @endphp @endforeach

{!! $answerContent !!}



@else

@if ($slug == 'TA') Choose the option A, B, C or D to answer the following questions based on the information provided in the text. Then write the correct answer on the answer sheet. @else Đọc thông tin sau và trả lời các câu hỏi @endif

{!! $content !!}
@php $question_count--; @endphp @if ($question->children && count($question->children)) @foreach ($question->children as $child) @php $question_count++; $content = $parseQuestionContent($child->content, $child->type, $question_count, $slug); @endphp
{!! $content !!}
@php $answerIndex = 0; $lastItemIndex = count($question->answers) - 1; @endphp @foreach ($child->answers as $answer) @if ($answerIndex == 0 || $answerIndex % 2 == 0) @endif @php $answerContent = $parseAnswerContent($answer->content, $alphabet[$answerIndex]); @endphp @if ($answerIndex == $lastItemIndex && $answerIndex % 2 == 0) @endif @if ($answerIndex == $lastItemIndex || $answerIndex % 2 == 1) @endif @php $answerIndex++; @endphp @endforeach

{!! $answerContent !!}



@endforeach @endif @endif @endforeach @endif @endif @endforeach @endif
{{--

HEADER

{{ $exam->name }} - Mã đề {{ '{' . '{MADE}' . '}' }} Trang from

--}}