Completed
Push — master ( 187d75...242b2a )
by Michael
01:34
created

TableNode::countColNum()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace dokuwiki\plugin\prosemirror\parser;
4
5
class TableNode extends Node
6
{
7
8
    /** @var TableRowNode[] */
9
    protected $tableRows = [];
10
    protected $rowSpans = [];
11
    protected $numCols;
12
13
    public function __construct($data)
14
    {
15
        foreach ($data['content'] as $row) {
16
            $this->tableRows[] = new TableRowNode($row, $this);
17
        }
18
        $this->countColNum();
19
    }
20
21
    /**
22
     * Count the total number of columns in the table
23
     *
24
     * This method calculates the number of columns in the first row, by adding the colspan of each cell.
25
     * This produces the correct number columns, since the first row cannot have ommited cells due to a
26
     * rowspan, as every other row could have.
27
     *
28
     */
29
    protected function countColNum() {
30
        $this->numCols = $this->tableRows[0]->countCols();
31
    }
32
33
    /**
34
     * Get the total number of columns for this table
35
     *
36
     * @return int
37
     */
38
    public function getNumTableCols() {
39
        return $this->numCols;
40
    }
41
42
    public function toSyntax()
43
    {
44
        $doc = '';
45
        foreach ($this->tableRows as $row) {
46
            $doc .= $row->toSyntax() . "\n";
47
        }
48
49
        return $doc;
50
    }
51
52
    public function getRowSpans()
53
    {
54
        return $this->rowSpans;
55
    }
56
57
    public function setRowSpans(array $rowSpans)
58
    {
59
        $this->rowSpans = $rowSpans;
60
    }
61
}
62