| 1 |
<?php |
| 2 |
|
| 3 |
namespace Give\FormMigration\Steps; |
| 4 |
|
| 5 |
use Give\FormMigration\Contracts\FormMigrationStep; |
| 6 |
|
| 7 |
/** |
| 8 |
* @since 3.0.0 |
| 9 |
*/ |
| 10 |
class PdfSettings extends FormMigrationStep |
| 11 |
{ |
| 12 |
/** |
| 13 |
* @since 3.0.0 |
| 14 |
*/ |
| 15 |
public function process() |
| 16 |
{ |
| 17 |
$oldFormId = $this->formV2->id; |
| 18 |
$newForm = $this->formV3; |
| 19 |
|
| 20 |
$pdfSettings = [ |
| 21 |
'enable' => $this->getMetaValue($oldFormId, 'give_pdf_receipts_enable_disable', 'global'), |
| 22 |
'generationMethod' => $this->getMetaValue($oldFormId, 'give_pdf_generation_method', 'set_pdf_templates'), |
| 23 |
'colorPicker' => $this->getMetaValue($oldFormId, 'give_pdf_colorpicker', '#1E8CBE'), |
| 24 |
'templateId' => $this->getMetaValue($oldFormId, 'give_pdf_templates', 'default'), |
| 25 |
'logoUpload' => $this->getMetaValue($oldFormId, 'give_pdf_logo_upload', ''), |
| 26 |
'name' => $this->getMetaValue($oldFormId, 'give_pdf_company_name', ''), |
| 27 |
'addressLine1' => $this->getMetaValue($oldFormId, 'give_pdf_address_line1', ''), |
| 28 |
'addressLine2' => $this->getMetaValue($oldFormId, 'give_pdf_address_line2', ''), |
| 29 |
'cityStateZip' => $this->getMetaValue($oldFormId, 'give_pdf_address_city_state_zip', ''), |
| 30 |
'displayWebsiteUrl' => $this->getMetaValue($oldFormId, 'give_pdf_url', ''), |
| 31 |
'emailAddress' => $this->getMetaValue($oldFormId, 'give_pdf_email_address', ''), |
| 32 |
'headerMessage' => $this->getMetaValue($oldFormId, 'give_pdf_header_message', ''), |
| 33 |
'footerMessage' => $this->getMetaValue($oldFormId, 'give_pdf_footer_message', ''), |
| 34 |
'additionalNotes' => $this->getMetaValue($oldFormId, 'give_pdf_additional_notes', ''), |
| 35 |
'customTemplateId' => $this->getMetaValue($oldFormId, 'give_pdf_receipt_template', ''), |
| 36 |
'customTemplateName' => $this->getMetaValue($oldFormId, 'give_pdf_receipt_template_name', ''), |
| 37 |
'customPageSize' => $this->getMetaValue($oldFormId, 'give_pdf_builder_page_size', ''), |
| 38 |
'customPdfBuilder' => $this->getMetaValue($oldFormId, 'give_pdf_builder', ''), |
| 39 |
]; |
| 40 |
|
| 41 |
$newForm->settings->pdfSettings = $pdfSettings; |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* @since 3.0.0 |
| 46 |
*/ |
| 47 |
private function getMetaValue(int $formId, string $metaKey, $defaultValue) |
| 48 |
{ |
| 49 |
$metaValue = give()->form_meta->get_meta($formId, $metaKey, true); |
| 50 |
|
| 51 |
if ( ! $metaValue) { |
| 52 |
return $defaultValue; |
| 53 |
} |
| 54 |
|
| 55 |
return $metaValue; |
| 56 |
} |
| 57 |
} |
| 58 |
|