MailMerge.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Service
  17. * @subpackage LiveDocx
  18. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /** Zend_Date **/
  23. require_once 'Zend/Date.php';
  24. /** Zend_Service_LiveDocx **/
  25. require_once 'Zend/Service/LiveDocx.php';
  26. /**
  27. * @category Zend
  28. * @package Zend_Service
  29. * @subpackage LiveDocx
  30. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. */
  33. class Zend_Service_LiveDocx_MailMerge extends Zend_Service_LiveDocx
  34. {
  35. /**
  36. * URI of LiveDocx.MailMerge service
  37. */
  38. const ENDPOINT = 'https://api.livedocx.com/1.2/mailmerge.asmx?WSDL';
  39. /**
  40. * Field values
  41. *
  42. * @var array
  43. */
  44. protected $_fieldValues;
  45. /**
  46. * Block field values
  47. *
  48. * @var array
  49. */
  50. protected $_blockFieldValues;
  51. /**
  52. * Document properties of PDF file (only)
  53. *
  54. * @var array
  55. */
  56. protected $_documentProperties;
  57. /**
  58. * Constructor (LiveDocx.MailMerge SOAP Service)
  59. *
  60. * @return void
  61. * @return throws Zend_Service_LiveDocx_Exception
  62. */
  63. public function __construct($options = null)
  64. {
  65. $this->_endpoint = self::ENDPOINT;
  66. $this->_fieldValues = array();
  67. $this->_blockFieldValues = array();
  68. $this->_setDefaultDocumentProperties();
  69. parent::__construct($options);
  70. }
  71. /**
  72. * Set the filename of a LOCAL template
  73. * (i.e. a template stored locally on YOUR server)
  74. *
  75. * @param string $filename
  76. * @return Zend_Service_LiveDocx_MailMerge
  77. * @throws Zend_Service_LiveDocx_Exception
  78. */
  79. public function setLocalTemplate($filename)
  80. {
  81. $this->logIn();
  82. try {
  83. $this->getSoapClient()->SetLocalTemplate(array(
  84. 'template' => base64_encode(file_get_contents($filename)),
  85. 'format' => self::getFormat($filename),
  86. ));
  87. } catch (Exception $e) {
  88. require_once 'Zend/Service/LiveDocx/Exception.php';
  89. throw new Zend_Service_LiveDocx_Exception(
  90. 'Cannot set local template', 0, $e
  91. );
  92. }
  93. return $this;
  94. }
  95. /**
  96. * Set the filename of a REMOTE template
  97. * (i.e. a template stored remotely on the LIVEDOCX server)
  98. *
  99. * @param string $filename
  100. * @return Zend_Service_LiveDocx_MailMerge
  101. * @throws Zend_Service_LiveDocx_Exception
  102. */
  103. public function setRemoteTemplate($filename)
  104. {
  105. $this->logIn();
  106. try {
  107. $this->getSoapClient()->SetRemoteTemplate(array(
  108. 'filename' => $filename,
  109. ));
  110. } catch (Exception $e) {
  111. require_once 'Zend/Service/LiveDocx/Exception.php';
  112. throw new Zend_Service_LiveDocx_Exception(
  113. 'Cannot set remote template', 0, $e
  114. );
  115. }
  116. return $this;
  117. }
  118. /**
  119. * Set an associative or multi-associative array of keys and values pairs
  120. *
  121. * @param array $values
  122. * @return Zend_Service_LiveDocx_MailMerge
  123. * @throws Zend_Service_LiveDocx_Exception
  124. */
  125. public function setFieldValues($values)
  126. {
  127. $this->logIn();
  128. foreach ($values as $value) {
  129. if (is_array($value)) {
  130. $method = 'multiAssocArrayToArrayOfArrayOfString';
  131. } else {
  132. $method = 'assocArrayToArrayOfArrayOfString';
  133. }
  134. break;
  135. }
  136. try {
  137. $this->getSoapClient()->SetFieldValues(array(
  138. 'fieldValues' => self::$method($values),
  139. ));
  140. } catch (Exception $e) {
  141. require_once 'Zend/Service/LiveDocx/Exception.php';
  142. throw new Zend_Service_LiveDocx_Exception(
  143. 'Cannot set field values', 0, $e
  144. );
  145. }
  146. return $this;
  147. }
  148. /**
  149. * Set an array of key and value or array of values
  150. *
  151. * @param string $field
  152. * @param array|string $value
  153. *
  154. * @throws Zend_Service_LiveDocx_Exception
  155. * @return Zend_Service_LiveDocx_MailMerge
  156. */
  157. public function setFieldValue($field, $value)
  158. {
  159. $this->_fieldValues[$field] = $value;
  160. return $this;
  161. }
  162. /**
  163. * Set block field values
  164. *
  165. * @param string $blockName
  166. * @param array $blockFieldValues
  167. *
  168. * @return Zend_Service_LiveDocx_MailMerge
  169. * @throws Zend_Service_LiveDocx_Exception
  170. */
  171. public function setBlockFieldValues($blockName, $blockFieldValues)
  172. {
  173. $this->logIn();
  174. try {
  175. $this->getSoapClient()->SetBlockFieldValues(array(
  176. 'blockName' => $blockName,
  177. 'blockFieldValues' => self::multiAssocArrayToArrayOfArrayOfString($blockFieldValues)
  178. ));
  179. } catch (Exception $e) {
  180. require_once 'Zend/Service/LiveDocx/Exception.php';
  181. throw new Zend_Service_LiveDocx_Exception(
  182. 'Cannot set block field values', 0, $e
  183. );
  184. }
  185. return $this;
  186. }
  187. /**
  188. * Assign values to template fields
  189. *
  190. * @param array|string $field
  191. * @param array|string $value
  192. * @return Zend_Service_LiveDocx_MailMerge
  193. * @throws Zend_Service_LiveDocx_Exception
  194. */
  195. public function assign($field, $value = null)
  196. {
  197. try {
  198. if (is_array($field) && (null === $value)) {
  199. foreach ($field as $fieldName => $fieldValue) {
  200. $this->setFieldValue($fieldName, $fieldValue);
  201. }
  202. } elseif (is_array($value)) {
  203. $this->setBlockFieldValues($field, $value);
  204. } else {
  205. $this->setFieldValue($field, $value);
  206. }
  207. } catch (Exception $e) {
  208. require_once 'Zend/Service/LiveDocx/Exception.php';
  209. throw new Zend_Service_LiveDocx_Exception(
  210. 'Cannot assign data to template', 0, $e
  211. );
  212. }
  213. return $this;
  214. }
  215. /**
  216. * Merge assigned data with template to generate document
  217. *
  218. * @throws Zend_Service_LiveDocx_Excpetion
  219. * @return void
  220. */
  221. public function createDocument()
  222. {
  223. $this->logIn();
  224. if (count($this->_fieldValues) > 0) {
  225. $this->setFieldValues($this->_fieldValues);
  226. }
  227. $this->_fieldValues = array();
  228. $this->_blockFieldValues = array();
  229. try {
  230. $this->getSoapClient()->CreateDocument();
  231. } catch (Exception $e) {
  232. require_once 'Zend/Service/LiveDocx/Exception.php';
  233. throw new Zend_Service_LiveDocx_Exception(
  234. 'Cannot create document', 0, $e
  235. );
  236. }
  237. }
  238. /**
  239. * Retrieve document in specified format
  240. *
  241. * @param string $format
  242. *
  243. * @throws Zend_Service_LiveDocx_Exception
  244. * @return binary
  245. */
  246. public function retrieveDocument($format)
  247. {
  248. $this->logIn();
  249. $ret = null;
  250. $format = strtolower($format);
  251. try {
  252. $result = $this->getSoapClient()->RetrieveDocument(array(
  253. 'format' => $format,
  254. ));
  255. } catch (Exception $e) {
  256. require_once 'Zend/Service/LiveDocx/Exception.php';
  257. throw new Zend_Service_LiveDocx_Exception(
  258. 'Cannot retrieve document - call setLocalTemplate() or setRemoteTemplate() first', 0, $e
  259. );
  260. }
  261. $ret = base64_decode($result->RetrieveDocumentResult);
  262. if ('pdf' === $format) {
  263. require_once 'Zend/Pdf.php';
  264. $pdf = Zend_Pdf::parse($ret);
  265. $pdf->properties = $this->_getDocumentProperties();
  266. $ret = $pdf->render();
  267. }
  268. return $ret;
  269. }
  270. /**
  271. * Return WMF (aka Windows metafile) data for specified page range of created document
  272. * Return array contains WMF data (binary) - array key is page number
  273. *
  274. * @param integer $fromPage
  275. * @param integer $toPage
  276. * @return array
  277. */
  278. public function getMetafiles($fromPage, $toPage)
  279. {
  280. $this->logIn();
  281. $ret = array();
  282. $result = $this->getSoapClient()->GetMetafiles(array(
  283. 'fromPage' => (integer) $fromPage,
  284. 'toPage' => (integer) $toPage,
  285. ));
  286. if (isset($result->GetMetafilesResult->string)) {
  287. $pageCounter = (integer) $fromPage;
  288. if (is_array($result->GetMetafilesResult->string)) {
  289. foreach ($result->GetMetafilesResult->string as $string) {
  290. $ret[$pageCounter] = base64_decode($string);
  291. $pageCounter++;
  292. }
  293. } else {
  294. $ret[$pageCounter] = base64_decode($result->GetMetafilesResult->string);
  295. }
  296. }
  297. return $ret;
  298. }
  299. /**
  300. * Return WMF (aka Windows metafile) data for pages of created document
  301. * Return array contains WMF data (binary) - array key is page number
  302. *
  303. * @return array
  304. */
  305. public function getAllMetafiles()
  306. {
  307. $this->logIn();
  308. $ret = array();
  309. $result = $this->getSoapClient()->GetAllMetafiles();
  310. if (isset($result->GetAllMetafilesResult->string)) {
  311. $pageCounter = 1;
  312. if (is_array($result->GetAllMetafilesResult->string)) {
  313. foreach ($result->GetAllMetafilesResult->string as $string) {
  314. $ret[$pageCounter] = base64_decode($string);
  315. $pageCounter++;
  316. }
  317. } else {
  318. $ret[$pageCounter] = base64_decode($result->GetAllMetafilesResult->string);
  319. }
  320. }
  321. return $ret;
  322. }
  323. /**
  324. * Return graphical bitmap data for specified page range of created document
  325. * Return array contains bitmap data (binary) - array key is page number
  326. *
  327. * @param integer $fromPage
  328. * @param integer $toPage
  329. * @param integer $zoomFactor
  330. * @param string $format
  331. * @return array
  332. */
  333. public function getBitmaps($fromPage, $toPage, $zoomFactor, $format)
  334. {
  335. $this->logIn();
  336. $ret = array();
  337. $result = $this->getSoapClient()->GetBitmaps(array(
  338. 'fromPage' => (integer) $fromPage,
  339. 'toPage' => (integer) $toPage,
  340. 'zoomFactor' => (integer) $zoomFactor,
  341. 'format' => (string) $format,
  342. ));
  343. if (isset($result->GetBitmapsResult->string)) {
  344. $pageCounter = (integer) $fromPage;
  345. if (is_array($result->GetBitmapsResult->string)) {
  346. foreach ($result->GetBitmapsResult->string as $string) {
  347. $ret[$pageCounter] = base64_decode($string);
  348. $pageCounter++;
  349. }
  350. } else {
  351. $ret[$pageCounter] = base64_decode($result->GetBitmapsResult->string);
  352. }
  353. }
  354. return $ret;
  355. }
  356. /**
  357. * Return graphical bitmap data for all pages of created document
  358. * Return array contains bitmap data (binary) - array key is page number
  359. *
  360. * @param integer $zoomFactor
  361. * @param string $format
  362. * @return array
  363. */
  364. public function getAllBitmaps($zoomFactor, $format)
  365. {
  366. $this->logIn();
  367. $ret = array();
  368. $result = $this->getSoapClient()->GetAllBitmaps(array(
  369. 'zoomFactor' => (integer) $zoomFactor,
  370. 'format' => (string) $format,
  371. ));
  372. if (isset($result->GetAllBitmapsResult->string)) {
  373. $pageCounter = 1;
  374. if (is_array($result->GetAllBitmapsResult->string)) {
  375. foreach ($result->GetAllBitmapsResult->string as $string) {
  376. $ret[$pageCounter] = base64_decode($string);
  377. $pageCounter++;
  378. }
  379. } else {
  380. $ret[$pageCounter] = base64_decode($result->GetAllBitmapsResult->string);
  381. }
  382. }
  383. return $ret;
  384. }
  385. /**
  386. * Return all the fields in the template
  387. *
  388. * @return array
  389. */
  390. public function getFieldNames()
  391. {
  392. $this->logIn();
  393. $ret = array();
  394. $result = $this->getSoapClient()->GetFieldNames();
  395. if (isset($result->GetFieldNamesResult->string)) {
  396. if (is_array($result->GetFieldNamesResult->string)) {
  397. $ret = $result->GetFieldNamesResult->string;
  398. } else {
  399. $ret[] = $result->GetFieldNamesResult->string;
  400. }
  401. }
  402. return $ret;
  403. }
  404. /**
  405. * Return all the block fields in the template
  406. *
  407. * @param string $blockName
  408. * @return array
  409. */
  410. public function getBlockFieldNames($blockName)
  411. {
  412. $this->logIn();
  413. $ret = array();
  414. $result = $this->getSoapClient()->GetBlockFieldNames(array(
  415. 'blockName' => $blockName
  416. ));
  417. if (isset($result->GetBlockFieldNamesResult->string)) {
  418. if (is_array($result->GetBlockFieldNamesResult->string)) {
  419. $ret = $result->GetBlockFieldNamesResult->string;
  420. } else {
  421. $ret[] = $result->GetBlockFieldNamesResult->string;
  422. }
  423. }
  424. return $ret;
  425. }
  426. /**
  427. * Return all the block fields in the template
  428. *
  429. * @return array
  430. */
  431. public function getBlockNames()
  432. {
  433. $this->logIn();
  434. $ret = array();
  435. $result = $this->getSoapClient()->GetBlockNames();
  436. if (isset($result->GetBlockNamesResult->string)) {
  437. if (is_array($result->GetBlockNamesResult->string)) {
  438. $ret = $result->GetBlockNamesResult->string;
  439. } else {
  440. $ret[] = $result->GetBlockNamesResult->string;
  441. }
  442. }
  443. return $ret;
  444. }
  445. /**
  446. * Set the default document properties
  447. *
  448. * Valid for PDF documents only
  449. *
  450. * @return null
  451. */
  452. protected function _setDefaultDocumentProperties()
  453. {
  454. $date = new Zend_Date();
  455. $this->_documentProperties = array();
  456. $projectName = sprintf('phpLiveDocx %s', self::getVersion());
  457. $projectUrl = 'http://www.phpLiveDocx.org';
  458. $creationDate = sprintf('D:%s', $date->toString('YYYYMMddHHmmss'));
  459. // Zend_Pdf expects keys with uppercase first letter
  460. $this->_documentProperties['Creator'] = $projectName;
  461. $this->_documentProperties['Producer'] = $projectUrl;
  462. $this->_documentProperties['CreationDate'] = $creationDate;
  463. $this->_documentProperties['ModDate'] = $creationDate;
  464. }
  465. /**
  466. * Set the document properties
  467. *
  468. * Valid for PDF documents only
  469. *
  470. * $properties is an assoc array with the following format:
  471. *
  472. * {code}
  473. * $properties = array (
  474. * 'title' => '', // (string)
  475. * 'author' => '', // (string)
  476. * 'subject' => '', // (string)
  477. * 'keywords' => '', // (string)
  478. * );
  479. * {code}
  480. *
  481. * @param array $properties
  482. * @return Zend_Service_LiveDocx_MailMerge
  483. */
  484. public function setDocumentProperties($properties)
  485. {
  486. // For consistency, keys in $properties are lowercase.
  487. // Zend_Pdf expects keys with uppercase first letter
  488. $keys = array('Title', 'Author', 'Subject', 'Keywords');
  489. foreach ($keys as $key) {
  490. $lowerCaseKey = strtolower($key);
  491. if (isset($properties[$lowerCaseKey])) {
  492. $this->_documentProperties[$key] = $properties[$lowerCaseKey];
  493. }
  494. }
  495. return $this;
  496. }
  497. /**
  498. * Return currently set document properties
  499. *
  500. * @return array
  501. */
  502. protected function _getDocumentProperties()
  503. {
  504. return $this->_documentProperties;
  505. }
  506. /**
  507. * Upload a template file to LiveDocx service
  508. *
  509. * @param string $filename
  510. * @return void
  511. * @throws Zend_Service_LiveDocx_Exception
  512. */
  513. public function uploadTemplate($filename)
  514. {
  515. $this->logIn();
  516. try {
  517. $this->getSoapClient()->UploadTemplate(array(
  518. 'template' => base64_encode(file_get_contents($filename)),
  519. 'filename' => basename($filename),
  520. ));
  521. } catch (Exception $e) {
  522. require_once 'Zend/Service/LiveDocx/Exception.php';
  523. throw new Zend_Service_LiveDocx_Exception(
  524. 'Cannot upload template', 0, $e
  525. );
  526. }
  527. }
  528. /**
  529. * Download template file from LiveDocx service
  530. *
  531. * @param string $filename
  532. * @return binary
  533. * @throws Zend_Service_LiveDocx_Exception
  534. */
  535. public function downloadTemplate($filename)
  536. {
  537. $this->logIn();
  538. try {
  539. $result = $this->getSoapClient()->DownloadTemplate(array(
  540. 'filename' => basename($filename),
  541. ));
  542. } catch (Exception $e) {
  543. require_once 'Zend/Service/LiveDocx/Exception.php';
  544. throw new Zend_Service_LiveDocx_Exception(
  545. 'Cannot download template', 0, $e
  546. );
  547. }
  548. return base64_decode($result->DownloadTemplateResult);
  549. }
  550. /**
  551. * Delete a template file from LiveDocx service
  552. *
  553. * @param string $filename
  554. * @return void
  555. * @throws Zend_Service_LiveDocx_Exception
  556. */
  557. public function deleteTemplate($filename)
  558. {
  559. $this->logIn();
  560. $this->getSoapClient()->DeleteTemplate(array(
  561. 'filename' => basename($filename),
  562. ));
  563. }
  564. /**
  565. * List all templates stored on LiveDocx service
  566. *
  567. * @return array
  568. */
  569. public function listTemplates()
  570. {
  571. $this->logIn();
  572. $ret = array();
  573. $result = $this->getSoapClient()->ListTemplates();
  574. if (isset($result->ListTemplatesResult)) {
  575. $ret = $this->_backendListArrayToMultiAssocArray($result->ListTemplatesResult);
  576. }
  577. return $ret;
  578. }
  579. /**
  580. * Check whether a template file is available on LiveDocx service
  581. *
  582. * @param string $filename
  583. * @return boolean
  584. */
  585. public function templateExists($filename)
  586. {
  587. $this->logIn();
  588. $result = $this->getSoapClient()->TemplateExists(array(
  589. 'filename' => basename($filename),
  590. ));
  591. return (boolean) $result->TemplateExistsResult;
  592. }
  593. /**
  594. * Share a document - i.e. the document is available to all over the Internet
  595. *
  596. * @return string
  597. */
  598. public function shareDocument()
  599. {
  600. $this->logIn();
  601. $ret = null;
  602. $result = $this->getSoapClient()->ShareDocument();
  603. if (isset($result->ShareDocumentResult)) {
  604. $ret = (string) $result->ShareDocumentResult;
  605. }
  606. return $ret;
  607. }
  608. /**
  609. * List all shared documents stored on LiveDocx service
  610. *
  611. * @return array
  612. */
  613. public function listSharedDocuments()
  614. {
  615. $this->logIn();
  616. $ret = array();
  617. $result = $this->getSoapClient()->ListSharedDocuments();
  618. if (isset($result->ListSharedDocumentsResult)) {
  619. $ret = $this->_backendListArrayToMultiAssocArray(
  620. $result->ListSharedDocumentsResult
  621. );
  622. }
  623. return $ret;
  624. }
  625. /**
  626. * Delete a shared document from LiveDocx service
  627. *
  628. * @param string $filename
  629. * @return void
  630. */
  631. public function deleteSharedDocument($filename)
  632. {
  633. $this->logIn();
  634. $this->getSoapClient()->DeleteSharedDocument(array(
  635. 'filename' => basename($filename),
  636. ));
  637. }
  638. /*
  639. * Download a shared document from LiveDocx service
  640. *
  641. * @param string $filename
  642. * @return binary
  643. * @throws Zend_Service_LiveDocx_Exception
  644. */
  645. public function downloadSharedDocument($filename)
  646. {
  647. $this->logIn();
  648. try {
  649. $result = $this->getSoapClient()->DownloadSharedDocument(array(
  650. 'filename' => basename($filename),
  651. ));
  652. } catch (Exception $e) {
  653. require_once 'Zend/Service/LiveDocx/Exception.php';
  654. throw new Zend_Service_LiveDocx_Exception(
  655. 'Cannot download shared document', 0, $e
  656. );
  657. }
  658. return base64_decode($result->DownloadSharedDocumentResult);
  659. }
  660. /**
  661. * Check whether a shared document is available on LiveDocx service
  662. *
  663. * @param string $filename
  664. * @return boolean
  665. */
  666. public function sharedDocumentExists($filename)
  667. {
  668. $this->logIn();
  669. $ret = false;
  670. $sharedDocuments = $this->listSharedDocuments();
  671. foreach ($sharedDocuments as $shareDocument) {
  672. if (isset($shareDocument['filename'])
  673. && (basename($filename) === $shareDocument['filename'])
  674. ) {
  675. $ret = true;
  676. break;
  677. }
  678. }
  679. return $ret;
  680. }
  681. /**
  682. * Return supported template formats (lowercase)
  683. *
  684. * @return array
  685. */
  686. public function getTemplateFormats()
  687. {
  688. $this->logIn();
  689. $ret = array();
  690. $result = $this->getSoapClient()->GetTemplateFormats();
  691. if (isset($result->GetTemplateFormatsResult->string)) {
  692. $ret = $result->GetTemplateFormatsResult->string;
  693. $ret = array_map('strtolower', $ret);
  694. }
  695. return $ret;
  696. }
  697. /**
  698. * Return supported document formats (lowercase)
  699. *
  700. * @return array
  701. */
  702. public function getDocumentFormats()
  703. {
  704. $this->logIn();
  705. $ret = array();
  706. $result = $this->getSoapClient()->GetDocumentFormats();
  707. if (isset($result->GetDocumentFormatsResult->string)) {
  708. $ret = $result->GetDocumentFormatsResult->string;
  709. $ret = array_map('strtolower', $ret);
  710. }
  711. return $ret;
  712. }
  713. /*
  714. * Return supported image formats (lowercase)
  715. *
  716. * @return array
  717. */
  718. public function getImageFormats()
  719. {
  720. $this->logIn();
  721. $ret = array();
  722. $result = $this->getSoapClient()->GetImageFormats();
  723. if (isset($result->GetImageFormatsResult->string)) {
  724. $ret = $result->GetImageFormatsResult->string;
  725. $ret = array_map('strtolower', $ret);
  726. }
  727. return $ret;
  728. }
  729. /**
  730. * Return the names of all fonts that are installed on backend server
  731. *
  732. * @return array
  733. */
  734. public function getFontNames()
  735. {
  736. $this->logIn();
  737. $ret = array();
  738. $result = $this->getSoapClient()->GetFontNames();
  739. if (isset($result->GetFontNamesResult->string)) {
  740. $ret = $result->GetFontNamesResult->string;
  741. }
  742. return $ret;
  743. }
  744. /**
  745. * Convert LiveDocx service return value from list methods to consistent PHP array
  746. *
  747. * @param array $list
  748. * @return array
  749. */
  750. protected function _backendListArrayToMultiAssocArray($list)
  751. {
  752. $this->logIn();
  753. $ret = array();
  754. if (isset($list->ArrayOfString)) {
  755. foreach ($list->ArrayOfString as $a) {
  756. if (is_array($a)) { // 1 template only
  757. $o = new stdClass();
  758. $o->string = $a;
  759. } else { // 2 or more templates
  760. $o = $a;
  761. }
  762. unset($a);
  763. if (isset($o->string)) {
  764. $date1 = new Zend_Date($o->string[3], Zend_Date::RFC_1123);
  765. $date2 = new Zend_Date($o->string[1], Zend_Date::RFC_1123);
  766. $ret[] = array (
  767. 'filename' => $o->string[0],
  768. 'fileSize' => (integer) $o->string[2],
  769. 'createTime' => (integer) $date1->get(Zend_Date::TIMESTAMP),
  770. 'modifyTime' => (integer) $date2->get(Zend_Date::TIMESTAMP),
  771. );
  772. }
  773. }
  774. }
  775. return $ret;
  776. }
  777. /**
  778. * Convert assoc array to required SOAP type
  779. *
  780. * @param array $assoc
  781. *
  782. * @return array
  783. */
  784. public static function assocArrayToArrayOfArrayOfString($assoc)
  785. {
  786. $arrayKeys = array_keys($assoc);
  787. $arrayValues = array_values($assoc);
  788. return array($arrayKeys, $arrayValues);
  789. }
  790. /**
  791. * Convert multi assoc array to required SOAP type
  792. *
  793. * @param array $multi
  794. * @return array
  795. */
  796. public static function multiAssocArrayToArrayOfArrayOfString($multi)
  797. {
  798. $arrayKeys = array_keys($multi[0]);
  799. $arrayValues = array();
  800. foreach ($multi as $v) {
  801. $arrayValues[] = array_values($v);
  802. }
  803. $arrayKeys = array($arrayKeys);
  804. return array_merge($arrayKeys, $arrayValues);
  805. }
  806. }