Skip to content

Commit

Permalink
BKDK-258
Browse files Browse the repository at this point in the history
  • Loading branch information
juuliabellcom committed Dec 2, 2020
1 parent 571011d commit df99d02
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions modules/os2forms_sbsys/src/Element/WebformAttachmentSbsysXml.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public static function getFileContent(array $element, WebformSubmissionInterface
$nemid_zipcode = htmlspecialchars($person_address['zipcode']);
}
}

/** @var \Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DataLookupInterface $sp_cvr */
$sp_cvr = $os2web_datalookup_plugins->createInstance('serviceplatformen_cvr');
if (!empty($nemid_com_cvr) && $sp_cvr->isReady()) {
Expand Down Expand Up @@ -84,6 +83,7 @@ public static function getFileContent(array $element, WebformSubmissionInterface
$webform = $webform_submission->getWebform();
$webform_title = htmlspecialchars($webform->label());
$fields = self::getWebformElementsAsList($webform_submission);

if (isset($fields['antal_rum_max'])) {
$maxRoom = htmlspecialchars($fields['antal_rum_max']);
}
Expand All @@ -102,14 +102,14 @@ public static function getFileContent(array $element, WebformSubmissionInterface
$xml_data = [
'OS2FormsId' => $os2formsId,
'SBSYSJournalisering' => [
'PrimaerPartCprNummer' => (!empty($nemid_cpr)) ? $nemid_cpr : '',
'PrimaerPartCprNummer' => (!empty($nemid_cpr) && empty($nemid_com_cvr)) ? $nemid_cpr : '',
'PrimaerPartCvrNummer' => (!empty($nemid_com_cvr)) ? $nemid_com_cvr : '',
'KLe' => $kle,
'SagSkabelonId' => $sagSkabelonId,
],
'DigitalForsendelse' => [
'Slutbruger' => [
'CprNummer' => (isset($nemid_cpr)) ? $nemid_cpr : '',
'CprNummer' => (!empty($nemid_cpr) && empty($nemid_com_cvr)) ? $nemid_cpr : '',
'CvrNummer' => (isset($nemid_com_cvr)) ? $nemid_com_cvr : '',
'Navn' => (isset($nemid_name)) ? $nemid_name : '',
'Adresse' => (isset($nemid_address)) ? $nemid_address : '',
Expand Down Expand Up @@ -200,19 +200,28 @@ protected static function getFirstValueByType($type, WebformSubmissionInterface
* Webform elements as simple array.
*/
protected static function getWebformElementsAsList(WebformSubmissionInterface $webform_submission) {
$nemid_cpr = self::getFirstValueByType('os2forms_nemid_cpr', $webform_submission);
$nemid_com_cvr = self::getFirstValueByType('os2forms_nemid_company_cvr', $webform_submission);
$webform = $webform_submission->getWebform();
$data = $webform_submission->getData();
$webform_elements = $webform->getElementsInitializedFlattenedAndHasValue();
$elements_list = [];

foreach ($webform_elements as $key => $webform_element) {
$field_name = $key;
$field_name = preg_replace('/\W/', '_', $field_name);
$webform_element['#type'];
if ($webform_element['#type'] == 'markup') {
$elements_list[$field_name] = $webform_element['value'];
}
elseif ($data && isset($data[$key])) {
$elements_list[$field_name] = $data[$key];
if ($webform_element['#type'] == 'os2forms_nemid_cpr') {
if (!empty($nemid_cpr) && empty($nemid_com_cvr)) {
$elements_list[$field_name] = $data[$key];
}
}
else {
$elements_list[$field_name] = $data[$key];
}
}
}
return $elements_list;
Expand Down

0 comments on commit df99d02

Please sign in to comment.