ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Rels.php
Go to the documentation of this file.
1<?php
37{
45 public function writeRelationships(PHPExcel $pPHPExcel = null)
46 {
47 // Create XML writer
48 $objWriter = null;
49 if ($this->getParentWriter()->getUseDiskCaching()) {
51 } else {
53 }
54
55 // XML header
56 $objWriter->startDocument('1.0','UTF-8','yes');
57
58 // Relationships
59 $objWriter->startElement('Relationships');
60 $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
61
62 $customPropertyList = $pPHPExcel->getProperties()->getCustomProperties();
63 if (!empty($customPropertyList)) {
64 // Relationship docProps/app.xml
65 $this->_writeRelationship(
67 4,
68 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties',
69 'docProps/custom.xml'
70 );
71
72 }
73
74 // Relationship docProps/app.xml
75 $this->_writeRelationship(
77 3,
78 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties',
79 'docProps/app.xml'
80 );
81
82 // Relationship docProps/core.xml
83 $this->_writeRelationship(
85 2,
86 'http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties',
87 'docProps/core.xml'
88 );
89
90 // Relationship xl/workbook.xml
91 $this->_writeRelationship(
93 1,
94 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument',
95 'xl/workbook.xml'
96 );
97 // a custom UI in workbook ?
98 if($pPHPExcel->hasRibbon()){
99 $this->_writeRelationShip(
101 5,
102 'http://schemas.microsoft.com/office/2006/relationships/ui/extensibility',
103 $pPHPExcel->getRibbonXMLData('target')
104 );
105 }
106
107 $objWriter->endElement();
108
109 // Return
110 return $objWriter->getData();
111 }
112
120 public function writeWorkbookRelationships(PHPExcel $pPHPExcel = null)
121 {
122 // Create XML writer
123 $objWriter = null;
124 if ($this->getParentWriter()->getUseDiskCaching()) {
126 } else {
128 }
129
130 // XML header
131 $objWriter->startDocument('1.0','UTF-8','yes');
132
133 // Relationships
134 $objWriter->startElement('Relationships');
135 $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
136
137 // Relationship styles.xml
138 $this->_writeRelationship(
140 1,
141 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles',
142 'styles.xml'
143 );
144
145 // Relationship theme/theme1.xml
146 $this->_writeRelationship(
148 2,
149 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme',
150 'theme/theme1.xml'
151 );
152
153 // Relationship sharedStrings.xml
154 $this->_writeRelationship(
156 3,
157 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings',
158 'sharedStrings.xml'
159 );
160
161 // Relationships with sheets
162 $sheetCount = $pPHPExcel->getSheetCount();
163 for ($i = 0; $i < $sheetCount; ++$i) {
164 $this->_writeRelationship(
166 ($i + 1 + 3),
167 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet',
168 'worksheets/sheet' . ($i + 1) . '.xml'
169 );
170 }
171 // Relationships for vbaProject if needed
172 // id : just after the last sheet
173 if($pPHPExcel->hasMacros()){
174 $this->_writeRelationShip(
176 ($i + 1 + 3),
177 'http://schemas.microsoft.com/office/2006/relationships/vbaProject',
178 'vbaProject.bin'
179 );
180 ++$i;//increment i if needed for an another relation
181 }
182
183 $objWriter->endElement();
184
185 // Return
186 return $objWriter->getData();
187 }
188
202 public function writeWorksheetRelationships(PHPExcel_Worksheet $pWorksheet = null, $pWorksheetId = 1, $includeCharts = FALSE)
203 {
204 // Create XML writer
205 $objWriter = null;
206 if ($this->getParentWriter()->getUseDiskCaching()) {
208 } else {
210 }
211
212 // XML header
213 $objWriter->startDocument('1.0','UTF-8','yes');
214
215 // Relationships
216 $objWriter->startElement('Relationships');
217 $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
218
219 // Write drawing relationships?
220 $d = 0;
221 if ($includeCharts) {
222 $charts = $pWorksheet->getChartCollection();
223 } else {
224 $charts = array();
225 }
226 if (($pWorksheet->getDrawingCollection()->count() > 0) ||
227 (count($charts) > 0)) {
228 $this->_writeRelationship(
230 ++$d,
231 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing',
232 '../drawings/drawing' . $pWorksheetId . '.xml'
233 );
234 }
235
236 // Write chart relationships?
237// $chartCount = 0;
238// $charts = $pWorksheet->getChartCollection();
239// echo 'Chart Rels: ' , count($charts) , '<br />';
240// if (count($charts) > 0) {
241// foreach($charts as $chart) {
242// $this->_writeRelationship(
243// $objWriter,
244// ++$d,
245// 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart',
246// '../charts/chart' . ++$chartCount . '.xml'
247// );
248// }
249// }
250//
251 // Write hyperlink relationships?
252 $i = 1;
253 foreach ($pWorksheet->getHyperlinkCollection() as $hyperlink) {
254 if (!$hyperlink->isInternal()) {
255 $this->_writeRelationship(
257 '_hyperlink_' . $i,
258 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink',
259 $hyperlink->getUrl(),
260 'External'
261 );
262
263 ++$i;
264 }
265 }
266
267 // Write comments relationship?
268 $i = 1;
269 if (count($pWorksheet->getComments()) > 0) {
270 $this->_writeRelationship(
272 '_comments_vml' . $i,
273 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing',
274 '../drawings/vmlDrawing' . $pWorksheetId . '.vml'
275 );
276
277 $this->_writeRelationship(
279 '_comments' . $i,
280 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments',
281 '../comments' . $pWorksheetId . '.xml'
282 );
283 }
284
285 // Write header/footer relationship?
286 $i = 1;
287 if (count($pWorksheet->getHeaderFooter()->getImages()) > 0) {
288 $this->_writeRelationship(
290 '_headerfooter_vml' . $i,
291 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing',
292 '../drawings/vmlDrawingHF' . $pWorksheetId . '.vml'
293 );
294 }
295
296 $objWriter->endElement();
297
298 // Return
299 return $objWriter->getData();
300 }
301
311 public function writeDrawingRelationships(PHPExcel_Worksheet $pWorksheet = null, &$chartRef, $includeCharts = FALSE)
312 {
313 // Create XML writer
314 $objWriter = null;
315 if ($this->getParentWriter()->getUseDiskCaching()) {
317 } else {
319 }
320
321 // XML header
322 $objWriter->startDocument('1.0','UTF-8','yes');
323
324 // Relationships
325 $objWriter->startElement('Relationships');
326 $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
327
328 // Loop through images and write relationships
329 $i = 1;
330 $iterator = $pWorksheet->getDrawingCollection()->getIterator();
331 while ($iterator->valid()) {
332 if ($iterator->current() instanceof PHPExcel_Worksheet_Drawing
333 || $iterator->current() instanceof PHPExcel_Worksheet_MemoryDrawing) {
334 // Write relationship for image drawing
335 $this->_writeRelationship(
337 $i,
338 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image',
339 '../media/' . str_replace(' ', '', $iterator->current()->getIndexedFilename())
340 );
341 }
342
343 $iterator->next();
344 ++$i;
345 }
346
347 if ($includeCharts) {
348 // Loop through charts and write relationships
349 $chartCount = $pWorksheet->getChartCount();
350 if ($chartCount > 0) {
351 for ($c = 0; $c < $chartCount; ++$c) {
352 $this->_writeRelationship(
354 $i++,
355 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart',
356 '../charts/chart' . ++$chartRef . '.xml'
357 );
358 }
359 }
360 }
361
362 $objWriter->endElement();
363
364 // Return
365 return $objWriter->getData();
366 }
367
376 {
377 // Create XML writer
378 $objWriter = null;
379 if ($this->getParentWriter()->getUseDiskCaching()) {
381 } else {
383 }
384
385 // XML header
386 $objWriter->startDocument('1.0','UTF-8','yes');
387
388 // Relationships
389 $objWriter->startElement('Relationships');
390 $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
391
392 // Loop through images and write relationships
393 foreach ($pWorksheet->getHeaderFooter()->getImages() as $key => $value) {
394 // Write relationship for image drawing
395 $this->_writeRelationship(
397 $key,
398 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image',
399 '../media/' . $value->getIndexedFilename()
400 );
401 }
402
403 $objWriter->endElement();
404
405 // Return
406 return $objWriter->getData();
407 }
408
419 private function _writeRelationship(PHPExcel_Shared_XMLWriter $objWriter = null, $pId = 1, $pType = '', $pTarget = '', $pTargetMode = '')
420 {
421 if ($pType != '' && $pTarget != '') {
422 // Write relationship
423 $objWriter->startElement('Relationship');
424 $objWriter->writeAttribute('Id', 'rId' . $pId);
425 $objWriter->writeAttribute('Type', $pType);
426 $objWriter->writeAttribute('Target', $pTarget);
427
428 if ($pTargetMode != '') {
429 $objWriter->writeAttribute('TargetMode', $pTargetMode);
430 }
431
432 $objWriter->endElement();
433 } else {
434 throw new PHPExcel_Writer_Exception("Invalid parameters passed.");
435 }
436 }
437}
$objWriter
An exception for terminatinating execution or to throw for unit testing.
const STORAGE_MEMORY
Temporary storage method.
Definition: XMLWriter.php:46
writeWorksheetRelationships(PHPExcel_Worksheet $pWorksheet=null, $pWorksheetId=1, $includeCharts=FALSE)
Write worksheet relationships to XML format.
Definition: Rels.php:202
writeHeaderFooterDrawingRelationships(PHPExcel_Worksheet $pWorksheet=null)
Write header/footer drawing relationships to XML format.
Definition: Rels.php:375
writeWorkbookRelationships(PHPExcel $pPHPExcel=null)
Write workbook relationships to XML format.
Definition: Rels.php:120
writeRelationships(PHPExcel $pPHPExcel=null)
Write relationships to XML format.
Definition: Rels.php:45
_writeRelationship(PHPExcel_Shared_XMLWriter $objWriter=null, $pId=1, $pType='', $pTarget='', $pTargetMode='')
Write Override content type.
Definition: Rels.php:419
writeDrawingRelationships(PHPExcel_Worksheet $pWorksheet=null, &$chartRef, $includeCharts=FALSE)
Write drawing relationships to XML format.
Definition: Rels.php:311
getParentWriter()
Get parent IWriter object.
Definition: WriterPart.php:61
$key
Definition: croninfo.php:18
for( $i=6;$i< 13;$i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
$i
Definition: disco.tpl.php:19