ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Meta.php
Go to the documentation of this file.
1 <?php
2 
4 
9 
10 class Meta extends WriterPart
11 {
17  public function write(): string
18  {
19  $spreadsheet = $this->getParentWriter()->getSpreadsheet();
20 
21  $objWriter = null;
22  if ($this->getParentWriter()->getUseDiskCaching()) {
23  $objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
24  } else {
25  $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
26  }
27 
28  // XML header
29  $objWriter->startDocument('1.0', 'UTF-8');
30 
31  // Meta
32  $objWriter->startElement('office:document-meta');
33 
34  $objWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
35  $objWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
36  $objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
37  $objWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0');
38  $objWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
39  $objWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
40  $objWriter->writeAttribute('office:version', '1.2');
41 
42  $objWriter->startElement('office:meta');
43 
44  $objWriter->writeElement('meta:initial-creator', $spreadsheet->getProperties()->getCreator());
45  $objWriter->writeElement('dc:creator', $spreadsheet->getProperties()->getCreator());
46  $created = $spreadsheet->getProperties()->getCreated();
47  $date = Date::dateTimeFromTimestamp("$created");
48  $date->setTimeZone(Date::getDefaultOrLocalTimeZone());
49  $objWriter->writeElement('meta:creation-date', $date->format(DATE_W3C));
50  $created = $spreadsheet->getProperties()->getModified();
51  $date = Date::dateTimeFromTimestamp("$created");
52  $date->setTimeZone(Date::getDefaultOrLocalTimeZone());
53  $objWriter->writeElement('dc:date', $date->format(DATE_W3C));
54  $objWriter->writeElement('dc:title', $spreadsheet->getProperties()->getTitle());
55  $objWriter->writeElement('dc:description', $spreadsheet->getProperties()->getDescription());
56  $objWriter->writeElement('dc:subject', $spreadsheet->getProperties()->getSubject());
57  $objWriter->writeElement('meta:keyword', $spreadsheet->getProperties()->getKeywords());
58  // Don't know if this changed over time, but the keywords are all
59  // in a single declaration now.
60  //$keywords = explode(' ', $spreadsheet->getProperties()->getKeywords());
61  //foreach ($keywords as $keyword) {
62  // $objWriter->writeElement('meta:keyword', $keyword);
63  //}
64 
65  //<meta:document-statistic meta:table-count="XXX" meta:cell-count="XXX" meta:object-count="XXX"/>
66  $objWriter->startElement('meta:user-defined');
67  $objWriter->writeAttribute('meta:name', 'Company');
68  $objWriter->writeRaw($spreadsheet->getProperties()->getCompany());
69  $objWriter->endElement();
70 
71  $objWriter->startElement('meta:user-defined');
72  $objWriter->writeAttribute('meta:name', 'category');
73  $objWriter->writeRaw($spreadsheet->getProperties()->getCategory());
74  $objWriter->endElement();
75 
76  self::writeDocPropsCustom($objWriter, $spreadsheet);
77 
78  $objWriter->endElement();
79 
80  $objWriter->endElement();
81 
82  return $objWriter->getData();
83  }
84 
85  private static function writeDocPropsCustom(XMLWriter $objWriter, Spreadsheet $spreadsheet): void
86  {
87  $customPropertyList = $spreadsheet->getProperties()->getCustomProperties();
88  foreach ($customPropertyList as $key => $customProperty) {
89  $propertyValue = $spreadsheet->getProperties()->getCustomPropertyValue($customProperty);
90  $propertyType = $spreadsheet->getProperties()->getCustomPropertyType($customProperty);
91 
92  $objWriter->startElement('meta:user-defined');
93  $objWriter->writeAttribute('meta:name', $customProperty);
94 
95  switch ($propertyType) {
96  case Properties::PROPERTY_TYPE_INTEGER:
97  case Properties::PROPERTY_TYPE_FLOAT:
98  $objWriter->writeAttribute('meta:value-type', 'float');
99  $objWriter->writeRawData($propertyValue);
100 
101  break;
102  case Properties::PROPERTY_TYPE_BOOLEAN:
103  $objWriter->writeAttribute('meta:value-type', 'boolean');
104  $objWriter->writeRawData($propertyValue ? 'true' : 'false');
105 
106  break;
107  case Properties::PROPERTY_TYPE_DATE:
108  $objWriter->writeAttribute('meta:value-type', 'date');
109  $dtobj = Date::dateTimeFromTimestamp($propertyValue ?? 0);
110  $objWriter->writeRawData($dtobj->format(DATE_W3C));
111 
112  break;
113  default:
114  $objWriter->writeRawData($propertyValue);
115 
116  break;
117  }
118 
119  $objWriter->endElement();
120  }
121  }
122 }
writeRawData($text)
Wrapper method for writeRaw.
Definition: XMLWriter.php:84
static writeDocPropsCustom(XMLWriter $objWriter, Spreadsheet $spreadsheet)
Definition: Meta.php:85
getDiskCachingDirectory()
Get disk caching directory.
Definition: BaseWriter.php:92
static dateTimeFromTimestamp(string $date, ?DateTimeZone $timeZone=null)
Definition: Date.php:504
getUseDiskCaching()
Get use disk caching where possible?
Definition: BaseWriter.php:72
write()
Write meta.xml to XML format.
Definition: Meta.php:17
$key
Definition: croninfo.php:18