5151use Psr \Log \LoggerTrait ;
5252use Symfony \Component \DependencyInjection \Attribute \Autowire ;
5353use Symfony \Contracts \EventDispatcher \EventDispatcherInterface ;
54- use WsdlToPhp \PackageBase \AbstractStructBase ;
5554
5655/**
5756 * Fordelingskomponent helper.
6160final class FordelingskomponentHelper implements LoggerInterface {
6261 use LoggerTrait;
6362
64- public const string ROUTING_MYNDIGHED = 'routing_myndighed ' ;
65-
66- public const string KLE_EMNE = 'kle_emne ' ;
67-
68- public const string HANDLING_FACET = 'handling_facet ' ;
69- public const string TITEL = 'titel ' ;
70- public const string BESKRIVELSE = 'beskrivelse ' ;
71-
72- public const string ATTACHMENT_ELEMENT = 'attachment_element ' ;
73-
7463 /**
7564 * Constructor.
7665 */
@@ -133,11 +122,9 @@ public function buildDistributionObject(
133122 ),
134123 DistributionObjectSettings::DISTRIBUTION_TYPE_FORMULAR => $ this ->buildDistributionFormularType (
135124 id: $ id ,
136- fraTidsPunkt: $ fraTidsPunkt ,
137- brevDato: $ brevDato ,
138- submission: $ submission ,
139- handlerSettings: $ handlerSettings ,
140- attachment: $ attachment ,
125+ submission: $ submission ,
126+ handlerSettings: $ handlerSettings ,
127+ attachment: $ attachment ,
141128 ),
142129 default => throw new Exception (sprintf ('Invalid distribution type: %s ' , $ type )),
143130 };
@@ -194,57 +181,57 @@ private function buildDistributionDokumentType(
194181 ): DistributionDokumentType {
195182 return new DistributionDokumentType (
196183 iD: $ id ,
197- kLEEmneForslag: $ handlerSettings ->distributionContext ->kleEmne ,
198- handlingFacetForslag: $ handlerSettings ->distributionContext ->handlingFacet ,
199- registrering: new DokumentRegistreringType (
200- fraTidsPunkt: SF2900 ::formatDateTime ($ fraTidsPunkt ),
201- livscyklusKode: LivscyklusKodeType::VALUE_OPRETTET ,
202- registreringItSystem: new UUID_URN ($ handlerSettings ->sender ->registreringItSystem ),
203- relationListe: new RelationsListe (
204- variantListe: new VariantListeType ([
205- new VariantType (
206- // If we don't clone the “virking", the XML serializer adds an
207- // ID and references which SF2900 does not handle.
208- virkning: $ this ->clone ($ virkning ),
209- rolle: VariantRolleType::VALUE_VARIANT ,
210- indeks: '1 ' ,
211- variantAttributter: new VariantAttributterType (
184+ kLEEmneForslag: $ handlerSettings ->distributionContext ->kleEmne ,
185+ registrering: new DokumentRegistreringType (
186+ fraTidsPunkt: SF2900 ::formatDateTime ($ fraTidsPunkt ),
187+ livscyklusKode: LivscyklusKodeType::VALUE_OPRETTET ,
188+ registreringItSystem: new UUID_URN ($ handlerSettings ->sender ->registreringItSystem ),
189+ relationListe: new RelationsListe (
190+ variantListe: new VariantListeType ([
191+ new VariantType (
192+ // If we don't clone the “virking", the XML serializer adds an
193+ // ID and references which SF2900 does not handle.
194+ virkning: $ this ->cloneVirkning ($ virkning ),
195+ rolle: VariantRolleType::VALUE_VARIANT ,
196+ indeks: '1 ' ,
197+ variantAttributter: new VariantAttributterType (
198+ // @todo What to use here?
199+ variantType: Attachment::FORMAT_NAME_PDF ,
200+ ),
201+ delAttributter: new DelAttributterType (
212202 // @todo What to use here?
213- variantType: Attachment::FORMAT_NAME_PDF ,
203+ delTekst: 'Hele dokumentet ' ,
204+ ),
214205 ),
215- delAttributter: new DelAttributterType (
206+ ]),
207+ ),
208+ tilstandsListe: [
209+ new TilstandListeType (
210+ tilstand: [
211+ new TilstandType (
212+ // @todo Hvad er fremdrift?
213+ fremdrift: FremdriftType::VALUE_ENDELIGT ,
214+ virkning: $ this ->cloneVirkning ($ virkning ),
215+ ),
216+ ]
217+ ),
218+ ],
219+ attributListe: new AttributterListeType ([
220+ new AttributterType (
221+ brugervendtNoegleTekst: $ handlerSettings ->distributionContext ->brugervendtNoegle ,
222+ titelTekst: $ handlerSettings ->distributionContext ->titel ,
223+ beskrivelseTekst: $ handlerSettings ->distributionContext ->beskrivelse ,
216224 // @todo What to use here?
217- delTekst: 'Hele dokumentet ' ,
218- ),
225+ dokumenttype: DokumenttypeType::VALUE_ANDEN ,
226+ retning: RetningType::VALUE_UDGAAENDE ,
227+ brevdato: SF2900 ::formatDate ($ brevDato ),
228+ virkning: $ this ->cloneVirkning ($ virkning ),
219229 ),
220230 ]),
231+ // importTidspunkt: null,
232+ // brugerRef: null,.
221233 ),
222- tilstandsListe: [
223- new TilstandListeType (
224- tilstand: [
225- new TilstandType (
226- // @todo Hvad er fremdrift?
227- fremdrift: FremdriftType::VALUE_ENDELIGT ,
228- virkning: $ this ->clone ($ virkning ),
229- ),
230- ]
231- ),
232- ],
233- attributListe: new AttributterListeType ([
234- new AttributterType (
235- brugervendtNoegleTekst: $ handlerSettings ->distributionContext ->brugervendtNoegle ,
236- titelTekst: $ handlerSettings ->distributionContext ->titel ,
237- beskrivelseTekst: $ handlerSettings ->distributionContext ->beskrivelse ,
238- // @todo What to use here?
239- dokumenttype: DokumenttypeType::VALUE_ANDEN ,
240- retning: RetningType::VALUE_UDGAAENDE ,
241- brevdato: SF2900 ::formatDate ($ brevDato ),
242- virkning: $ this ->clone ($ virkning ),
243- ),
244- ]),
245- // importTidspunkt: null,
246- // brugerRef: null,.
247- )
234+ handlingFacetForslag: $ handlerSettings ->distributionContext ->handlingFacet
248235 );
249236 }
250237
@@ -253,8 +240,6 @@ private function buildDistributionDokumentType(
253240 */
254241 private function buildDistributionFormularType (
255242 string $ id ,
256- \DateTimeInterface $ fraTidsPunkt ,
257- \DateTimeInterface $ brevDato ,
258243 WebformSubmissionInterface $ submission ,
259244 HandlerSettings $ handlerSettings ,
260245 Attachment $ attachment ,
@@ -272,13 +257,20 @@ private function buildDistributionFormularType(
272257 $ formatNavn = pathinfo ($ attachment ->filename , PATHINFO_EXTENSION );
273258 $ formularIndhold = base64_encode ($ attachment ->contents );
274259
260+ // The XML will be embedded in an SOAP:Envelope element, so we have to
261+ // make sure that the XML declaration is not included when embedding.
262+ // Passing a DOMDocument to FormularXMLType takes care of this.
263+ $ dom = new \DOMDocument ();
264+ $ dom ->loadXML ($ xml );
265+ $ formularXML = new FormularXMLType ($ dom );
266+
275267 $ meddelelse = new MeddelelseType (
276268 formularType: $ handlerSettings ->distributionObject ->formularType ,
277269 formular: new FormularType (
278270 titelTekst: $ titelTekst ,
279271 formatNavn: $ formatNavn ,
280272 formularIndhold: $ formularIndhold ,
281- formularXML: new FormularXMLType ( $ xml ) ,
273+ formularXML: $ formularXML ,
282274 ),
283275 );
284276
@@ -439,16 +431,16 @@ private function buildVirkning(HandlerSettings $handlerSettings): VirkningType {
439431 }
440432
441433 /**
442- * Deep clone an object .
434+ * Deep clone a virking .
443435 *
444- * @param \WsdlToPhp\PackageBase\AbstractStructBase<T> $object
436+ * @param \ItkDev\Serviceplatformen\SF2900\StructType\VirkningType $virkning
445437 * The object to clone.
446438 *
447- * @return \WsdlToPhp\PackageBase\AbstractStructBase<T>
439+ * @return \ItkDev\Serviceplatformen\SF2900\StructType\VirkningType
448440 * The cloned object.
449441 */
450- private function clone ( AbstractStructBase $ object ): AbstractStructBase {
451- return unserialize (serialize ($ object ));
442+ private function cloneVirkning ( VirkningType $ virkning ): VirkningType {
443+ return unserialize (serialize ($ virkning ));
452444 }
453445
454446}
0 commit comments