1<?php
2/**
3 * Handle ODT Table row elements.
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     LarsDW223
7 * @package    ODT\Elements\ODTElementTableRow
8 */
9
10/** Include ODTStateElement */
11require_once DOKU_PLUGIN.'odt/ODT/elements/ODTStateElement.php';
12
13/**
14 * ODTElementTableRow:
15 * Class for handling the table row element.
16 *
17 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
18 * @author     LarsDW223
19 */
20class ODTElementTableRow extends ODTStateElement
21{
22    /**
23     * Constructor.
24     *
25     * @param    string    $style_name    Name of the style
26     */
27    public function __construct($style_name=NULL) {
28        parent::__construct();
29        $this->setClass ('table-row');
30        if (isset($style_name)) {
31            $this->setStyleName ($style_name);
32        }
33    }
34
35    /**
36     * Return the elements name.
37     *
38     * @return    string    The ODT XML element name.
39     */
40    public function getElementName () {
41        return ('table:table-row');
42    }
43
44    /**
45     * Return string with encoded opening tag.
46     *
47     * @return    string    The ODT XML code to open this element.
48     */
49    public function getOpeningTag () {
50        $style_name = $this->getStyleName();
51        if (isset($style_name)) {
52            return '<table:table-row table:style-name="'.$style_name.'">';
53        }
54        return '<table:table-row>';
55    }
56
57    /**
58     * Return string with encoded closing tag.
59     *
60     * @return    string    The ODT XML code to close this element.
61     */
62    public function getClosingTag () {
63        return '</table:table-row>';
64    }
65
66    /**
67     * Are we in a paragraph or not?
68     * As a table row we are not.
69     *
70     * @return    boolean
71     */
72    public function getInParagraph() {
73        return false;
74    }
75
76    /**
77     * Determine and set the parent for this element.
78     * As a table row our parent is the table element.
79     *
80     * @param    ODTStateElement    $previous
81     */
82    public function determineParent(ODTStateElement $previous) {
83        $table = $previous;
84        while (isset($table)) {
85            if ($table->getClass() == 'table') {
86                break;
87            }
88            $table = $table->getParent();
89        }
90        $this->setParent($table);
91
92        if (!isset($table)) {
93            // ??? Should not be...
94            return;
95        }
96
97        // A new row, we are back in the first column again.
98        $table->increaseRowCount();
99        $table->setTableCurrentColumn(0);
100    }
101
102    /**
103     * Return the table to which this column belongs.
104     *
105     * @return    ODTStateElement
106     */
107    public function getTable () {
108        return $this->getParent();
109    }
110}
111