fix doc
This commit is contained in:
@@ -120,7 +120,9 @@ class MailingController extends Controller
|
||||
return back()->with('error', 'Nessun destinatario email valido trovato.')->withInput();
|
||||
}
|
||||
|
||||
$attachmentPaths = $this->resolveMailingAttachmentPaths($documentiAllegati);
|
||||
$attachmentResult = $this->resolveMailingAttachmentPaths($documentiAllegati);
|
||||
$attachmentPaths = $attachmentResult['paths'];
|
||||
$linkDocs = $attachmentResult['links'];
|
||||
|
||||
$firmaId = $data['firma_id'] ?? null;
|
||||
if (!$firmaId && !empty($data['lista_id'])) {
|
||||
@@ -128,7 +130,7 @@ class MailingController extends Controller
|
||||
$firmaId = $lista?->firma?->id;
|
||||
}
|
||||
|
||||
$corpoConFirma = $data['corpo'];
|
||||
$corpoConFirma = $this->appendMailingLinksToBody($data['corpo'], $linkDocs);
|
||||
if ($firmaId) {
|
||||
$firma = Firma::find($firmaId);
|
||||
if ($firma && $firma->contenuto_html) {
|
||||
@@ -284,14 +286,16 @@ class MailingController extends Controller
|
||||
return back()->with('error', 'Nessun destinatario email valido trovato nelle liste selezionate.');
|
||||
}
|
||||
|
||||
$attachmentPaths = $this->resolveMailingAttachmentPaths($documentiAllegati);
|
||||
$attachmentResult = $this->resolveMailingAttachmentPaths($documentiAllegati);
|
||||
$attachmentPaths = $attachmentResult['paths'];
|
||||
$linkDocs = $attachmentResult['links'];
|
||||
|
||||
$firmaId = $data['firma_id'] ?? null;
|
||||
if (!$firmaId && $listeModels->count() === 1) {
|
||||
$firmaId = $listeModels->first()->firma_id;
|
||||
}
|
||||
|
||||
$corpoConFirma = $data['corpo'];
|
||||
$corpoConFirma = $this->appendMailingLinksToBody($data['corpo'], $linkDocs);
|
||||
if ($firmaId) {
|
||||
$firma = Firma::find($firmaId);
|
||||
if ($firma && $firma->contenuto_html) {
|
||||
@@ -419,17 +423,34 @@ class MailingController extends Controller
|
||||
private function resolveMailingAttachmentPaths(array $documentIds): array
|
||||
{
|
||||
$paths = [];
|
||||
$links = [];
|
||||
if (empty($documentIds)) {
|
||||
return $paths;
|
||||
return ['paths' => $paths, 'links' => $links];
|
||||
}
|
||||
|
||||
$docs = Documento::whereIn('id', $documentIds)->get();
|
||||
foreach ($docs as $doc) {
|
||||
if ($doc->file_path && Storage::exists($doc->file_path)) {
|
||||
if ($doc->isLink()) {
|
||||
$links[] = ['nome' => $doc->nome_file, 'url' => $doc->url];
|
||||
} elseif ($doc->file_path && Storage::exists($doc->file_path)) {
|
||||
$paths[] = Storage::path($doc->file_path);
|
||||
}
|
||||
}
|
||||
|
||||
return $paths;
|
||||
return ['paths' => $paths, 'links' => $links];
|
||||
}
|
||||
|
||||
private function appendMailingLinksToBody(string $body, array $linkDocs): string
|
||||
{
|
||||
if (empty($linkDocs)) {
|
||||
return $body;
|
||||
}
|
||||
|
||||
$linksText = "\n\n---\nDocumenti collegati:\n";
|
||||
foreach ($linkDocs as $link) {
|
||||
$linksText .= "- {$link['nome']}: {$link['url']}\n";
|
||||
}
|
||||
|
||||
return $body . $linksText;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user