PageRenderTime 25ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Document/Properties.php

https://github.com/tmccormi/openemr
PHP | 629 lines | 312 code | 77 blank | 240 comment | 17 complexity | 91777177dd55f94b74249d0cac1875f3 MD5 | raw file
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheet\Document;
  3. class Properties
  4. {
  5. /** constants */
  6. const PROPERTY_TYPE_BOOLEAN = 'b';
  7. const PROPERTY_TYPE_INTEGER = 'i';
  8. const PROPERTY_TYPE_FLOAT = 'f';
  9. const PROPERTY_TYPE_DATE = 'd';
  10. const PROPERTY_TYPE_STRING = 's';
  11. const PROPERTY_TYPE_UNKNOWN = 'u';
  12. /**
  13. * Creator.
  14. *
  15. * @var string
  16. */
  17. private $creator = 'Unknown Creator';
  18. /**
  19. * LastModifiedBy.
  20. *
  21. * @var string
  22. */
  23. private $lastModifiedBy;
  24. /**
  25. * Created.
  26. *
  27. * @var int
  28. */
  29. private $created;
  30. /**
  31. * Modified.
  32. *
  33. * @var int
  34. */
  35. private $modified;
  36. /**
  37. * Title.
  38. *
  39. * @var string
  40. */
  41. private $title = 'Untitled Spreadsheet';
  42. /**
  43. * Description.
  44. *
  45. * @var string
  46. */
  47. private $description = '';
  48. /**
  49. * Subject.
  50. *
  51. * @var string
  52. */
  53. private $subject = '';
  54. /**
  55. * Keywords.
  56. *
  57. * @var string
  58. */
  59. private $keywords = '';
  60. /**
  61. * Category.
  62. *
  63. * @var string
  64. */
  65. private $category = '';
  66. /**
  67. * Manager.
  68. *
  69. * @var string
  70. */
  71. private $manager = '';
  72. /**
  73. * Company.
  74. *
  75. * @var string
  76. */
  77. private $company = 'Microsoft Corporation';
  78. /**
  79. * Custom Properties.
  80. *
  81. * @var string
  82. */
  83. private $customProperties = [];
  84. /**
  85. * Create a new Document Properties instance.
  86. */
  87. public function __construct()
  88. {
  89. // Initialise values
  90. $this->lastModifiedBy = $this->creator;
  91. $this->created = time();
  92. $this->modified = time();
  93. }
  94. /**
  95. * Get Creator.
  96. *
  97. * @return string
  98. */
  99. public function getCreator()
  100. {
  101. return $this->creator;
  102. }
  103. /**
  104. * Set Creator.
  105. *
  106. * @param string $creator
  107. *
  108. * @return Properties
  109. */
  110. public function setCreator($creator)
  111. {
  112. $this->creator = $creator;
  113. return $this;
  114. }
  115. /**
  116. * Get Last Modified By.
  117. *
  118. * @return string
  119. */
  120. public function getLastModifiedBy()
  121. {
  122. return $this->lastModifiedBy;
  123. }
  124. /**
  125. * Set Last Modified By.
  126. *
  127. * @param string $pValue
  128. *
  129. * @return Properties
  130. */
  131. public function setLastModifiedBy($pValue)
  132. {
  133. $this->lastModifiedBy = $pValue;
  134. return $this;
  135. }
  136. /**
  137. * Get Created.
  138. *
  139. * @return int
  140. */
  141. public function getCreated()
  142. {
  143. return $this->created;
  144. }
  145. /**
  146. * Set Created.
  147. *
  148. * @param int|string $time
  149. *
  150. * @return Properties
  151. */
  152. public function setCreated($time)
  153. {
  154. if ($time === null) {
  155. $time = time();
  156. } elseif (is_string($time)) {
  157. if (is_numeric($time)) {
  158. $time = (int) $time;
  159. } else {
  160. $time = strtotime($time);
  161. }
  162. }
  163. $this->created = $time;
  164. return $this;
  165. }
  166. /**
  167. * Get Modified.
  168. *
  169. * @return int
  170. */
  171. public function getModified()
  172. {
  173. return $this->modified;
  174. }
  175. /**
  176. * Set Modified.
  177. *
  178. * @param int|string $time
  179. *
  180. * @return Properties
  181. */
  182. public function setModified($time)
  183. {
  184. if ($time === null) {
  185. $time = time();
  186. } elseif (is_string($time)) {
  187. if (is_numeric($time)) {
  188. $time = (int) $time;
  189. } else {
  190. $time = strtotime($time);
  191. }
  192. }
  193. $this->modified = $time;
  194. return $this;
  195. }
  196. /**
  197. * Get Title.
  198. *
  199. * @return string
  200. */
  201. public function getTitle()
  202. {
  203. return $this->title;
  204. }
  205. /**
  206. * Set Title.
  207. *
  208. * @param string $title
  209. *
  210. * @return Properties
  211. */
  212. public function setTitle($title)
  213. {
  214. $this->title = $title;
  215. return $this;
  216. }
  217. /**
  218. * Get Description.
  219. *
  220. * @return string
  221. */
  222. public function getDescription()
  223. {
  224. return $this->description;
  225. }
  226. /**
  227. * Set Description.
  228. *
  229. * @param string $description
  230. *
  231. * @return Properties
  232. */
  233. public function setDescription($description)
  234. {
  235. $this->description = $description;
  236. return $this;
  237. }
  238. /**
  239. * Get Subject.
  240. *
  241. * @return string
  242. */
  243. public function getSubject()
  244. {
  245. return $this->subject;
  246. }
  247. /**
  248. * Set Subject.
  249. *
  250. * @param string $subject
  251. *
  252. * @return Properties
  253. */
  254. public function setSubject($subject)
  255. {
  256. $this->subject = $subject;
  257. return $this;
  258. }
  259. /**
  260. * Get Keywords.
  261. *
  262. * @return string
  263. */
  264. public function getKeywords()
  265. {
  266. return $this->keywords;
  267. }
  268. /**
  269. * Set Keywords.
  270. *
  271. * @param string $keywords
  272. *
  273. * @return Properties
  274. */
  275. public function setKeywords($keywords)
  276. {
  277. $this->keywords = $keywords;
  278. return $this;
  279. }
  280. /**
  281. * Get Category.
  282. *
  283. * @return string
  284. */
  285. public function getCategory()
  286. {
  287. return $this->category;
  288. }
  289. /**
  290. * Set Category.
  291. *
  292. * @param string $category
  293. *
  294. * @return Properties
  295. */
  296. public function setCategory($category)
  297. {
  298. $this->category = $category;
  299. return $this;
  300. }
  301. /**
  302. * Get Company.
  303. *
  304. * @return string
  305. */
  306. public function getCompany()
  307. {
  308. return $this->company;
  309. }
  310. /**
  311. * Set Company.
  312. *
  313. * @param string $company
  314. *
  315. * @return Properties
  316. */
  317. public function setCompany($company)
  318. {
  319. $this->company = $company;
  320. return $this;
  321. }
  322. /**
  323. * Get Manager.
  324. *
  325. * @return string
  326. */
  327. public function getManager()
  328. {
  329. return $this->manager;
  330. }
  331. /**
  332. * Set Manager.
  333. *
  334. * @param string $manager
  335. *
  336. * @return Properties
  337. */
  338. public function setManager($manager)
  339. {
  340. $this->manager = $manager;
  341. return $this;
  342. }
  343. /**
  344. * Get a List of Custom Property Names.
  345. *
  346. * @return array of string
  347. */
  348. public function getCustomProperties()
  349. {
  350. return array_keys($this->customProperties);
  351. }
  352. /**
  353. * Check if a Custom Property is defined.
  354. *
  355. * @param string $propertyName
  356. *
  357. * @return bool
  358. */
  359. public function isCustomPropertySet($propertyName)
  360. {
  361. return isset($this->customProperties[$propertyName]);
  362. }
  363. /**
  364. * Get a Custom Property Value.
  365. *
  366. * @param string $propertyName
  367. *
  368. * @return string
  369. */
  370. public function getCustomPropertyValue($propertyName)
  371. {
  372. if (isset($this->customProperties[$propertyName])) {
  373. return $this->customProperties[$propertyName]['value'];
  374. }
  375. }
  376. /**
  377. * Get a Custom Property Type.
  378. *
  379. * @param string $propertyName
  380. *
  381. * @return string
  382. */
  383. public function getCustomPropertyType($propertyName)
  384. {
  385. if (isset($this->customProperties[$propertyName])) {
  386. return $this->customProperties[$propertyName]['type'];
  387. }
  388. }
  389. /**
  390. * Set a Custom Property.
  391. *
  392. * @param string $propertyName
  393. * @param mixed $propertyValue
  394. * @param string $propertyType
  395. * 'i' : Integer
  396. * 'f' : Floating Point
  397. * 's' : String
  398. * 'd' : Date/Time
  399. * 'b' : Boolean
  400. *
  401. * @return Properties
  402. */
  403. public function setCustomProperty($propertyName, $propertyValue = '', $propertyType = null)
  404. {
  405. if (($propertyType === null) || (!in_array($propertyType, [self::PROPERTY_TYPE_INTEGER,
  406. self::PROPERTY_TYPE_FLOAT,
  407. self::PROPERTY_TYPE_STRING,
  408. self::PROPERTY_TYPE_DATE,
  409. self::PROPERTY_TYPE_BOOLEAN, ]))) {
  410. if ($propertyValue === null) {
  411. $propertyType = self::PROPERTY_TYPE_STRING;
  412. } elseif (is_float($propertyValue)) {
  413. $propertyType = self::PROPERTY_TYPE_FLOAT;
  414. } elseif (is_int($propertyValue)) {
  415. $propertyType = self::PROPERTY_TYPE_INTEGER;
  416. } elseif (is_bool($propertyValue)) {
  417. $propertyType = self::PROPERTY_TYPE_BOOLEAN;
  418. } else {
  419. $propertyType = self::PROPERTY_TYPE_STRING;
  420. }
  421. }
  422. $this->customProperties[$propertyName] = [
  423. 'value' => $propertyValue,
  424. 'type' => $propertyType,
  425. ];
  426. return $this;
  427. }
  428. /**
  429. * Implement PHP __clone to create a deep clone, not just a shallow copy.
  430. */
  431. public function __clone()
  432. {
  433. $vars = get_object_vars($this);
  434. foreach ($vars as $key => $value) {
  435. if (is_object($value)) {
  436. $this->$key = clone $value;
  437. } else {
  438. $this->$key = $value;
  439. }
  440. }
  441. }
  442. public static function convertProperty($propertyValue, $propertyType)
  443. {
  444. switch ($propertyType) {
  445. case 'empty': // Empty
  446. return '';
  447. break;
  448. case 'null': // Null
  449. return null;
  450. break;
  451. case 'i1': // 1-Byte Signed Integer
  452. case 'i2': // 2-Byte Signed Integer
  453. case 'i4': // 4-Byte Signed Integer
  454. case 'i8': // 8-Byte Signed Integer
  455. case 'int': // Integer
  456. return (int) $propertyValue;
  457. break;
  458. case 'ui1': // 1-Byte Unsigned Integer
  459. case 'ui2': // 2-Byte Unsigned Integer
  460. case 'ui4': // 4-Byte Unsigned Integer
  461. case 'ui8': // 8-Byte Unsigned Integer
  462. case 'uint': // Unsigned Integer
  463. return abs((int) $propertyValue);
  464. break;
  465. case 'r4': // 4-Byte Real Number
  466. case 'r8': // 8-Byte Real Number
  467. case 'decimal': // Decimal
  468. return (float) $propertyValue;
  469. break;
  470. case 'lpstr': // LPSTR
  471. case 'lpwstr': // LPWSTR
  472. case 'bstr': // Basic String
  473. return $propertyValue;
  474. break;
  475. case 'date': // Date and Time
  476. case 'filetime': // File Time
  477. return strtotime($propertyValue);
  478. break;
  479. case 'bool': // Boolean
  480. return ($propertyValue == 'true') ? true : false;
  481. break;
  482. case 'cy': // Currency
  483. case 'error': // Error Status Code
  484. case 'vector': // Vector
  485. case 'array': // Array
  486. case 'blob': // Binary Blob
  487. case 'oblob': // Binary Blob Object
  488. case 'stream': // Binary Stream
  489. case 'ostream': // Binary Stream Object
  490. case 'storage': // Binary Storage
  491. case 'ostorage': // Binary Storage Object
  492. case 'vstream': // Binary Versioned Stream
  493. case 'clsid': // Class ID
  494. case 'cf': // Clipboard Data
  495. return $propertyValue;
  496. break;
  497. }
  498. return $propertyValue;
  499. }
  500. public static function convertPropertyType($propertyType)
  501. {
  502. switch ($propertyType) {
  503. case 'i1': // 1-Byte Signed Integer
  504. case 'i2': // 2-Byte Signed Integer
  505. case 'i4': // 4-Byte Signed Integer
  506. case 'i8': // 8-Byte Signed Integer
  507. case 'int': // Integer
  508. case 'ui1': // 1-Byte Unsigned Integer
  509. case 'ui2': // 2-Byte Unsigned Integer
  510. case 'ui4': // 4-Byte Unsigned Integer
  511. case 'ui8': // 8-Byte Unsigned Integer
  512. case 'uint': // Unsigned Integer
  513. return self::PROPERTY_TYPE_INTEGER;
  514. break;
  515. case 'r4': // 4-Byte Real Number
  516. case 'r8': // 8-Byte Real Number
  517. case 'decimal': // Decimal
  518. return self::PROPERTY_TYPE_FLOAT;
  519. break;
  520. case 'empty': // Empty
  521. case 'null': // Null
  522. case 'lpstr': // LPSTR
  523. case 'lpwstr': // LPWSTR
  524. case 'bstr': // Basic String
  525. return self::PROPERTY_TYPE_STRING;
  526. break;
  527. case 'date': // Date and Time
  528. case 'filetime': // File Time
  529. return self::PROPERTY_TYPE_DATE;
  530. break;
  531. case 'bool': // Boolean
  532. return self::PROPERTY_TYPE_BOOLEAN;
  533. break;
  534. case 'cy': // Currency
  535. case 'error': // Error Status Code
  536. case 'vector': // Vector
  537. case 'array': // Array
  538. case 'blob': // Binary Blob
  539. case 'oblob': // Binary Blob Object
  540. case 'stream': // Binary Stream
  541. case 'ostream': // Binary Stream Object
  542. case 'storage': // Binary Storage
  543. case 'ostorage': // Binary Storage Object
  544. case 'vstream': // Binary Versioned Stream
  545. case 'clsid': // Class ID
  546. case 'cf': // Clipboard Data
  547. return self::PROPERTY_TYPE_UNKNOWN;
  548. break;
  549. }
  550. return self::PROPERTY_TYPE_UNKNOWN;
  551. }
  552. }