File Source for DocumentProperties.php

PHPExcel

# Source for file DocumentProperties.php

Documentation is available at DocumentProperties.php

1. <?php
2. /**
3. * PHPExcel
4. *
5. * Copyright (c) 2006 - 2011 PHPExcel
6. *
7. * This library is free software; you can redistribute it and/or
8. * modify it under the terms of the GNU Lesser General Public
9. * License as published by the Free Software Foundation; either
10. * version 2.1 of the License, or (at your option) any later version.
11. *
12. * This library is distributed in the hope that it will be useful,
13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15. * Lesser General Public License for more details.
16. *
17. * You should have received a copy of the GNU Lesser General Public
18. * License along with this library; if not, write to the Free Software
19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20. *
21. * @category PHPExcel
22. * @package PHPExcel
23. * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25. * @version 1.7.6, 2011-02-27
26. */
29. /**
30. * PHPExcel_DocumentProperties
31. *
32. * @category PHPExcel
33. * @package PHPExcel
34. * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
35. */
36. class PHPExcel_DocumentProperties
37. {
38. /** constants */
39. const PROPERTY_TYPE_BOOLEAN = 'b';
40. const PROPERTY_TYPE_INTEGER = 'i';
41. const PROPERTY_TYPE_FLOAT = 'f';
42. const PROPERTY_TYPE_DATE = 'd';
43. const PROPERTY_TYPE_STRING = 's';
44. const PROPERTY_TYPE_UNKNOWN = 'u';
47. /**
48. * Creator
49. *
50. * @var string
51. */
52. private $_creator = 'Unknown Creator';
54. /**
55. * LastModifiedBy
56. *
57. * @var string
58. */
59. private $_lastModifiedBy;
61. /**
62. * Created
63. *
64. * @var datetime
65. */
66. private $_created;
68. /**
69. * Modified
70. *
71. * @var datetime
72. */
73. private $_modified;
75. /**
76. * Title
77. *
78. * @var string
79. */
80. private $_title = 'Untitled Spreadsheet';
82. /**
83. * Description
84. *
85. * @var string
86. */
87. private $_description = '';
89. /**
90. * Subject
91. *
92. * @var string
93. */
94. private $_subject = '';
96. /**
97. * Keywords
98. *
99. * @var string
100. */
101. private $_keywords = '';
103. /**
104. * Category
105. *
106. * @var string
107. */
108. private $_category = '';
110. /**
111. * Manager
112. *
113. * @var string
114. */
115. private $_manager = '';
117. /**
118. * Company
119. *
120. * @var string
121. */
122. private $_company = 'Microsoft Corporation';
124. /**
125. * Custom Properties
126. *
127. * @var string
128. */
129. private $_customProperties = array();
132. /**
133. * Create a new PHPExcel_DocumentProperties
134. */
135. public function __construct()
136. {
137. // Initialise values
138. $this->_lastModifiedBy = $this->_creator;
139. $this->_created = time();
140. $this->_modified = time();
141. }
143. /**
144. * Get Creator
145. *
146. * @return string
147. */
148. public function getCreator() {
149. return $this->_creator;
150. }
152. /**
153. * Set Creator
154. *
155. * @param string $pValue
156. * @return PHPExcel_DocumentProperties
157. */
158. public function setCreator($pValue = '') {
159. $this->_creator = $pValue;
160. return $this;
161. }
163. /**
164. * Get Last Modified By
165. *
166. * @return string
167. */
168. public function getLastModifiedBy() {
169. return $this->_lastModifiedBy;
170. }
172. /**
173. * Set Last Modified By
174. *
175. * @param string $pValue
176. * @return PHPExcel_DocumentProperties
177. */
178. public function setLastModifiedBy($pValue = '') {
179. $this->_lastModifiedBy = $pValue;
180. return $this;
181. }
183. /**
184. * Get Created
185. *
186. * @return datetime
187. */
188. public function getCreated() {
189. return $this->_created;
190. }
192. /**
193. * Set Created
194. *
195. * @param datetime $pValue
196. * @return PHPExcel_DocumentProperties
197. */
198. public function setCreated($pValue = null) {
199. if ( is_null($pValue)) {
200. $pValue = time();
201. } elseif ( is_string($pValue)) {
202. if ( is_numeric($pValue)) {
203. $pValue = intval($pValue);
204. } else {
205. $pValue = strtotime($pValue);
206. }
207. }
209. $this->_created = $pValue;
210. return $this;
211. }
213. /**
214. * Get Modified
215. *
216. * @return datetime
217. */
218. public function getModified() {
219. return $this->_modified;
220. }
222. /**
223. * Set Modified
224. *
225. * @param datetime $pValue
226. * @return PHPExcel_DocumentProperties
227. */
228. public function setModified($pValue = null) {
229. if ( is_null($pValue)) {
230. $pValue = time();
231. } elseif ( is_string($pValue)) {
232. if ( is_numeric($pValue)) {
233. $pValue = intval($pValue);
234. } else {
235. $pValue = strtotime($pValue);
236. }
237. }
239. $this->_modified = $pValue;
240. return $this;
241. }
243. /**
244. * Get Title
245. *
246. * @return string
247. */
248. public function getTitle() {
249. return $this->_title;
250. }
252. /**
253. * Set Title
254. *
255. * @param string $pValue
256. * @return PHPExcel_DocumentProperties
257. */
258. public function setTitle($pValue = '') {
259. $this->_title = $pValue;
260. return $this;
261. }
263. /**
264. * Get Description
265. *
266. * @return string
267. */
268. public function getDescription() {
269. return $this->_description;
270. }
272. /**
273. * Set Description
274. *
275. * @param string $pValue
276. * @return PHPExcel_DocumentProperties
277. */
278. public function setDescription($pValue = '') {
279. $this->_description = $pValue;
280. return $this;
281. }
283. /**
284. * Get Subject
285. *
286. * @return string
287. */
288. public function getSubject() {
289. return $this->_subject;
290. }
292. /**
293. * Set Subject
294. *
295. * @param string $pValue
296. * @return PHPExcel_DocumentProperties
297. */
298. public function setSubject($pValue = '') {
299. $this->_subject = $pValue;
300. return $this;
301. }
303. /**
304. * Get Keywords
305. *
306. * @return string
307. */
308. public function getKeywords() {
309. return $this->_keywords;
310. }
312. /**
313. * Set Keywords
314. *
315. * @param string $pValue
316. * @return PHPExcel_DocumentProperties
317. */
318. public function setKeywords($pValue = '') {
319. $this->_keywords = $pValue;
320. return $this;
321. }
323. /**
324. * Get Category
325. *
326. * @return string
327. */
328. public function getCategory() {
329. return $this->_category;
330. }
332. /**
333. * Set Category
334. *
335. * @param string $pValue
336. * @return PHPExcel_DocumentProperties
337. */
338. public function setCategory($pValue = '') {
339. $this->_category = $pValue;
340. return $this;
341. }
343. /**
344. * Get Company
345. *
346. * @return string
347. */
348. public function getCompany() {
349. return $this->_company;
350. }
352. /**
353. * Set Company
354. *
355. * @param string $pValue
356. * @return PHPExcel_DocumentProperties
357. */
358. public function setCompany($pValue = '') {
359. $this->_company = $pValue;
360. return $this;
361. }
363. /**
364. * Get Manager
365. *
366. * @return string
367. */
368. public function getManager() {
369. return $this->_manager;
370. }
372. /**
373. * Set Manager
374. *
375. * @param string $pValue
376. * @return PHPExcel_DocumentProperties
377. */
378. public function setManager($pValue = '') {
379. $this->_manager = $pValue;
380. return $this;
381. }
383. /**
384. * Get a List of Custom Property Names
385. *
386. * @return array of string
387. */
388. public function getCustomProperties() {
389. return array_keys($this->_customProperties);
390. }
392. /**
393. * Check if a Custom Property is defined
394. *
395. * @param string $propertyName
396. * @return boolean
397. */
398. public function isCustomPropertySet($propertyName) {
399. return isset($this->_customProperties[$propertyName]);
400. }
402. /**
403. * Get a Custom Property Value
404. *
405. * @param string $propertyName
406. * @return string
407. */
408. public function getCustomPropertyValue($propertyName) {
409. if (isset($this->_customProperties[$propertyName])) {
410. return $this->_customProperties[$propertyName]['value'];
411. }
413. }
415. /**
416. * Get a Custom Property Type
417. *
418. * @param string $propertyName
419. * @return string
420. */
421. public function getCustomPropertyType($propertyName) {
422. if (isset($this->_customProperties[$propertyName])) {
423. return $this->_customProperties[$propertyName]['type'];
424. }
426. }
428. /**
429. * Set a Custom Property
430. *
431. * @param string $propertyName
432. * @param mixed $propertyValue
433. * @param string $propertyType
434. * 'i' : Integer
435. * 'f' : Floating Point
436. * 's' : String
437. * 'd' : Date/Time
438. * 'b' : Boolean
439. * @return PHPExcel_DocumentProperties
440. */
441. public function setCustomProperty($propertyName,$propertyValue='',$propertyType=NULL) {
442. if (( is_null($propertyType)) || (! in_array($propertyType,array(self:: PROPERTY_TYPE_INTEGER,
443. self:: PROPERTY_TYPE_FLOAT,
444. self:: PROPERTY_TYPE_STRING,
445. self:: PROPERTY_TYPE_DATE,
446. self:: PROPERTY_TYPE_BOOLEAN)))) {
447. if ( is_null($propertyValue)) {
448. $propertyType = self:: PROPERTY_TYPE_STRING;
449. } elseif ( is_float($propertyValue)) {
450. $propertyType = self:: PROPERTY_TYPE_FLOAT;
451. } elseif( is_int($propertyValue)) {
452. $propertyType = self:: PROPERTY_TYPE_INTEGER;
453. } elseif ( is_bool($propertyValue)) {
454. $propertyType = self:: PROPERTY_TYPE_BOOLEAN;
455. } else {
456. $propertyType = self:: PROPERTY_TYPE_STRING;
457. }
458. }
460. $this->_customProperties[$propertyName] = array('value' => $propertyValue, 'type' => $propertyType);
461. return $this;
462. }
464. /**
465. * Implement PHP __clone to create a deep clone, not just a shallow copy.
466. */
467. public function __clone() {
468. $vars = get_object_vars($this);
469. foreach ($vars as $key => $value) {
470. if ( is_object($value)) {
471. $this->$key = clone $value;
472. } else {
473. $this->$key = $value;
474. }
475. }
476. }
478. public static function convertProperty($propertyValue,$propertyType) {
479. switch ($propertyType) {
480. case 'empty' : // Empty
481. return '';
482. break;
483. case 'null' : // Null
484. return NULL;
485. break;
486. case 'i1' : // 1-Byte Signed Integer
487. case 'i2' : // 2-Byte Signed Integer
488. case 'i4' : // 4-Byte Signed Integer
489. case 'i8' : // 8-Byte Signed Integer
490. case 'int' : // Integer
491. return (int) $propertyValue;
492. break;
493. case 'ui1' : // 1-Byte Unsigned Integer
494. case 'ui2' : // 2-Byte Unsigned Integer
495. case 'ui4' : // 4-Byte Unsigned Integer
496. case 'ui8' : // 8-Byte Unsigned Integer
497. case 'uint' : // Unsigned Integer
498. return abs((int) $propertyValue);
499. break;
500. case 'r4' : // 4-Byte Real Number
501. case 'r8' : // 8-Byte Real Number
502. case 'decimal' : // Decimal
503. return (float) $propertyValue;
504. break;
505. case 'lpstr' : // LPSTR
506. case 'lpwstr' : // LPWSTR
507. case 'bstr' : // Basic String
508. return $propertyValue;
509. break;
510. case 'date' : // Date and Time
511. case 'filetime' : // File Time
512. return strtotime($propertyValue);
513. break;
514. case 'bool' : // Boolean
515. return ($propertyValue == 'true') ? True : False;
516. break;
517. case 'cy' : // Currency
518. case 'error' : // Error Status Code
519. case 'vector' : // Vector
520. case 'array' : // Array
521. case 'blob' : // Binary Blob
522. case 'oblob' : // Binary Blob Object
523. case 'stream' : // Binary Stream
524. case 'ostream' : // Binary Stream Object
525. case 'storage' : // Binary Storage
526. case 'ostorage' : // Binary Storage Object
527. case 'vstream' : // Binary Versioned Stream
528. case 'clsid' : // Class ID
529. case 'cf' : // Clipboard Data
530. return $propertyValue;
531. break;
532. }
533. return $propertyValue;
534. }
536. public static function convertPropertyType($propertyType) {
537. switch ($propertyType) {
538. case 'i1' : // 1-Byte Signed Integer
539. case 'i2' : // 2-Byte Signed Integer
540. case 'i4' : // 4-Byte Signed Integer
541. case 'i8' : // 8-Byte Signed Integer
542. case 'int' : // Integer
543. case 'ui1' : // 1-Byte Unsigned Integer
544. case 'ui2' : // 2-Byte Unsigned Integer
545. case 'ui4' : // 4-Byte Unsigned Integer
546. case 'ui8' : // 8-Byte Unsigned Integer
547. case 'uint' : // Unsigned Integer
548. return self:: PROPERTY_TYPE_INTEGER;
549. break;
550. case 'r4' : // 4-Byte Real Number
551. case 'r8' : // 8-Byte Real Number
552. case 'decimal' : // Decimal
553. return self:: PROPERTY_TYPE_FLOAT;
554. break;
555. case 'empty' : // Empty
556. case 'null' : // Null
557. case 'lpstr' : // LPSTR
558. case 'lpwstr' : // LPWSTR
559. case 'bstr' : // Basic String
560. return self:: PROPERTY_TYPE_STRING;
561. break;
562. case 'date' : // Date and Time
563. case 'filetime' : // File Time
564. return self:: PROPERTY_TYPE_DATE;
565. break;
566. case 'bool' : // Boolean
567. return self:: PROPERTY_TYPE_BOOLEAN;
568. break;
569. case 'cy' : // Currency
570. case 'error' : // Error Status Code
571. case 'vector' : // Vector
572. case 'array' : // Array
573. case 'blob' : // Binary Blob
574. case 'oblob' : // Binary Blob Object
575. case 'stream' : // Binary Stream
576. case 'ostream' : // Binary Stream Object
577. case 'storage' : // Binary Storage
578. case 'ostorage' : // Binary Storage Object
579. case 'vstream' : // Binary Versioned Stream
580. case 'clsid' : // Class ID
581. case 'cf' : // Clipboard Data
582. return self:: PROPERTY_TYPE_UNKNOWN;
583. break;
584. }
585. return self:: PROPERTY_TYPE_UNKNOWN;
586. }
588. }

Documentation generated on Sun, 27 Feb 2011 16:30:13 -0800 by phpDocumentor 1.4.3