Modifications
This commit is contained in:
parent
4a3ecb3a61
commit
169e532434
|
@ -52,16 +52,6 @@ class BluescaleMailApi
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
$attachments = $template->attachments;
|
|
||||||
if (count($attachments) > 0) { // Formatting attachments to UploadFiles
|
|
||||||
$formatted_attachmments = [];
|
|
||||||
foreach ($attachments as $attachment) {
|
|
||||||
$formatted_attachmments[] = new UploadedFile($attachment['path'], $attachment['filename'], null, null, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
$template->attachments = $formatted_attachmments;
|
|
||||||
}
|
|
||||||
|
|
||||||
$multipart_form = [];
|
$multipart_form = [];
|
||||||
|
|
||||||
foreach ($template as $key => $value) { // Formatting whole template to pass in 'multipart' form
|
foreach ($template as $key => $value) { // Formatting whole template to pass in 'multipart' form
|
||||||
|
@ -71,11 +61,15 @@ class BluescaleMailApi
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($value as $multiKey => $multiValue) {
|
foreach ($value as $multiKey => $multiValue) {
|
||||||
$multiName = $key . '[' .$multiKey . ']' . (is_array($multiValue) ? '[' . key($multiValue) . ']' : '' ) . '';
|
$multiName = $key . '[' .$multiKey . ']' . (is_array($multiValue) ? '[' . key($multiValue) . ']' : '' );
|
||||||
$data = ['name' => $multiName, 'contents' => (is_array($multiValue) ? reset($multiValue) : $multiValue)];
|
$data = ['name' => $multiName];
|
||||||
|
|
||||||
if (substr($key, 0, 11) === "attachments")
|
if ($key === "attachments") {
|
||||||
$data['filename'] = $multiValue->getClientOriginalName();
|
$data['contents'] = file_get_contents($multiValue['path']);
|
||||||
|
$data['filename'] = $multiValue['filename'];
|
||||||
|
} else {
|
||||||
|
$data['contents'] = (is_array($multiValue) ? reset($multiValue) : $multiValue);
|
||||||
|
}
|
||||||
|
|
||||||
$multipart_form[] = $data;
|
$multipart_form[] = $data;
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,6 +153,16 @@ class BluescaleMailTemplate implements \JsonSerializable
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function addAttachment($file, $filename = null)
|
||||||
|
{
|
||||||
|
$file = is_object($file) && method_exists($file, 'getRealPath') ? $file->getRealPath() : $file;
|
||||||
|
|
||||||
|
$this->attachments[] = [
|
||||||
|
'file' => $file,
|
||||||
|
'filename' => $filename ?? basename($file)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $key
|
* @param string $key
|
||||||
* @param string $value
|
* @param string $value
|
||||||
|
|
Loading…
Reference in New Issue