33 lines
1.5 KiB
PHP
33 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Models\Opportunity;
|
|
|
|
/** Presentation only: originals, editorial fields and audit records remain intact. */
|
|
final class OpportunityPublicText
|
|
{
|
|
public static function description(Opportunity $record, string $text): string
|
|
{
|
|
$source = data_get($record->workflow_context, 'corridor_agribusiness');
|
|
if (! is_array($source) || ($source['source_sha256'] ?? null) !== CorridorAgribusinessOpportunities::SOURCE_HASH) return $text;
|
|
|
|
$hash = CorridorAgribusinessOpportunities::SOURCE_HASH;
|
|
$sourceLine = 'Fonte: '.$source['source'].'; SHA-256 '.$hash;
|
|
$paragraphs = explode("\n\n", $text);
|
|
$result = [];
|
|
foreach ($paragraphs as $paragraph) {
|
|
$paragraph = trim($paragraph);
|
|
if (in_array($paragraph, [$sourceLine, $sourceLine.'.', 'Edição: Não indicada.', 'Data-base: Não indicada.',
|
|
'Limitações e lacunas: '.CorridorAgribusinessOpportunities::LIMITATIONS,
|
|
OpportunityPromotion::NOTICE], true)) continue;
|
|
if ($paragraph === 'Enquadramento documental: '.$source['corridor'].'.') $paragraph = $source['corridor'].'.';
|
|
if ($paragraph === CorridorAgribusinessOpportunities::LIMITATIONS) {
|
|
$paragraph = 'A localização exacta, a disponibilidade de terreno e as condições do investimento serão definidas durante a preparação do projecto.';
|
|
}
|
|
if ($paragraph !== '') $result[] = $paragraph;
|
|
}
|
|
return implode("\n\n", $result);
|
|
}
|
|
}
|