1: <?php
2: /**
3: * PHPWord
4: *
5: * Copyright (c) 2013 PHPWord
6: *
7: * This library is free software; you can redistribute it and/or
8: * modify it under the terms of the GNU Lesser General Public
9: * License as published by the Free Software Foundation; either
10: * version 2.1 of the License, or (at your option) any later version.
11: *
12: * This library is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this library; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20: *
21: * @category PHPWord
22: * @package PHPWord
23: * @copyright Copyright (c) 2013 PHPWord
24: * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25: * @version 0.7.0
26: */
27:
28: /**
29: * Class PHPWord_Section_Table
30: */
31: class PHPWord_Section_Table
32: {
33:
34: /**
35: * Table style
36: *
37: * @var PHPWord_Style_Table
38: */
39: private $_style;
40:
41: /**
42: * Table rows
43: *
44: * @var array
45: */
46: private $_rows = array();
47:
48: /**
49: * Table holder
50: *
51: * @var string
52: */
53: private $_insideOf = null;
54:
55: /**
56: * Table holder count
57: *
58: * @var array
59: */
60: private $_pCount;
61:
62: /**
63: * Table width
64: *
65: * @var int
66: */
67: private $_width = null;
68:
69:
70: /**
71: * Create a new table
72: *
73: * @param string $insideOf
74: * @param int $pCount
75: * @param mixed $style
76: */
77: public function __construct($insideOf, $pCount, $style = null)
78: {
79: $this->_insideOf = $insideOf;
80: $this->_pCount = $pCount;
81:
82: if (!is_null($style)) {
83: if (is_array($style)) {
84: $this->_style = new PHPWord_Style_Table();
85:
86: foreach ($style as $key => $value) {
87: if (substr($key, 0, 1) != '_') {
88: $key = '_' . $key;
89: }
90: $this->_style->setStyleValue($key, $value);
91: }
92: } else {
93: $this->_style = $style;
94: }
95: }
96: }
97:
98: /**
99: * Add a row
100: *
101: * @param int $height
102: */
103: public function addRow($height = null, $style = null)
104: {
105: $row = new PHPWord_Section_Table_Row($this->_insideOf, $this->_pCount, $height, $style);
106: $this->_rows[] = $row;
107: return $row;
108: }
109:
110: /**
111: * Add a cell
112: *
113: * @param int $width
114: * @param mixed $style
115: * @return PHPWord_Section_Table_Cell
116: */
117: public function addCell($width = null, $style = null)
118: {
119: $i = count($this->_rows) - 1;
120: $cell = $this->_rows[$i]->addCell($width, $style);
121: return $cell;
122: }
123:
124: /**
125: * Get all rows
126: *
127: * @return array
128: */
129: public function getRows()
130: {
131: return $this->_rows;
132: }
133:
134: /**
135: * Get table style
136: *
137: * @return PHPWord_Style_Table
138: */
139: public function getStyle()
140: {
141: return $this->_style;
142: }
143:
144: /**
145: * Set table width
146: *
147: * @var int $width
148: */
149: public function setWidth($width)
150: {
151: $this->_width = $width;
152: }
153:
154: /**
155: * Get table width
156: *
157: * @return int
158: */
159: public function getWidth()
160: {
161: return $this->_width;
162: }
163:
164: }
165: