ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Properties.php
Go to the documentation of this file.
1 <?php
2 
4 
8 
9 class Properties
10 {
11  private $spreadsheet;
12 
14  {
15  $this->spreadsheet = $spreadsheet;
16  }
17 
18  public function load(SimpleXMLElement $xml, $namespacesMeta): void
19  {
20  $docProps = $this->spreadsheet->getProperties();
21  $officeProperty = $xml->children($namespacesMeta['office']);
22  foreach ($officeProperty as $officePropertyData) {
23  // @var \SimpleXMLElement $officePropertyData
24  if (isset($namespacesMeta['dc'])) {
25  $officePropertiesDC = $officePropertyData->children($namespacesMeta['dc']);
26  $this->setCoreProperties($docProps, $officePropertiesDC);
27  }
28 
29  $officePropertyMeta = (object) [];
30  if (isset($namespacesMeta['dc'])) {
31  $officePropertyMeta = $officePropertyData->children($namespacesMeta['meta']);
32  }
33  foreach ($officePropertyMeta as $propertyName => $propertyValue) {
34  $this->setMetaProperties($namespacesMeta, $propertyValue, $propertyName, $docProps);
35  }
36  }
37  }
38 
39  private function setCoreProperties(DocumentProperties $docProps, SimpleXMLElement $officePropertyDC): void
40  {
41  foreach ($officePropertyDC as $propertyName => $propertyValue) {
42  $propertyValue = (string) $propertyValue;
43  switch ($propertyName) {
44  case 'title':
45  $docProps->setTitle($propertyValue);
46 
47  break;
48  case 'subject':
49  $docProps->setSubject($propertyValue);
50 
51  break;
52  case 'creator':
53  $docProps->setCreator($propertyValue);
54  $docProps->setLastModifiedBy($propertyValue);
55 
56  break;
57  case 'date':
58  $docProps->setModified($propertyValue);
59 
60  break;
61  case 'description':
62  $docProps->setDescription($propertyValue);
63 
64  break;
65  }
66  }
67  }
68 
69  private function setMetaProperties(
70  $namespacesMeta,
71  SimpleXMLElement $propertyValue,
72  $propertyName,
73  DocumentProperties $docProps
74  ): void {
75  $propertyValueAttributes = $propertyValue->attributes($namespacesMeta['meta']);
76  $propertyValue = (string) $propertyValue;
77  switch ($propertyName) {
78  case 'initial-creator':
79  $docProps->setCreator($propertyValue);
80 
81  break;
82  case 'keyword':
83  $docProps->setKeywords($propertyValue);
84 
85  break;
86  case 'creation-date':
87  $docProps->setCreated($propertyValue);
88 
89  break;
90  case 'user-defined':
91  $this->setUserDefinedProperty($propertyValueAttributes, $propertyValue, $docProps);
92 
93  break;
94  }
95  }
96 
97  private function setUserDefinedProperty($propertyValueAttributes, $propertyValue, DocumentProperties $docProps): void
98  {
99  $propertyValueName = '';
100  $propertyValueType = DocumentProperties::PROPERTY_TYPE_STRING;
101  foreach ($propertyValueAttributes as $key => $value) {
102  if ($key == 'name') {
103  $propertyValueName = (string) $value;
104  } elseif ($key == 'value-type') {
105  switch ($value) {
106  case 'date':
107  $propertyValue = DocumentProperties::convertProperty($propertyValue, 'date');
108  $propertyValueType = DocumentProperties::PROPERTY_TYPE_DATE;
109 
110  break;
111  case 'boolean':
112  $propertyValue = DocumentProperties::convertProperty($propertyValue, 'bool');
113  $propertyValueType = DocumentProperties::PROPERTY_TYPE_BOOLEAN;
114 
115  break;
116  case 'float':
117  $propertyValue = DocumentProperties::convertProperty($propertyValue, 'r4');
118  $propertyValueType = DocumentProperties::PROPERTY_TYPE_FLOAT;
119 
120  break;
121  default:
122  $propertyValueType = DocumentProperties::PROPERTY_TYPE_STRING;
123  }
124  }
125  }
126 
127  $docProps->setCustomProperty($propertyValueName, $propertyValue, $propertyValueType);
128  }
129 }
setMetaProperties( $namespacesMeta, SimpleXMLElement $propertyValue, $propertyName, DocumentProperties $docProps)
Definition: Properties.php:69
setCoreProperties(DocumentProperties $docProps, SimpleXMLElement $officePropertyDC)
Definition: Properties.php:39
setUserDefinedProperty($propertyValueAttributes, $propertyValue, DocumentProperties $docProps)
Definition: Properties.php:97
load(SimpleXMLElement $xml, $namespacesMeta)
Definition: Properties.php:18
$key
Definition: croninfo.php:18