MailMerge.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980
  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. * @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. $ret = null;
  323. $format = strtolower($format);
  324. try {
  325. $result = $this->getSoapClient()->RetrieveDocument(array(
  326. 'format' => $format,
  327. ));
  328. } catch (Exception $e) {
  329. require_once 'Zend/Service/LiveDocx/Exception.php';
  330. throw new Zend_Service_LiveDocx_Exception(
  331. 'Cannot retrieve document - call setLocalTemplate() or setRemoteTemplate() first', 0, $e
  332. );
  333. }
  334. $ret = base64_decode($result->RetrieveDocumentResult);
  335. return $ret;
  336. }
  337. /**
  338. * Return WMF (aka Windows metafile) data for specified page range of created document
  339. * Return array contains WMF data (binary) - array key is page number
  340. *
  341. * @param integer $fromPage
  342. * @param integer $toPage
  343. * @return array
  344. * @since LiveDocx 1.2
  345. */
  346. public function getMetafiles($fromPage, $toPage)
  347. {
  348. $this->logIn();
  349. $ret = array();
  350. $result = $this->getSoapClient()->GetMetafiles(array(
  351. 'fromPage' => (integer) $fromPage,
  352. 'toPage' => (integer) $toPage,
  353. ));
  354. if (isset($result->GetMetafilesResult->string)) {
  355. $pageCounter = (integer) $fromPage;
  356. if (is_array($result->GetMetafilesResult->string)) {
  357. foreach ($result->GetMetafilesResult->string as $string) {
  358. $ret[$pageCounter] = base64_decode($string);
  359. $pageCounter++;
  360. }
  361. } else {
  362. $ret[$pageCounter] = base64_decode($result->GetMetafilesResult->string);
  363. }
  364. }
  365. return $ret;
  366. }
  367. /**
  368. * Return WMF (aka Windows metafile) data for pages of created document
  369. * Return array contains WMF data (binary) - array key is page number
  370. *
  371. * @return array
  372. * @since LiveDocx 1.2
  373. */
  374. public function getAllMetafiles()
  375. {
  376. $this->logIn();
  377. $ret = array();
  378. $result = $this->getSoapClient()->GetAllMetafiles();
  379. if (isset($result->GetAllMetafilesResult->string)) {
  380. $pageCounter = 1;
  381. if (is_array($result->GetAllMetafilesResult->string)) {
  382. foreach ($result->GetAllMetafilesResult->string as $string) {
  383. $ret[$pageCounter] = base64_decode($string);
  384. $pageCounter++;
  385. }
  386. } else {
  387. $ret[$pageCounter] = base64_decode($result->GetAllMetafilesResult->string);
  388. }
  389. }
  390. return $ret;
  391. }
  392. /**
  393. * Return graphical bitmap data for specified page range of created document
  394. * Return array contains bitmap data (binary) - array key is page number
  395. *
  396. * @param integer $fromPage
  397. * @param integer $toPage
  398. * @param integer $zoomFactor
  399. * @param string $format
  400. * @return array
  401. * @since LiveDocx 1.2
  402. */
  403. public function getBitmaps($fromPage, $toPage, $zoomFactor, $format)
  404. {
  405. $this->logIn();
  406. $ret = array();
  407. $result = $this->getSoapClient()->GetBitmaps(array(
  408. 'fromPage' => (integer) $fromPage,
  409. 'toPage' => (integer) $toPage,
  410. 'zoomFactor' => (integer) $zoomFactor,
  411. 'format' => (string) $format,
  412. ));
  413. if (isset($result->GetBitmapsResult->string)) {
  414. $pageCounter = (integer) $fromPage;
  415. if (is_array($result->GetBitmapsResult->string)) {
  416. foreach ($result->GetBitmapsResult->string as $string) {
  417. $ret[$pageCounter] = base64_decode($string);
  418. $pageCounter++;
  419. }
  420. } else {
  421. $ret[$pageCounter] = base64_decode($result->GetBitmapsResult->string);
  422. }
  423. }
  424. return $ret;
  425. }
  426. /**
  427. * Return graphical bitmap data for all pages of created document
  428. * Return array contains bitmap data (binary) - array key is page number
  429. *
  430. * @param integer $zoomFactor
  431. * @param string $format
  432. * @return array
  433. * @since LiveDocx 1.2
  434. */
  435. public function getAllBitmaps($zoomFactor, $format)
  436. {
  437. $this->logIn();
  438. $ret = array();
  439. $result = $this->getSoapClient()->GetAllBitmaps(array(
  440. 'zoomFactor' => (integer) $zoomFactor,
  441. 'format' => (string) $format,
  442. ));
  443. if (isset($result->GetAllBitmapsResult->string)) {
  444. $pageCounter = 1;
  445. if (is_array($result->GetAllBitmapsResult->string)) {
  446. foreach ($result->GetAllBitmapsResult->string as $string) {
  447. $ret[$pageCounter] = base64_decode($string);
  448. $pageCounter++;
  449. }
  450. } else {
  451. $ret[$pageCounter] = base64_decode($result->GetAllBitmapsResult->string);
  452. }
  453. }
  454. return $ret;
  455. }
  456. /**
  457. * Return all the fields in the template
  458. *
  459. * @return array
  460. * @since LiveDocx 1.0
  461. */
  462. public function getFieldNames()
  463. {
  464. $this->logIn();
  465. $ret = array();
  466. $result = $this->getSoapClient()->GetFieldNames();
  467. if (isset($result->GetFieldNamesResult->string)) {
  468. if (is_array($result->GetFieldNamesResult->string)) {
  469. $ret = $result->GetFieldNamesResult->string;
  470. } else {
  471. $ret[] = $result->GetFieldNamesResult->string;
  472. }
  473. }
  474. return $ret;
  475. }
  476. /**
  477. * Return all the block fields in the template
  478. *
  479. * @param string $blockName
  480. * @return array
  481. * @since LiveDocx 1.0
  482. */
  483. public function getBlockFieldNames($blockName)
  484. {
  485. $this->logIn();
  486. $ret = array();
  487. $result = $this->getSoapClient()->GetBlockFieldNames(array(
  488. 'blockName' => $blockName
  489. ));
  490. if (isset($result->GetBlockFieldNamesResult->string)) {
  491. if (is_array($result->GetBlockFieldNamesResult->string)) {
  492. $ret = $result->GetBlockFieldNamesResult->string;
  493. } else {
  494. $ret[] = $result->GetBlockFieldNamesResult->string;
  495. }
  496. }
  497. return $ret;
  498. }
  499. /**
  500. * Return all the block fields in the template
  501. *
  502. * @return array
  503. * @since LiveDocx 1.0
  504. */
  505. public function getBlockNames()
  506. {
  507. $this->logIn();
  508. $ret = array();
  509. $result = $this->getSoapClient()->GetBlockNames();
  510. if (isset($result->GetBlockNamesResult->string)) {
  511. if (is_array($result->GetBlockNamesResult->string)) {
  512. $ret = $result->GetBlockNamesResult->string;
  513. } else {
  514. $ret[] = $result->GetBlockNamesResult->string;
  515. }
  516. }
  517. return $ret;
  518. }
  519. /**
  520. * Upload a template file to LiveDocx service
  521. *
  522. * @param string $filename
  523. * @return void
  524. * @throws Zend_Service_LiveDocx_Exception
  525. * @since LiveDocx 1.0
  526. */
  527. public function uploadTemplate($filename)
  528. {
  529. $this->logIn();
  530. try {
  531. $this->getSoapClient()->UploadTemplate(array(
  532. 'template' => base64_encode(file_get_contents($filename)),
  533. 'filename' => basename($filename),
  534. ));
  535. } catch (Exception $e) {
  536. require_once 'Zend/Service/LiveDocx/Exception.php';
  537. throw new Zend_Service_LiveDocx_Exception(
  538. 'Cannot upload template', 0, $e
  539. );
  540. }
  541. }
  542. /**
  543. * Download template file from LiveDocx service
  544. *
  545. * @param string $filename
  546. * @return binary
  547. * @throws Zend_Service_LiveDocx_Exception
  548. * @since LiveDocx 1.0
  549. */
  550. public function downloadTemplate($filename)
  551. {
  552. $this->logIn();
  553. try {
  554. $result = $this->getSoapClient()->DownloadTemplate(array(
  555. 'filename' => basename($filename),
  556. ));
  557. } catch (Exception $e) {
  558. require_once 'Zend/Service/LiveDocx/Exception.php';
  559. throw new Zend_Service_LiveDocx_Exception(
  560. 'Cannot download template', 0, $e
  561. );
  562. }
  563. return base64_decode($result->DownloadTemplateResult);
  564. }
  565. /**
  566. * Delete a template file from LiveDocx service
  567. *
  568. * @param string $filename
  569. * @return void
  570. * @throws Zend_Service_LiveDocx_Exception
  571. * @since LiveDocx 1.0
  572. */
  573. public function deleteTemplate($filename)
  574. {
  575. $this->logIn();
  576. $this->getSoapClient()->DeleteTemplate(array(
  577. 'filename' => basename($filename),
  578. ));
  579. }
  580. /**
  581. * List all templates stored on LiveDocx service
  582. *
  583. * @return array
  584. * @since LiveDocx 1.0
  585. */
  586. public function listTemplates()
  587. {
  588. $this->logIn();
  589. $ret = array();
  590. $result = $this->getSoapClient()->ListTemplates();
  591. if (isset($result->ListTemplatesResult)) {
  592. $ret = $this->_backendListArrayToMultiAssocArray($result->ListTemplatesResult);
  593. }
  594. return $ret;
  595. }
  596. /**
  597. * Check whether a template file is available on LiveDocx service
  598. *
  599. * @param string $filename
  600. * @return boolean
  601. * @since LiveDocx 1.0
  602. */
  603. public function templateExists($filename)
  604. {
  605. $this->logIn();
  606. $result = $this->getSoapClient()->TemplateExists(array(
  607. 'filename' => basename($filename),
  608. ));
  609. return (boolean) $result->TemplateExistsResult;
  610. }
  611. /**
  612. * Share a document - i.e. the document is available to all over the Internet
  613. *
  614. * @return string
  615. * @since LiveDocx 1.0
  616. */
  617. public function shareDocument()
  618. {
  619. $this->logIn();
  620. $ret = null;
  621. $result = $this->getSoapClient()->ShareDocument();
  622. if (isset($result->ShareDocumentResult)) {
  623. $ret = (string) $result->ShareDocumentResult;
  624. }
  625. return $ret;
  626. }
  627. /**
  628. * List all shared documents stored on LiveDocx service
  629. *
  630. * @return array
  631. * @since LiveDocx 1.0
  632. */
  633. public function listSharedDocuments()
  634. {
  635. $this->logIn();
  636. $ret = array();
  637. $result = $this->getSoapClient()->ListSharedDocuments();
  638. if (isset($result->ListSharedDocumentsResult)) {
  639. $ret = $this->_backendListArrayToMultiAssocArray(
  640. $result->ListSharedDocumentsResult
  641. );
  642. }
  643. return $ret;
  644. }
  645. /**
  646. * Delete a shared document from LiveDocx service
  647. *
  648. * @param string $filename
  649. * @return void
  650. * @since LiveDocx 1.0
  651. */
  652. public function deleteSharedDocument($filename)
  653. {
  654. $this->logIn();
  655. $this->getSoapClient()->DeleteSharedDocument(array(
  656. 'filename' => basename($filename),
  657. ));
  658. }
  659. /*
  660. * Download a shared document from LiveDocx service
  661. *
  662. * @param string $filename
  663. * @return binary
  664. * @throws Zend_Service_LiveDocx_Exception
  665. * @since LiveDocx 1.0
  666. */
  667. public function downloadSharedDocument($filename)
  668. {
  669. $this->logIn();
  670. try {
  671. $result = $this->getSoapClient()->DownloadSharedDocument(array(
  672. 'filename' => basename($filename),
  673. ));
  674. } catch (Exception $e) {
  675. require_once 'Zend/Service/LiveDocx/Exception.php';
  676. throw new Zend_Service_LiveDocx_Exception(
  677. 'Cannot download shared document', 0, $e
  678. );
  679. }
  680. return base64_decode($result->DownloadSharedDocumentResult);
  681. }
  682. /**
  683. * Check whether a shared document is available on LiveDocx service
  684. *
  685. * @param string $filename
  686. * @return boolean
  687. * @since LiveDocx 1.0
  688. */
  689. public function sharedDocumentExists($filename)
  690. {
  691. $this->logIn();
  692. $ret = false;
  693. $sharedDocuments = $this->listSharedDocuments();
  694. foreach ($sharedDocuments as $shareDocument) {
  695. if (isset($shareDocument['filename'])
  696. && (basename($filename) === $shareDocument['filename'])
  697. ) {
  698. $ret = true;
  699. break;
  700. }
  701. }
  702. return $ret;
  703. }
  704. /**
  705. * Return supported template formats (lowercase)
  706. *
  707. * @return array
  708. * @since LiveDocx 1.0
  709. */
  710. public function getTemplateFormats()
  711. {
  712. $this->logIn();
  713. $ret = array();
  714. $result = $this->getSoapClient()->GetTemplateFormats();
  715. if (isset($result->GetTemplateFormatsResult->string)) {
  716. $ret = $result->GetTemplateFormatsResult->string;
  717. $ret = array_map('strtolower', $ret);
  718. }
  719. return $ret;
  720. }
  721. /**
  722. * Return supported document formats (lowercase)
  723. *
  724. * @return array
  725. * @since LiveDocx 1.1
  726. */
  727. public function getDocumentFormats()
  728. {
  729. $this->logIn();
  730. $ret = array();
  731. $result = $this->getSoapClient()->GetDocumentFormats();
  732. if (isset($result->GetDocumentFormatsResult->string)) {
  733. $ret = $result->GetDocumentFormatsResult->string;
  734. $ret = array_map('strtolower', $ret);
  735. }
  736. return $ret;
  737. }
  738. /*
  739. * Return supported image formats (lowercase)
  740. *
  741. * @return array
  742. * @since LiveDocx 1.2
  743. */
  744. public function getImageFormats()
  745. {
  746. $this->logIn();
  747. $ret = array();
  748. $result = $this->getSoapClient()->GetImageFormats();
  749. if (isset($result->GetImageFormatsResult->string)) {
  750. $ret = $result->GetImageFormatsResult->string;
  751. $ret = array_map('strtolower', $ret);
  752. }
  753. return $ret;
  754. }
  755. /**
  756. * Return the names of all fonts that are installed on backend server
  757. *
  758. * @return array
  759. * @since LiveDocx 1.2
  760. */
  761. public function getFontNames()
  762. {
  763. $this->logIn();
  764. $ret = array();
  765. $result = $this->getSoapClient()->GetFontNames();
  766. if (isset($result->GetFontNamesResult->string)) {
  767. $ret = $result->GetFontNamesResult->string;
  768. }
  769. return $ret;
  770. }
  771. /**
  772. * Return supported document access options
  773. *
  774. * @return array
  775. * @since LiveDocx 1.2 Premium
  776. */
  777. public function getDocumentAccessOptions()
  778. {
  779. $this->logIn();
  780. $ret = array();
  781. $result = $this->getSoapClient()->GetDocumentAccessOptions();
  782. if (isset($result->GetDocumentAccessOptionsResult->string)) {
  783. $ret = $result->GetDocumentAccessOptionsResult->string;
  784. }
  785. return $ret;
  786. }
  787. /**
  788. * Convert LiveDocx service return value from list methods to consistent PHP array
  789. *
  790. * @param array $list
  791. * @return array
  792. * @since LiveDocx 1.0
  793. */
  794. protected function _backendListArrayToMultiAssocArray($list)
  795. {
  796. $this->logIn();
  797. $ret = array();
  798. if (isset($list->ArrayOfString)) {
  799. foreach ($list->ArrayOfString as $a) {
  800. if (is_array($a)) { // 1 template only
  801. $o = new stdClass();
  802. $o->string = $a;
  803. } else { // 2 or more templates
  804. $o = $a;
  805. }
  806. unset($a);
  807. if (isset($o->string)) {
  808. $date1 = new Zend_Date($o->string[3], Zend_Date::RFC_1123);
  809. $date2 = new Zend_Date($o->string[1], Zend_Date::RFC_1123);
  810. $ret[] = array (
  811. 'filename' => $o->string[0],
  812. 'fileSize' => (integer) $o->string[2],
  813. 'createTime' => (integer) $date1->get(Zend_Date::TIMESTAMP),
  814. 'modifyTime' => (integer) $date2->get(Zend_Date::TIMESTAMP),
  815. );
  816. }
  817. }
  818. }
  819. return $ret;
  820. }
  821. /**
  822. * Convert assoc array to required SOAP type
  823. *
  824. * @param array $assoc
  825. *
  826. * @return array
  827. * @since LiveDocx 1.0
  828. */
  829. public static function assocArrayToArrayOfArrayOfString($assoc)
  830. {
  831. $arrayKeys = array_keys($assoc);
  832. $arrayValues = array_values($assoc);
  833. return array($arrayKeys, $arrayValues);
  834. }
  835. /**
  836. * Convert multi assoc array to required SOAP type
  837. *
  838. * @param array $multi
  839. * @return array
  840. * @since LiveDocx 1.0
  841. */
  842. public static function multiAssocArrayToArrayOfArrayOfString($multi)
  843. {
  844. $arrayKeys = array_keys($multi[0]);
  845. $arrayValues = array();
  846. foreach ($multi as $v) {
  847. $arrayValues[] = array_values($v);
  848. }
  849. $arrayKeys = array($arrayKeys);
  850. return array_merge($arrayKeys, $arrayValues);
  851. }
  852. }