1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-05 18:52:44 +01:00

Create support for recursive copying of DOM

This commit is contained in:
Benjamin Beganović 2020-08-26 12:52:20 +02:00
parent 09dc17d3dc
commit 971a723607

View File

@ -228,33 +228,48 @@ trait PdfMakerUtilities
$table = $document->getElementById('page-container');
$this->document->getElementsByTagName('body')
->item(0)
->appendChild($this->document->importNode($table, true));
$body = $this->document->getElementsByTagName('body')
->item(0);
foreach ($this->data['template'] as $element) {
if ($element['id'] == 'header' || $element['id'] == 'footer') {
$body->appendChild(
$this->document->importNode($table, true)
);
for ($i = 0; $i < $body->childNodes->length; $i++) {
$element = $body->childNodes->item($i);
if ($element->nodeType !== 1) {
continue;
}
$node = $this->document->getElementById($element['id']);
$node->parentNode->removeChild($node);
if (
$element->getAttribute('id') == 'header' ||
$element->getAttribute('id') == 'footer' ||
$element->getAttribute('id') === 'page-container'
) {
continue;
}
$this->document->getElementById('repeat-content')->appendChild($node);
$clone = $element->cloneNode(true);
$element->parentNode->removeChild($element);
$this->document->getElementById('repeat-content')->appendChild($clone);
}
if ($header = $this->document->getElementById('header')) {
$header = $this->document->getElementById('header');
$header->parentNode->removeChild($header);
$clone = $header->cloneNode(true);
$this->document->getElementById('repeat-header')->appendChild($header);
$header->parentNode->removeChild($header);
$this->document->getElementById('repeat-header')->appendChild($clone);
}
if ($footer = $this->document->getElementById('footer')) {
$footer = $this->document->getElementById('footer');
$footer->parentNode->removeChild($footer);
$clone = $footer->cloneNode(true);
$this->document->getElementById('repeat-footer')->appendChild($footer);
$footer->parentNode->removeChild($footer);
$this->document->getElementById('repeat-footer')->appendChild($clone);
}
}
}