ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
DocProps.php
Go to the documentation of this file.
1 <?php
2 
4 
9 
10 class DocProps extends WriterPart
11 {
17  public function writeDocPropsApp(Spreadsheet $spreadsheet)
18  {
19  // Create XML writer
20  $objWriter = null;
21  if ($this->getParentWriter()->getUseDiskCaching()) {
22  $objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
23  } else {
24  $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
25  }
26 
27  // XML header
28  $objWriter->startDocument('1.0', 'UTF-8', 'yes');
29 
30  // Properties
31  $objWriter->startElement('Properties');
32  $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/officeDocument/2006/extended-properties');
33  $objWriter->writeAttribute('xmlns:vt', 'http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes');
34 
35  // Application
36  $objWriter->writeElement('Application', 'Microsoft Excel');
37 
38  // DocSecurity
39  $objWriter->writeElement('DocSecurity', '0');
40 
41  // ScaleCrop
42  $objWriter->writeElement('ScaleCrop', 'false');
43 
44  // HeadingPairs
45  $objWriter->startElement('HeadingPairs');
46 
47  // Vector
48  $objWriter->startElement('vt:vector');
49  $objWriter->writeAttribute('size', '2');
50  $objWriter->writeAttribute('baseType', 'variant');
51 
52  // Variant
53  $objWriter->startElement('vt:variant');
54  $objWriter->writeElement('vt:lpstr', 'Worksheets');
55  $objWriter->endElement();
56 
57  // Variant
58  $objWriter->startElement('vt:variant');
59  $objWriter->writeElement('vt:i4', $spreadsheet->getSheetCount());
60  $objWriter->endElement();
61 
62  $objWriter->endElement();
63 
64  $objWriter->endElement();
65 
66  // TitlesOfParts
67  $objWriter->startElement('TitlesOfParts');
68 
69  // Vector
70  $objWriter->startElement('vt:vector');
71  $objWriter->writeAttribute('size', $spreadsheet->getSheetCount());
72  $objWriter->writeAttribute('baseType', 'lpstr');
73 
74  $sheetCount = $spreadsheet->getSheetCount();
75  for ($i = 0; $i < $sheetCount; ++$i) {
76  $objWriter->writeElement('vt:lpstr', $spreadsheet->getSheet($i)->getTitle());
77  }
78 
79  $objWriter->endElement();
80 
81  $objWriter->endElement();
82 
83  // Company
84  $objWriter->writeElement('Company', $spreadsheet->getProperties()->getCompany());
85 
86  // Company
87  $objWriter->writeElement('Manager', $spreadsheet->getProperties()->getManager());
88 
89  // LinksUpToDate
90  $objWriter->writeElement('LinksUpToDate', 'false');
91 
92  // SharedDoc
93  $objWriter->writeElement('SharedDoc', 'false');
94 
95  // HyperlinksChanged
96  $objWriter->writeElement('HyperlinksChanged', 'false');
97 
98  // AppVersion
99  $objWriter->writeElement('AppVersion', '12.0000');
100 
101  $objWriter->endElement();
102 
103  // Return
104  return $objWriter->getData();
105  }
106 
112  public function writeDocPropsCore(Spreadsheet $spreadsheet)
113  {
114  // Create XML writer
115  $objWriter = null;
116  if ($this->getParentWriter()->getUseDiskCaching()) {
117  $objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
118  } else {
119  $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
120  }
121 
122  // XML header
123  $objWriter->startDocument('1.0', 'UTF-8', 'yes');
124 
125  // cp:coreProperties
126  $objWriter->startElement('cp:coreProperties');
127  $objWriter->writeAttribute('xmlns:cp', 'http://schemas.openxmlformats.org/package/2006/metadata/core-properties');
128  $objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
129  $objWriter->writeAttribute('xmlns:dcterms', 'http://purl.org/dc/terms/');
130  $objWriter->writeAttribute('xmlns:dcmitype', 'http://purl.org/dc/dcmitype/');
131  $objWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
132 
133  // dc:creator
134  $objWriter->writeElement('dc:creator', $spreadsheet->getProperties()->getCreator());
135 
136  // cp:lastModifiedBy
137  $objWriter->writeElement('cp:lastModifiedBy', $spreadsheet->getProperties()->getLastModifiedBy());
138 
139  // dcterms:created
140  $objWriter->startElement('dcterms:created');
141  $objWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF');
142  $created = $spreadsheet->getProperties()->getCreated();
143  $date = Date::dateTimeFromTimestamp("$created");
144  $objWriter->writeRawData($date->format(DATE_W3C));
145  $objWriter->endElement();
146 
147  // dcterms:modified
148  $objWriter->startElement('dcterms:modified');
149  $objWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF');
150  $created = $spreadsheet->getProperties()->getModified();
151  $date = Date::dateTimeFromTimestamp("$created");
152  $objWriter->writeRawData($date->format(DATE_W3C));
153  $objWriter->endElement();
154 
155  // dc:title
156  $objWriter->writeElement('dc:title', $spreadsheet->getProperties()->getTitle());
157 
158  // dc:description
159  $objWriter->writeElement('dc:description', $spreadsheet->getProperties()->getDescription());
160 
161  // dc:subject
162  $objWriter->writeElement('dc:subject', $spreadsheet->getProperties()->getSubject());
163 
164  // cp:keywords
165  $objWriter->writeElement('cp:keywords', $spreadsheet->getProperties()->getKeywords());
166 
167  // cp:category
168  $objWriter->writeElement('cp:category', $spreadsheet->getProperties()->getCategory());
169 
170  $objWriter->endElement();
171 
172  // Return
173  return $objWriter->getData();
174  }
175 
181  public function writeDocPropsCustom(Spreadsheet $spreadsheet)
182  {
183  $customPropertyList = $spreadsheet->getProperties()->getCustomProperties();
184  if (empty($customPropertyList)) {
185  return null;
186  }
187 
188  // Create XML writer
189  $objWriter = null;
190  if ($this->getParentWriter()->getUseDiskCaching()) {
191  $objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
192  } else {
193  $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
194  }
195 
196  // XML header
197  $objWriter->startDocument('1.0', 'UTF-8', 'yes');
198 
199  // cp:coreProperties
200  $objWriter->startElement('Properties');
201  $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/officeDocument/2006/custom-properties');
202  $objWriter->writeAttribute('xmlns:vt', 'http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes');
203 
204  foreach ($customPropertyList as $key => $customProperty) {
205  $propertyValue = $spreadsheet->getProperties()->getCustomPropertyValue($customProperty);
206  $propertyType = $spreadsheet->getProperties()->getCustomPropertyType($customProperty);
207 
208  $objWriter->startElement('property');
209  $objWriter->writeAttribute('fmtid', '{D5CDD505-2E9C-101B-9397-08002B2CF9AE}');
210  $objWriter->writeAttribute('pid', $key + 2);
211  $objWriter->writeAttribute('name', $customProperty);
212 
213  switch ($propertyType) {
214  case Properties::PROPERTY_TYPE_INTEGER:
215  $objWriter->writeElement('vt:i4', $propertyValue);
216 
217  break;
218  case Properties::PROPERTY_TYPE_FLOAT:
219  $objWriter->writeElement('vt:r8', $propertyValue);
220 
221  break;
222  case Properties::PROPERTY_TYPE_BOOLEAN:
223  $objWriter->writeElement('vt:bool', ($propertyValue) ? 'true' : 'false');
224 
225  break;
226  case Properties::PROPERTY_TYPE_DATE:
227  $objWriter->startElement('vt:filetime');
228  $date = Date::dateTimeFromTimestamp("$propertyValue");
229  $objWriter->writeRawData($date->format(DATE_W3C));
230  $objWriter->endElement();
231 
232  break;
233  default:
234  $objWriter->writeElement('vt:lpwstr', $propertyValue);
235 
236  break;
237  }
238 
239  $objWriter->endElement();
240  }
241 
242  $objWriter->endElement();
243 
244  return $objWriter->getData();
245  }
246 }
getSheet($pIndex)
Get sheet by index.
writeDocPropsApp(Spreadsheet $spreadsheet)
Write docProps/app.xml to XML format.
Definition: DocProps.php:17
getDiskCachingDirectory()
Get disk caching directory.
Definition: BaseWriter.php:92
static dateTimeFromTimestamp(string $date, ?DateTimeZone $timeZone=null)
Definition: Date.php:504
writeDocPropsCore(Spreadsheet $spreadsheet)
Write docProps/core.xml to XML format.
Definition: DocProps.php:112
$i
Definition: disco.tpl.php:19
getUseDiskCaching()
Get use disk caching where possible?
Definition: BaseWriter.php:72
writeDocPropsCustom(Spreadsheet $spreadsheet)
Write docProps/custom.xml to XML format.
Definition: DocProps.php:181
$key
Definition: croninfo.php:18