diff --git a/app/diagnostic_functions.php b/app/diagnostic_functions.php index 5b28d12..e5ace3b 100644 --- a/app/diagnostic_functions.php +++ b/app/diagnostic_functions.php @@ -789,6 +789,29 @@ function diagnostic_generate_ai_report_copy(array $attempt): array ]; } +function diagnostic_build_report_result_overview_html(string $overview): string +{ + $overview = diagnostic_report_limit(trim($overview), 1000); + if ($overview === '') { + return ''; + } + + return '
' + . '
Co ten wynik mówi o Twojej organizacji
' + . '
' . diagnostic_email_escape($overview) . '
' + . '
'; +} + +function diagnostic_build_report_result_overview_text(string $overview): string +{ + $overview = diagnostic_report_limit(trim($overview), 1000); + if ($overview === '') { + return ''; + } + + return "Co ten wynik mówi o Twojej organizacji:\n" . $overview; +} + function diagnostic_build_report_html(array $attempt, array $copy): string { $result = $attempt['result'] ?? []; @@ -796,6 +819,7 @@ function diagnostic_build_report_html(array $attempt, array $copy): string $strengthsHtml = diagnostic_email_list($copy['strengths'] ?? []); $prioritiesHtml = diagnostic_email_list($copy['priorities'] ?? []); $nextStepsHtml = diagnostic_email_list($copy['next_steps'] ?? []); + $resultOverviewHtml = diagnostic_build_report_result_overview_html((string)($copy['result_overview'] ?? '')); $content = '

' . diagnostic_email_escape((string)($copy['intro'] ?? '')) . '

' . '' @@ -808,6 +832,7 @@ function diagnostic_build_report_html(array $attempt, array $copy): string . '' . '' . '
' + . $resultOverviewHtml . '
' . '
Co ten wynik oznacza
' . '
' . diagnostic_email_escape((string)($copy['what_it_means'] ?? '')) . '
' @@ -829,6 +854,7 @@ function diagnostic_build_report_html(array $attempt, array $copy): string function diagnostic_build_report_text(array $attempt, array $copy): string { $result = $attempt['result'] ?? []; + $resultOverviewText = diagnostic_build_report_result_overview_text((string)($copy['result_overview'] ?? '')); $lines = []; $lines[] = 'DoktorBiznes.pl'; $lines[] = diagnostic_brand_home_url(); @@ -839,6 +865,10 @@ function diagnostic_build_report_text(array $attempt, array $copy): string $lines[] = (string)($copy['intro'] ?? ''); $lines[] = ''; $lines[] = (string)($copy['executive_summary'] ?? ''); + if ($resultOverviewText !== '') { + $lines[] = ''; + $lines[] = $resultOverviewText; + } $lines[] = ''; $lines[] = 'Co ten wynik oznacza:'; $lines[] = (string)($copy['what_it_means'] ?? ''); @@ -979,11 +1009,37 @@ function diagnostic_cached_report_content(array $attempt): ?array $subject = $package['subject']; $html = $package['html']; $text = $package['text']; + $resultOverview = diagnostic_report_limit((string)($attempt['ai_summary_text'] ?? ''), 1000); if ($subject === '' || $html === '' || $text === '') { return null; } + if ($resultOverview === '') { + return null; + } + + $overviewHtml = diagnostic_build_report_result_overview_html($resultOverview); + $overviewText = diagnostic_build_report_result_overview_text($resultOverview); + + if ($overviewHtml !== '' && strpos($html, 'Co ten wynik mówi o Twojej organizacji') === false) { + $needle = '
'; + if (strpos($html, $needle) !== false) { + $html = str_replace($needle, $overviewHtml . $needle, $html); + } else { + return null; + } + } + + if ($overviewText !== '' && strpos($text, 'Co ten wynik mówi o Twojej organizacji:') === false) { + $needle = "\n\nCo ten wynik oznacza:\n"; + if (strpos($text, $needle) !== false) { + $text = str_replace($needle, "\n\n" . $overviewText . $needle, $text); + } else { + return null; + } + } + if (!empty($attempt['id']) && ( $subject !== (string)($attempt['report_subject'] ?? '') || $html !== (string)($attempt['report_html'] ?? '') @@ -993,6 +1049,7 @@ function diagnostic_cached_report_content(array $attempt): ?array 'subject' => $subject, 'html' => $html, 'text' => $text, + 'result_overview' => $resultOverview, ]); } @@ -1001,7 +1058,7 @@ function diagnostic_cached_report_content(array $attempt): ?array 'subject' => $subject, 'html' => $html, 'text' => $text, - 'result_overview' => diagnostic_report_limit((string)($attempt['ai_summary_text'] ?? ''), 1000), + 'result_overview' => $resultOverview, 'source' => 'cache', ]; } diff --git a/diagnostic.php b/diagnostic.php index f1eeaa3..6c6f7c6 100644 --- a/diagnostic.php +++ b/diagnostic.php @@ -335,7 +335,6 @@ $resultOverview = ($view === 'result' && $attempt && ($attempt['status'] ?? '')
-
Opis wygenerowany przez AI

Co ten wynik mówi o Twojej organizacji