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 {
14  protected $spreadsheet;
15 
17  {
18  $this->spreadsheet = $spreadsheet;
19  }
20 
21  private function docPropertiesOld(SimpleXMLElement $gnmXML): void
22  {
23  $docProps = $this->spreadsheet->getProperties();
24  foreach ($gnmXML->Summary->Item as $summaryItem) {
25  $propertyName = $summaryItem->name;
26  $propertyValue = $summaryItem->{'val-string'};
27  switch ($propertyName) {
28  case 'title':
29  $docProps->setTitle(trim($propertyValue));
30 
31  break;
32  case 'comments':
33  $docProps->setDescription(trim($propertyValue));
34 
35  break;
36  case 'keywords':
37  $docProps->setKeywords(trim($propertyValue));
38 
39  break;
40  case 'category':
41  $docProps->setCategory(trim($propertyValue));
42 
43  break;
44  case 'manager':
45  $docProps->setManager(trim($propertyValue));
46 
47  break;
48  case 'author':
49  $docProps->setCreator(trim($propertyValue));
50  $docProps->setLastModifiedBy(trim($propertyValue));
51 
52  break;
53  case 'company':
54  $docProps->setCompany(trim($propertyValue));
55 
56  break;
57  }
58  }
59  }
60 
61  private function docPropertiesDC(SimpleXMLElement $officePropertyDC): void
62  {
63  $docProps = $this->spreadsheet->getProperties();
64  foreach ($officePropertyDC as $propertyName => $propertyValue) {
65  $propertyValue = trim((string) $propertyValue);
66  switch ($propertyName) {
67  case 'title':
68  $docProps->setTitle($propertyValue);
69 
70  break;
71  case 'subject':
72  $docProps->setSubject($propertyValue);
73 
74  break;
75  case 'creator':
76  $docProps->setCreator($propertyValue);
77  $docProps->setLastModifiedBy($propertyValue);
78 
79  break;
80  case 'date':
81  $creationDate = $propertyValue;
82  $docProps->setModified($creationDate);
83 
84  break;
85  case 'description':
86  $docProps->setDescription($propertyValue);
87 
88  break;
89  }
90  }
91  }
92 
93  private function docPropertiesMeta(SimpleXMLElement $officePropertyMeta): void
94  {
95  $docProps = $this->spreadsheet->getProperties();
96  foreach ($officePropertyMeta as $propertyName => $propertyValue) {
97  if ($propertyValue !== null) {
98  $attributes = $propertyValue->attributes(Gnumeric::NAMESPACE_META);
99  $propertyValue = trim((string) $propertyValue);
100  switch ($propertyName) {
101  case 'keyword':
102  $docProps->setKeywords($propertyValue);
103 
104  break;
105  case 'initial-creator':
106  $docProps->setCreator($propertyValue);
107  $docProps->setLastModifiedBy($propertyValue);
108 
109  break;
110  case 'creation-date':
111  $creationDate = $propertyValue;
112  $docProps->setCreated($creationDate);
113 
114  break;
115  case 'user-defined':
116  [, $attrName] = explode(':', $attributes['name']);
117  $this->userDefinedProperties($attrName, $propertyValue);
118 
119  break;
120  }
121  }
122  }
123  }
124 
125  private function userDefinedProperties(string $attrName, string $propertyValue): void
126  {
127  $docProps = $this->spreadsheet->getProperties();
128  switch ($attrName) {
129  case 'publisher':
130  $docProps->setCompany($propertyValue);
131 
132  break;
133  case 'category':
134  $docProps->setCategory($propertyValue);
135 
136  break;
137  case 'manager':
138  $docProps->setManager($propertyValue);
139 
140  break;
141  }
142  }
143 
144  public function readProperties(SimpleXMLElement $xml, SimpleXMLElement $gnmXML): void
145  {
146  $officeXML = $xml->children(Gnumeric::NAMESPACE_OFFICE);
147  if (!empty($officeXML)) {
148  $officeDocXML = $officeXML->{'document-meta'};
149  $officeDocMetaXML = $officeDocXML->meta;
150 
151  foreach ($officeDocMetaXML as $officePropertyData) {
152  $officePropertyDC = $officePropertyData->children(Gnumeric::NAMESPACE_DC);
153  $this->docPropertiesDC($officePropertyDC);
154 
155  $officePropertyMeta = $officePropertyData->children(Gnumeric::NAMESPACE_META);
156  $this->docPropertiesMeta($officePropertyMeta);
157  }
158  } elseif (isset($gnmXML->Summary)) {
159  $this->docPropertiesOld($gnmXML);
160  }
161  }
162 }
readProperties(SimpleXMLElement $xml, SimpleXMLElement $gnmXML)
Definition: Properties.php:144
docPropertiesMeta(SimpleXMLElement $officePropertyMeta)
Definition: Properties.php:93
if(array_key_exists('yes', $_REQUEST)) $attributes
Definition: getconsent.php:85
docPropertiesDC(SimpleXMLElement $officePropertyDC)
Definition: Properties.php:61
userDefinedProperties(string $attrName, string $propertyValue)
Definition: Properties.php:125