示例#1
0
 /**
  * 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;
 }