/** * Write footnote/endnote contents as textruns * * @return string */ private function writeNotes() { /** @var \PhpOffice\PhpWord\Writer\HTML $parentWriter Type hint */ $parentWriter = $this->getParentWriter(); $phpWord = $parentWriter->getPhpWord(); $notes = $parentWriter->getNotes(); $content = ''; if (!empty($notes)) { $content .= "<hr />" . PHP_EOL; foreach ($notes as $noteId => $noteMark) { list($noteType, $noteTypeId) = explode('-', $noteMark); $method = 'get' . ($noteType == 'endnote' ? 'Endnotes' : 'Footnotes'); $collection = $phpWord->{$method}()->getItems(); if (array_key_exists($noteTypeId, $collection)) { $element = $collection[$noteTypeId]; $noteAnchor = "<a name=\"note-{$noteId}\" />"; $noteAnchor .= "<a href=\"#{$noteMark}\" class=\"NoteRef\"><sup>{$noteId}</sup></a>"; $writer = new TextRunWriter($this->getParentWriter(), $element); $writer->setOpeningText($noteAnchor); $content .= $writer->write(); } } } return $content; }
/** * Write footnote/endnote contents as textruns */ private function writeNotes() { $html = ''; if (!empty($this->notes)) { $html .= "<hr />"; foreach ($this->notes as $noteId => $noteMark) { $noteAnchor = "note-{$noteId}"; list($noteType, $noteTypeId) = explode('-', $noteMark); $collectionObject = 'PhpOffice\\PhpWord\\' . ($noteType == 'endnote' ? 'Endnotes' : 'Footnotes'); $collection = $collectionObject::getElements(); if (array_key_exists($noteTypeId, $collection)) { $element = $collection[$noteTypeId]; $elmWriter = new TextRunWriter($this, $element, true); $content = "<a href=\"#{$noteMark}\" class=\"NoteRef\"><sup>{$noteId}</sup></a>" . $elmWriter->write(); $html .= "<p><a name=\"{$noteAnchor}\" />{$content}</p>" . PHP_EOL; } } } return $html; }