1<?php
2
3namespace dokuwiki\plugin\wordimport\docx;
4
5/**
6 * A table
7 *
8 * A table is not really a paragraph but we treat it as one for simplicity. However it contains rows of cells which
9 * again contain paragraphs.
10 */
11class Table extends AbstractParagraph
12{
13    /** @var Paragraph[][] */
14    protected $table = [];
15
16    /** @inheritdoc */
17    public function parse()
18    {
19        $rows = $this->p->xpath('w:tr');
20        foreach ($rows as $row) {
21            $tableRow = [];
22            $cells = $row->xpath('w:tc');
23            foreach ($cells as $cell) {
24                $cell = new TableCell($this->docx, $cell);
25                $cell->parse();
26                $tableRow[] = $cell;
27            }
28            $this->table[] = $tableRow;
29        }
30    }
31
32    /** @inheritdoc */
33    public function __toString(): string
34    {
35        $text = '';
36        foreach ($this->table as $row) {
37            $text .= '|';
38            foreach ($row as $cell) {
39                $text .= $cell->__toString();
40            }
41            $text .= "\n";
42        }
43        return $text;
44    }
45}
46