1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26:
27:
28: 29: 30:
31: class
32: {
33:
34: 35: 36: 37: 38:
39: private ;
40:
41: 42: 43: 44: 45:
46: private $_rId;
47:
48: 49: 50: 51: 52: 53:
54: private $_type = PHPWord_Section_Header::AUTO;
55:
56: 57: 58: 59: 60:
61: const EVEN = 'even';
62:
63: 64: 65: 66: 67:
68: const AUTO = 'default';
69:
70: 71: 72: 73: 74:
75: const FIRST = 'first';
76:
77: 78: 79: 80: 81:
82: private $_elementCollection = array();
83:
84: 85: 86:
87: public function __construct($sectionCount)
88: {
89: $this->_headerCount = $sectionCount;
90: }
91:
92: 93: 94: 95: 96: 97: 98: 99:
100: public function addText($text, $styleFont = null, $styleParagraph = null)
101: {
102: if (!PHPWord_Shared_String::IsUTF8($text)) {
103: $text = utf8_encode($text);
104: }
105: $text = new PHPWord_Section_Text($text, $styleFont, $styleParagraph);
106: $this->_elementCollection[] = $text;
107: return $text;
108: }
109:
110: 111: 112: 113: 114:
115: public function addTextBreak($count = 1)
116: {
117: for ($i = 1; $i <= $count; $i++) {
118: $this->_elementCollection[] = new PHPWord_Section_TextBreak();
119: }
120: }
121:
122: 123: 124: 125: 126:
127: public function createTextRun($styleParagraph = null)
128: {
129: $textRun = new PHPWord_Section_TextRun($styleParagraph);
130: $this->_elementCollection[] = $textRun;
131: return $textRun;
132: }
133:
134: 135: 136: 137: 138: 139:
140: public function addTable($style = null)
141: {
142: $table = new PHPWord_Section_Table('header', $this->_headerCount, $style);
143: $this->_elementCollection[] = $table;
144: return $table;
145: }
146:
147: 148: 149: 150: 151: 152: 153:
154: public function addImage($src, $style = null)
155: {
156: $image = new PHPWord_Section_Image($src, $style);
157:
158: if (!is_null($image->getSource())) {
159: $rID = PHPWord_Media::addHeaderMediaElement($this->_headerCount, $src);
160: $image->setRelationId($rID);
161:
162: $this->_elementCollection[] = $image;
163: return $image;
164: } else {
165: trigger_error('Src does not exist or invalid image type.', E_USER_ERROR);
166: }
167: }
168:
169: 170: 171: 172: 173: 174: 175:
176: public function addMemoryImage($link, $style = null)
177: {
178: $memoryImage = new PHPWord_Section_MemoryImage($link, $style);
179: if (!is_null($memoryImage->getSource())) {
180: $rID = PHPWord_Media::addHeaderMediaElement($this->_headerCount, $link, $memoryImage);
181: $memoryImage->setRelationId($rID);
182:
183: $this->_elementCollection[] = $memoryImage;
184: return $memoryImage;
185: } else {
186: trigger_error('Unsupported image type.');
187: }
188: }
189:
190: 191: 192: 193: 194: 195: 196: 197:
198: public function addPreserveText($text, $styleFont = null, $styleParagraph = null)
199: {
200: if (!PHPWord_Shared_String::IsUTF8($text)) {
201: $text = utf8_encode($text);
202: }
203: $ptext = new PHPWord_Section_Footer_PreserveText($text, $styleFont, $styleParagraph);
204: $this->_elementCollection[] = $ptext;
205: return $ptext;
206: }
207:
208: 209: 210: 211: 212: 213: 214:
215: public function addWatermark($src, $style = null)
216: {
217: $image = new PHPWord_Section_Image($src, $style, true);
218:
219: if (!is_null($image->getSource())) {
220: $rID = PHPWord_Media::addHeaderMediaElement($this->_headerCount, $src);
221: $image->setRelationId($rID);
222:
223: $this->_elementCollection[] = $image;
224: return $image;
225: } else {
226: trigger_error('Src does not exist or invalid image type.', E_USER_ERROR);
227: }
228: }
229:
230: 231: 232:
233: public function getRelationId()
234: {
235: return $this->_rId;
236: }
237:
238: 239: 240: 241: 242:
243: public function setRelationId($rId)
244: {
245: $this->_rId = $rId;
246: }
247:
248: 249: 250:
251: public function getElements()
252: {
253: return $this->_elementCollection;
254: }
255:
256: 257: 258:
259: public function ()
260: {
261: return $this->_headerCount;
262: }
263:
264: 265: 266:
267: public function getType()
268: {
269: return $this->_type;
270: }
271:
272: 273: 274:
275: public function resetType()
276: {
277: return $this->_type = PHPWord_Section_Header::AUTO;
278: }
279:
280: 281: 282:
283: public function firstPage()
284: {
285: return $this->_type = PHPWord_Section_Header::FIRST;
286: }
287:
288: 289: 290:
291: public function evenPage()
292: {
293: return $this->_type = PHPWord_Section_Header::EVEN;
294: }
295:
296: }