Modifications

This commit is contained in:
Loann 2020-06-08 16:26:35 +02:00
parent 4bad426149
commit 4a3ecb3a61
1 changed files with 27 additions and 9 deletions

View File

@ -39,7 +39,6 @@ class BluescaleMailApi
$notifiable_recipient = false; $notifiable_recipient = false;
$notifiable_email = $notifiable->email; $notifiable_email = $notifiable->email;
$recipients = $template->recipients; $recipients = $template->recipients;
$attachments = $template->attachments;
if (count($recipients) > 0) if (count($recipients) > 0)
foreach ($recipients as $recipient) foreach ($recipients as $recipient)
@ -51,21 +50,40 @@ class BluescaleMailApi
$template->recipients[] = [ $template->recipients[] = [
'address' => $notifiable->email 'address' => $notifiable->email
]; ];
}
if (count($attachments) > 0) { $attachments = $template->attachments;
$formatted_attachmments = []; if (count($attachments) > 0) { // Formatting attachments to UploadFiles
foreach ($attachments as $attachment) { $formatted_attachmments = [];
$file = new UploadedFile($attachment['path'], $attachment['filename'], 'application/octet-stream', null, null, false); foreach ($attachments as $attachment) {
$formatted_attachmments[] = $file; $formatted_attachmments[] = new UploadedFile($attachment['path'], $attachment['filename'], null, null, false);
} }
$template->attachments = $formatted_attachmments; $template->attachments = $formatted_attachmments;
}
$multipart_form = [];
foreach($template as $key => $value){ // Formatting whole template to pass in 'multipart' form
if(!is_array($value)){
$multipart_form[] = ['name' => $key, 'contents' => $value];
continue;
}
foreach($value as $multiKey => $multiValue){
$multiName = $key . '[' .$multiKey . ']' . (is_array($multiValue) ? '[' . key($multiValue) . ']' : '' ) . '';
$data = ['name' => $multiName, 'contents' => (is_array($multiValue) ? reset($multiValue) : $multiValue)];
if (substr($key, 0, 11) === "attachments")
$data['filename'] = $multiValue->getClientOriginalName();
$multipart_form[] = $data;
} }
} }
try { try {
return $client->request('post', $url, [ return $client->request('post', $url, [
'form_params' => $template, 'multipart' => $multipart_form,
'headers' => [ 'headers' => [
'Authorization' => 'Bearer ' . $this->api_key, 'Authorization' => 'Bearer ' . $this->api_key,
'Accept' => 'application/json' 'Accept' => 'application/json'