Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
96.97% |
32 / 33 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| TOC | |
96.97% |
32 / 33 |
|
50.00% |
1 / 2 |
6 | |
0.00% |
0 / 1 |
| write | |
92.31% |
12 / 13 |
|
0.00% |
0 / 1 |
3.00 | |||
| writeSource | |
100.00% |
20 / 20 |
|
100.00% |
1 / 1 |
3 | |||
| 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 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. |
| 12 | * |
| 13 | * @see https://github.com/PHPOffice/PHPWord |
| 14 | * |
| 15 | * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 |
| 16 | */ |
| 17 | |
| 18 | namespace PhpOffice\PhpWord\Writer\ODText\Element; |
| 19 | |
| 20 | use PhpOffice\PhpWord\Element\TOC as TOCElement; |
| 21 | |
| 22 | /** |
| 23 | * Table of contents element writer. |
| 24 | */ |
| 25 | class TOC extends AbstractElement |
| 26 | { |
| 27 | /** |
| 28 | * Write element. |
| 29 | */ |
| 30 | public function write(): void |
| 31 | { |
| 32 | $xmlWriter = $this->getXmlWriter(); |
| 33 | $element = $this->getElement(); |
| 34 | if (!$element instanceof TOCElement) { |
| 35 | return; |
| 36 | } |
| 37 | |
| 38 | $xmlWriter->startElement('text:table-of-content'); |
| 39 | $fontStyle = $element->getStyleFont(); |
| 40 | if (is_string($fontStyle)) { |
| 41 | $xmlWriter->writeAttribute('text:style-name', $fontStyle); |
| 42 | } |
| 43 | $xmlWriter->writeAttribute('text:name', 'Table of Contents'); |
| 44 | |
| 45 | $this->writeSource($element); |
| 46 | |
| 47 | $xmlWriter->startElement('text:index-body'); |
| 48 | $xmlWriter->endElement(); |
| 49 | $xmlWriter->endElement(); |
| 50 | } |
| 51 | |
| 52 | private function writeSource(TOCElement $element): void |
| 53 | { |
| 54 | $xmlWriter = $this->getXmlWriter(); |
| 55 | $xmlWriter->startElement('text:table-of-content-source'); |
| 56 | $xmlWriter->writeAttribute('text:index-scope', 'document'); |
| 57 | $xmlWriter->writeAttribute('text:use-outline-level', 'true'); |
| 58 | $xmlWriter->writeAttribute('text:use-index-marks', 'false'); |
| 59 | $xmlWriter->writeAttribute('text:use-index-source-styles', 'false'); |
| 60 | |
| 61 | $maxDepth = $element->getMaxDepth(); |
| 62 | if ($maxDepth > 0) { |
| 63 | $xmlWriter->writeAttribute('text:outline-level', $maxDepth); |
| 64 | for ($level = $element->getMinDepth(); $level <= $maxDepth; ++$level) { |
| 65 | $xmlWriter->startElement('text:table-of-content-entry-template'); |
| 66 | $xmlWriter->writeAttribute('text:outline-level', $level); |
| 67 | $xmlWriter->startElement('text:index-entry-text'); |
| 68 | $xmlWriter->endElement(); |
| 69 | $xmlWriter->startElement('text:index-entry-tab-stop'); |
| 70 | $xmlWriter->endElement(); |
| 71 | $xmlWriter->startElement('text:index-entry-page-number'); |
| 72 | $xmlWriter->endElement(); |
| 73 | $xmlWriter->endElement(); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | $xmlWriter->endElement(); |
| 78 | } |
| 79 | } |