1
|
|
|
<?php |
2
|
|
|
namespace Ellumilel\Rels; |
3
|
|
|
|
4
|
|
|
use Ellumilel\Sheet; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* @link https://msdn.microsoft.com/en-us/library/bb264572(v=office.12).aspx |
8
|
|
|
* |
9
|
|
|
* Class Relationships |
10
|
|
|
* @package Ellumilel\Rels |
11
|
|
|
* @author Denis Tikhonov <[email protected]> |
12
|
|
|
*/ |
13
|
|
|
class Relationships |
14
|
|
|
{ |
15
|
|
|
/** @var string */ |
16
|
|
|
private $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"; |
17
|
|
|
/** @var string */ |
18
|
|
|
private $urlSchema = 'http://schemas.openxmlformats.org/officeDocument/2006'; |
19
|
|
|
/** @var string */ |
20
|
|
|
private $urlRel = 'http://schemas.openxmlformats.org/package/2006/relationships'; |
21
|
|
|
/** @var bool */ |
22
|
|
|
private $sharedStringsRelations = false; |
23
|
|
|
/** @var array */ |
24
|
|
|
private $sheets = []; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Relationships constructor. |
28
|
|
|
* |
29
|
|
|
* @param bool $sharedStringsRelations |
30
|
|
|
*/ |
31
|
|
|
public function __construct($sharedStringsRelations = false) |
32
|
|
|
{ |
33
|
|
|
$this->sharedStringsRelations = $sharedStringsRelations; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @return string |
38
|
|
|
*/ |
39
|
|
|
public function buildRelationshipsXML() |
40
|
|
|
{ |
41
|
|
|
$relXml = ''; |
42
|
|
|
$relXml .= $this->xml; |
43
|
|
|
$relXml .= '<Relationships xmlns="'.$this->urlRel.'">'; |
44
|
|
|
$relXml .= '<Relationship Id="rId1" Type="'.$this->urlSchema.'/relationships/officeDocument"'; |
45
|
|
|
$relXml .= ' Target="xl/workbook.xml"/>'; |
46
|
|
|
$relXml .= '<Relationship Id="rId2" Type="'.$this->urlSchema.'/relationships/metadata/core-properties"'; |
47
|
|
|
$relXml .= ' Target="docProps/core.xml"/>'; |
48
|
|
|
$relXml .= '<Relationship Id="rId3" Type="'.$this->urlSchema.'/relationships/extended-properties"'; |
49
|
|
|
$relXml .= ' Target="docProps/app.xml"/>'."\n"; |
50
|
|
|
$relXml .= '</Relationships>'; |
51
|
|
|
|
52
|
|
|
return $relXml; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return string |
57
|
|
|
*/ |
58
|
|
|
public function buildWorkbookRelationshipsXML() |
59
|
|
|
{ |
60
|
|
|
$i = 0; |
61
|
|
|
$relXml = ''; |
62
|
|
|
$relXml .= $this->xml; |
63
|
|
|
$relXml .= '<Relationships xmlns="'.$this->urlRel.'">'; |
64
|
|
|
$relXml .= '<Relationship Id="rId1" Type="'.$this->urlSchema.'/relationships/styles" Target="styles.xml"/>'; |
65
|
|
|
foreach ($this->sheets as $sheet) { |
66
|
|
|
/** @var Sheet $sheet */ |
67
|
|
|
$relXml .= '<Relationship Id="rId'.($i + 2).'" |
68
|
|
|
Type="'.$this->urlSchema.'/relationships/worksheet" Target="worksheets/'.($sheet->getXmlName()).'"/>'; |
69
|
|
|
$i++; |
70
|
|
|
} |
71
|
|
|
if (!empty($this->sharedStringsRelations)) { |
72
|
|
|
$relXml .= '<Relationship Id="rId'.(count($this->sheets) + 2).'" |
73
|
|
|
Type="'.$this->urlSchema.'/relationships/sharedStrings" Target="sharedStrings.xml"/>'; |
74
|
|
|
} |
75
|
|
|
$relXml .= "\n"; |
76
|
|
|
$relXml .= '</Relationships>'; |
77
|
|
|
|
78
|
|
|
return $relXml; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param array $sheets |
83
|
|
|
* |
84
|
|
|
* @return $this |
85
|
|
|
*/ |
86
|
|
|
public function setSheet(array $sheets) |
87
|
|
|
{ |
88
|
|
|
$this->sheets = $sheets; |
89
|
|
|
|
90
|
|
|
return $this; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|