|
18 | 18 |
|
19 | 19 | namespace PhpOffice\PhpWord\Writer\ODText\Element; |
20 | 20 |
|
| 21 | +use PhpOffice\PhpWord\Element\Comment; |
21 | 22 | use PhpOffice\PhpWord\Writer\Word2007\Element\AbstractElement as Word2007AbstractElement; |
22 | 23 |
|
23 | 24 | /** |
|
27 | 28 | */ |
28 | 29 | abstract class AbstractElement extends Word2007AbstractElement |
29 | 30 | { |
| 31 | + protected function writeCommentRangeStart(): void |
| 32 | + { |
| 33 | + if ($this->getElement()->getCommentsRangeStart() === null) { |
| 34 | + return; |
| 35 | + } |
| 36 | + |
| 37 | + foreach ($this->getElement()->getCommentsRangeStart()->getItems() as $comment) { |
| 38 | + $this->getXmlWriter()->startElement('office:annotation'); |
| 39 | + $this->getXmlWriter()->writeAttribute('office:name', $comment->getElementId()); |
| 40 | + $this->getXmlWriter()->writeElement('dc:creator', $comment->getAuthor()); |
| 41 | + if ($comment->getDate() !== null) { |
| 42 | + $this->getXmlWriter()->writeElement('dc:date', $comment->getDate()->format('Y-m-d\\TH:i:s\\Z')); |
| 43 | + } |
| 44 | + |
| 45 | + $containerWriter = new Container($this->getXmlWriter(), $comment); |
| 46 | + $containerWriter->write(); |
| 47 | + $this->getXmlWriter()->endElement(); |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + protected function writeCommentRangeEnd(): void |
| 52 | + { |
| 53 | + $element = $this->getElement(); |
| 54 | + $comments = $element->getCommentsRangeEnd(); |
| 55 | + if ($comments !== null) { |
| 56 | + foreach ($comments->getItems() as $comment) { |
| 57 | + $this->writeCommentRangeEndElement($comment); |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + $comments = $element->getCommentsRangeStart(); |
| 62 | + if ($comments !== null) { |
| 63 | + foreach ($comments->getItems() as $comment) { |
| 64 | + if ($comment->getEndElement() === null) { |
| 65 | + $this->writeCommentRangeEndElement($comment); |
| 66 | + } |
| 67 | + } |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + private function writeCommentRangeEndElement(Comment $comment): void |
| 72 | + { |
| 73 | + $this->getXmlWriter()->startElement('office:annotation-end'); |
| 74 | + $this->getXmlWriter()->writeAttribute('office:name', $comment->getElementId()); |
| 75 | + $this->getXmlWriter()->endElement(); |
| 76 | + } |
| 77 | + |
30 | 78 | protected function replaceTabs($text, $xmlWriter): void |
31 | 79 | { |
32 | 80 | if (preg_match('/^ +/', $text, $matches)) { |
|
0 commit comments