Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
95.00% |
19 / 20 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| Footnote | |
95.00% |
19 / 20 |
|
0.00% |
0 / 1 |
4 | |
0.00% |
0 / 1 |
| write | |
95.00% |
19 / 20 |
|
0.00% |
0 / 1 |
4 | |||
| 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. 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\ODText\Element; |
| 20 | |
| 21 | /** |
| 22 | * Footnote element writer. |
| 23 | */ |
| 24 | class Footnote extends AbstractElement |
| 25 | { |
| 26 | /** |
| 27 | * ODF note class. |
| 28 | * |
| 29 | * @var string |
| 30 | */ |
| 31 | protected $noteClass = 'footnote'; |
| 32 | |
| 33 | /** |
| 34 | * ODF note ID prefix. |
| 35 | * |
| 36 | * @var string |
| 37 | */ |
| 38 | protected $idPrefix = 'ftn'; |
| 39 | |
| 40 | /** |
| 41 | * Write footnote element. |
| 42 | */ |
| 43 | public function write(): void |
| 44 | { |
| 45 | $xmlWriter = $this->getXmlWriter(); |
| 46 | $element = $this->getElement(); |
| 47 | if (!$element instanceof \PhpOffice\PhpWord\Element\Footnote) { |
| 48 | return; |
| 49 | } |
| 50 | |
| 51 | $number = $element->getRelationId() + 1; |
| 52 | if (!$this->withoutP) { |
| 53 | $xmlWriter->startElement('text:p'); |
| 54 | } |
| 55 | |
| 56 | $xmlWriter->startElement('text:note'); |
| 57 | $xmlWriter->writeAttribute('text:note-class', $this->noteClass); |
| 58 | $xmlWriter->writeAttribute('text:id', $this->idPrefix . $number); |
| 59 | |
| 60 | $xmlWriter->startElement('text:note-citation'); |
| 61 | $xmlWriter->text((string) $number); |
| 62 | $xmlWriter->endElement(); |
| 63 | |
| 64 | $xmlWriter->startElement('text:note-body'); |
| 65 | $containerWriter = new Container($xmlWriter, $element); |
| 66 | $containerWriter->write(); |
| 67 | $xmlWriter->endElement(); |
| 68 | |
| 69 | $xmlWriter->endElement(); |
| 70 | |
| 71 | if (!$this->withoutP) { |
| 72 | $xmlWriter->endElement(); |
| 73 | } |
| 74 | } |
| 75 | } |