• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PHPOffice / PHPWord / 13025401639

29 Jan 2025 05:48AM UTC coverage: 96.825% (-0.4%) from 97.217%
13025401639

Pull #2562

github

web-flow
Merge ebe3e5dac into 2d2759585
Pull Request #2562: TemplateProcessor SetComplexBlock/Value and Sections

6 of 7 new or added lines in 1 file covered. (85.71%)

245 existing lines in 40 files now uncovered.

12227 of 12628 relevant lines covered (96.82%)

34.56 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.14
/src/PhpWord/Writer/HTML/Part/Body.php
1
<?php
2

3
/**
4
 * This file is part of PHPWord - A pure PHP library for reading and writing
5
 * word processing documents.
6
 *
7
 * PHPWord is free software distributed under the terms of the GNU Lesser
8
 * General Public License version 3 as published by the Free Software Foundation.
9
 *
10
 * For the full copyright and license information, please read the LICENSE
11
 * file that was distributed with this source code. For the full list of
12
 * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
13
 *
14
 * @see         https://github.com/PHPOffice/PHPWord
15
 *
16
 * @license     http://www.gnu.org/licenses/lgpl.txt LGPL version 3
17
 */
18

19
namespace PhpOffice\PhpWord\Writer\HTML\Part;
20

21
use PhpOffice\PhpWord\Writer\HTML\Element\Container;
22
use PhpOffice\PhpWord\Writer\HTML\Element\TextRun as TextRunWriter;
23
use PhpOffice\PhpWord\Writer\PDF\TCPDF;
24

25
/**
26
 * HTML body part writer.
27
 *
28
 * @since 0.11.0
29
 */
30
class Body extends AbstractPart
31
{
32
    /**
33
     * Write part.
34
     *
35
     * @return string
36
     */
37
    public function write()
38
    {
39
        $phpWord = $this->getParentWriter()->getPhpWord();
37✔
40

41
        $content = '';
37✔
42

43
        $content .= '<body>' . PHP_EOL;
37✔
44
        $sections = $phpWord->getSections();
37✔
45
        $secno = 0;
37✔
46
        $isTCPDFWriter = $this->getParentWriter() instanceof TCPDF;
37✔
47
        foreach ($sections as $section) {
37✔
48
            ++$secno;
34✔
49
            if ($isTCPDFWriter && $secno > 1) {
34✔
UNCOV
50
                $content .= "<div style=\"page: page$secno; page-break-before:always;\">" . PHP_EOL;
×
51
            } else {
52
                $content .= "<div style='page: page$secno'>" . PHP_EOL;
34✔
53
            }
54
            $writer = new Container($this->getParentWriter(), $section);
34✔
55
            $content .= $writer->write();
34✔
56
            $content .= '</div>' . PHP_EOL;
34✔
57
        }
58

59
        $content .= $this->writeNotes();
37✔
60
        $content .= '</body>' . PHP_EOL;
37✔
61

62
        return $content;
37✔
63
    }
64

65
    /**
66
     * Write footnote/endnote contents as textruns.
67
     *
68
     * @return string
69
     */
70
    private function writeNotes()
71
    {
72
        /** @var \PhpOffice\PhpWord\Writer\HTML $parentWriter Type hint */
73
        $parentWriter = $this->getParentWriter();
37✔
74
        $phpWord = $parentWriter->getPhpWord();
37✔
75
        $notes = $parentWriter->getNotes();
37✔
76

77
        $content = '';
37✔
78

79
        if (!empty($notes)) {
37✔
80
            $content .= '<hr />' . PHP_EOL;
1✔
81
            foreach ($notes as $noteId => $noteMark) {
1✔
82
                [$noteType, $noteTypeId] = explode('-', $noteMark);
1✔
83
                $method = 'get' . ($noteType == 'endnote' ? 'Endnotes' : 'Footnotes');
1✔
84
                $collection = $phpWord->$method()->getItems();
1✔
85

86
                if (isset($collection[$noteTypeId])) {
1✔
87
                    $element = $collection[$noteTypeId];
1✔
88
                    $noteAnchor = "<a name=\"note-{$noteId}\" />";
1✔
89
                    $noteAnchor .= "<a href=\"#{$noteMark}\" class=\"NoteRef\"><sup>{$noteId}</sup></a>";
1✔
90

91
                    $writer = new TextRunWriter($this->getParentWriter(), $element);
1✔
92
                    $writer->setOpeningText($noteAnchor);
1✔
93
                    $content .= $writer->write();
1✔
94
                }
95
            }
96
        }
97

98
        return $content;
37✔
99
    }
100
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc