MailMerge.php 27 KB

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