13 * to license@zend.com so we can send you a copy immediately. |
13 * to license@zend.com so we can send you a copy immediately. |
14 * |
14 * |
15 * @category Zend |
15 * @category Zend |
16 * @package Zend_Service |
16 * @package Zend_Service |
17 * @subpackage LiveDocx |
17 * @subpackage LiveDocx |
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
18 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
20 * @version $Id: MailMerge.php 23022 2010-10-05 15:30:55Z jonathan_maron $ |
20 * @version $Id: MailMerge.php 24593 2012-01-05 20:35:02Z matthew $ |
21 */ |
21 */ |
22 |
22 |
23 /** Zend_Date **/ |
23 /** Zend_Date **/ |
24 require_once 'Zend/Date.php'; |
24 require_once 'Zend/Date.php'; |
25 |
25 |
28 |
28 |
29 /** |
29 /** |
30 * @category Zend |
30 * @category Zend |
31 * @package Zend_Service |
31 * @package Zend_Service |
32 * @subpackage LiveDocx |
32 * @subpackage LiveDocx |
33 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
33 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
34 * @license http://framework.zend.com/license/new-bsd New BSD License |
34 * @license http://framework.zend.com/license/new-bsd New BSD License |
35 * @since LiveDocx 1.0 |
35 * @since LiveDocx 1.0 |
36 */ |
36 */ |
37 class Zend_Service_LiveDocx_MailMerge extends Zend_Service_LiveDocx |
37 class Zend_Service_LiveDocx_MailMerge extends Zend_Service_LiveDocx |
38 { |
38 { |
39 /** |
39 /** |
40 * URI of LiveDocx.MailMerge WSDL |
40 * URI of LiveDocx.MailMerge WSDL |
41 * @since LiveDocx 1.0 |
41 * @since LiveDocx 1.0 |
42 */ |
42 */ |
43 //const WSDL = 'https://api.livedocx.com/1.2/mailmerge.asmx?WSDL'; |
43 //const WSDL = 'https://api.livedocx.com/1.2/mailmerge.asmx?WSDL'; |
44 const WSDL = 'https://api.livedocx.com/2.0/mailmerge.asmx?WSDL'; |
44 const WSDL = 'https://api.livedocx.com/2.0/mailmerge.asmx?WSDL'; |
45 |
45 |
46 /** |
46 /** |
145 * @since LiveDocx 1.0 |
145 * @since LiveDocx 1.0 |
146 */ |
146 */ |
147 public function setFieldValues($values) |
147 public function setFieldValues($values) |
148 { |
148 { |
149 $this->logIn(); |
149 $this->logIn(); |
150 |
150 |
151 foreach ($values as $value) { |
151 foreach ($values as $value) { |
152 if (is_array($value)) { |
152 if (is_array($value)) { |
153 $method = 'multiAssocArrayToArrayOfArrayOfString'; |
153 $method = 'multiAssocArrayToArrayOfArrayOfString'; |
154 } else { |
154 } else { |
155 $method = 'assocArrayToArrayOfArrayOfString'; |
155 $method = 'assocArrayToArrayOfArrayOfString'; |
156 } |
156 } |
157 break; |
157 break; |
158 } |
158 } |
159 |
159 |
160 try { |
160 try { |
161 $this->getSoapClient()->SetFieldValues(array( |
161 $this->getSoapClient()->SetFieldValues(array( |
162 'fieldValues' => self::$method($values), |
162 'fieldValues' => self::$method($values), |
163 )); |
163 )); |
164 } catch (Exception $e) { |
164 } catch (Exception $e) { |
248 return $this; |
248 return $this; |
249 } |
249 } |
250 |
250 |
251 /** |
251 /** |
252 * Set a password to open to document |
252 * Set a password to open to document |
253 * |
253 * |
254 * This method can only be used for PDF documents |
254 * This method can only be used for PDF documents |
255 * |
255 * |
256 * @param string $password |
256 * @param string $password |
257 * @return Zend_Service_LiveDocx_MailMerge |
257 * @return Zend_Service_LiveDocx_MailMerge |
258 * @throws Zend_Service_LiveDocx_Exception |
258 * @throws Zend_Service_LiveDocx_Exception |
259 * @since LiveDocx 1.2 Premium |
259 * @since LiveDocx 1.2 Premium |
260 */ |
260 */ |
261 public function setDocumentPassword($password) |
261 public function setDocumentPassword($password) |
262 { |
262 { |
263 $this->logIn(); |
263 $this->logIn(); |
264 |
264 |
265 try { |
265 try { |
266 $this->getSoapClient()->SetDocumentPassword(array( |
266 $this->getSoapClient()->SetDocumentPassword(array( |
267 'password' => $password |
267 'password' => $password |
268 )); |
268 )); |
269 } catch (Exception $e) { |
269 } catch (Exception $e) { |
270 require_once 'Zend/Service/LiveDocx/Exception.php'; |
270 require_once 'Zend/Service/LiveDocx/Exception.php'; |
271 throw new Zend_Service_LiveDocx_Exception( |
271 throw new Zend_Service_LiveDocx_Exception( |
272 'Cannot set document password. This method can be used on PDF files only.', 0, $e |
272 'Cannot set document password. This method can be used on PDF files only.', 0, $e |
273 ); |
273 ); |
274 } |
274 } |
275 |
275 |
276 return $this; |
276 return $this; |
277 } |
277 } |
278 |
278 |
279 /** |
279 /** |
280 * Set a master password for document and determine which security features |
280 * Set a master password for document and determine which security features |
281 * are accessible without using the master password. |
281 * are accessible without using the master password. |
282 * |
282 * |
283 * As default, nothing is allowed. To allow a security setting, |
283 * As default, nothing is allowed. To allow a security setting, |
284 * explicatively set it using one of he DOCUMENT_ACCESS_PERMISSION_* class |
284 * explicatively set it using one of he DOCUMENT_ACCESS_PERMISSION_* class |
285 * constants. |
285 * constants. |
286 * |
286 * |
287 * {code} |
287 * {code} |
288 * $phpLiveDocx->setDocumentAccessPermissions( |
288 * $phpLiveDocx->setDocumentAccessPermissions( |
289 * array ( |
289 * array ( |
290 * Zend_Service_LiveDocx_MailMerge::DOCUMENT_ACCESS_PERMISSION_ALLOW_PRINTING_HIGH_LEVEL, |
290 * Zend_Service_LiveDocx_MailMerge::DOCUMENT_ACCESS_PERMISSION_ALLOW_PRINTING_HIGH_LEVEL, |
291 * Zend_Service_LiveDocx_MailMerge::DOCUMENT_ACCESS_PERMISSION_ALLOW_EXTRACT_CONTENTS |
291 * Zend_Service_LiveDocx_MailMerge::DOCUMENT_ACCESS_PERMISSION_ALLOW_EXTRACT_CONTENTS |
292 * ), |
292 * ), |
293 * 'myDocumentAccessPassword' |
293 * 'myDocumentAccessPassword' |
294 * ); |
294 * ); |
295 * {code} |
295 * {code} |
296 * |
296 * |
297 * This method can only be used for PDF documents |
297 * This method can only be used for PDF documents |
298 * |
298 * |
299 * @param array $permissions |
299 * @param array $permissions |
300 * @param string $password |
300 * @param string $password |
301 * @return Zend_Service_LiveDocx_MailMerge |
301 * @return Zend_Service_LiveDocx_MailMerge |
302 * @throws Zend_Service_LiveDocx_Exception |
302 * @throws Zend_Service_LiveDocx_Exception |
303 * @since LiveDocx 1.2 Premium |
303 * @since LiveDocx 1.2 Premium |
304 */ |
304 */ |
305 public function setDocumentAccessPermissions($permissions, $password) |
305 public function setDocumentAccessPermissions($permissions, $password) |
306 { |
306 { |
307 $this->logIn(); |
307 $this->logIn(); |
308 |
308 |
309 try { |
309 try { |
310 $this->getSoapClient()->SetDocumentAccessPermissions(array( |
310 $this->getSoapClient()->SetDocumentAccessPermissions(array( |
311 'permissions' => $permissions, |
311 'permissions' => $permissions, |
312 'password' => $password |
312 'password' => $password |
313 )); |
313 )); |
315 require_once 'Zend/Service/LiveDocx/Exception.php'; |
315 require_once 'Zend/Service/LiveDocx/Exception.php'; |
316 throw new Zend_Service_LiveDocx_Exception( |
316 throw new Zend_Service_LiveDocx_Exception( |
317 'Cannot set document access permissions', 0, $e |
317 'Cannot set document access permissions', 0, $e |
318 ); |
318 ); |
319 } |
319 } |
320 |
320 |
321 return $this; |
321 return $this; |
322 } |
322 } |
323 |
323 |
324 /** |
324 /** |
325 * Merge assigned data with template to generate document |
325 * Merge assigned data with template to generate document |
326 * |
326 * |
327 * @throws Zend_Service_LiveDocx_Excpetion |
327 * @throws Zend_Service_LiveDocx_Excpetion |
328 * @return void |
328 * @return void |
329 * @since LiveDocx 1.0 |
329 * @since LiveDocx 1.0 |
330 */ |
330 */ |
331 public function createDocument() |
331 public function createDocument() |
332 { |
332 { |
333 $this->logIn(); |
333 $this->logIn(); |
334 |
334 |
335 if (count($this->_fieldValues) > 0) { |
335 if (count($this->_fieldValues) > 0) { |
336 $this->setFieldValues($this->_fieldValues); |
336 $this->setFieldValues($this->_fieldValues); |
337 } |
337 } |
338 |
338 |
339 $this->_fieldValues = array(); |
339 $this->_fieldValues = array(); |
437 $ret[$pageCounter] = base64_decode($result->GetAllMetafilesResult->string); |
437 $ret[$pageCounter] = base64_decode($result->GetAllMetafilesResult->string); |
438 } |
438 } |
439 } |
439 } |
440 |
440 |
441 return $ret; |
441 return $ret; |
442 } |
442 } |
443 |
443 |
444 /** |
444 /** |
445 * Return graphical bitmap data for specified page range of created document |
445 * Return graphical bitmap data for specified page range of created document |
446 * Return array contains bitmap data (binary) - array key is page number |
446 * Return array contains bitmap data (binary) - array key is page number |
447 * |
447 * |
448 * @param integer $fromPage |
448 * @param integer $fromPage |
449 * @param integer $toPage |
449 * @param integer $toPage |
450 * @param integer $zoomFactor |
450 * @param integer $zoomFactor |
451 * @param string $format |
451 * @param string $format |
452 * @return array |
452 * @return array |
453 * @since LiveDocx 1.2 |
453 * @since LiveDocx 1.2 |
454 */ |
454 */ |
455 public function getBitmaps($fromPage, $toPage, $zoomFactor, $format) |
455 public function getBitmaps($fromPage, $toPage, $zoomFactor, $format) |
456 { |
456 { |
457 $this->logIn(); |
457 $this->logIn(); |
458 |
458 |
459 $ret = array(); |
459 $ret = array(); |
460 |
460 |
461 $result = $this->getSoapClient()->GetBitmaps(array( |
461 $result = $this->getSoapClient()->GetBitmaps(array( |
462 'fromPage' => (integer) $fromPage, |
462 'fromPage' => (integer) $fromPage, |
463 'toPage' => (integer) $toPage, |
463 'toPage' => (integer) $toPage, |
464 'zoomFactor' => (integer) $zoomFactor, |
464 'zoomFactor' => (integer) $zoomFactor, |
465 'format' => (string) $format, |
465 'format' => (string) $format, |
475 } else { |
475 } else { |
476 $ret[$pageCounter] = base64_decode($result->GetBitmapsResult->string); |
476 $ret[$pageCounter] = base64_decode($result->GetBitmapsResult->string); |
477 } |
477 } |
478 } |
478 } |
479 |
479 |
480 return $ret; |
480 return $ret; |
481 } |
481 } |
482 |
482 |
483 /** |
483 /** |
484 * Return graphical bitmap data for all pages of created document |
484 * Return graphical bitmap data for all pages of created document |
485 * Return array contains bitmap data (binary) - array key is page number |
485 * Return array contains bitmap data (binary) - array key is page number |
486 * |
486 * |
487 * @param integer $zoomFactor |
487 * @param integer $zoomFactor |
488 * @param string $format |
488 * @param string $format |
489 * @return array |
489 * @return array |
490 * @since LiveDocx 1.2 |
490 * @since LiveDocx 1.2 |
491 */ |
491 */ |
492 public function getAllBitmaps($zoomFactor, $format) |
492 public function getAllBitmaps($zoomFactor, $format) |
493 { |
493 { |
494 $this->logIn(); |
494 $this->logIn(); |
495 |
495 |
496 $ret = array(); |
496 $ret = array(); |
497 $result = $this->getSoapClient()->GetAllBitmaps(array( |
497 $result = $this->getSoapClient()->GetAllBitmaps(array( |
498 'zoomFactor' => (integer) $zoomFactor, |
498 'zoomFactor' => (integer) $zoomFactor, |
499 'format' => (string) $format, |
499 'format' => (string) $format, |
500 )); |
500 )); |
649 * @since LiveDocx 1.0 |
649 * @since LiveDocx 1.0 |
650 */ |
650 */ |
651 public function deleteTemplate($filename) |
651 public function deleteTemplate($filename) |
652 { |
652 { |
653 $this->logIn(); |
653 $this->logIn(); |
654 |
654 |
655 $this->getSoapClient()->DeleteTemplate(array( |
655 $this->getSoapClient()->DeleteTemplate(array( |
656 'filename' => basename($filename), |
656 'filename' => basename($filename), |
657 )); |
657 )); |
658 } |
658 } |
659 |
659 |
660 /** |
660 /** |
661 * List all templates stored on LiveDocx service |
661 * List all templates stored on LiveDocx service |
662 * |
662 * |
663 * @return array |
663 * @return array |
664 * @since LiveDocx 1.0 |
664 * @since LiveDocx 1.0 |
665 */ |
665 */ |
666 public function listTemplates() |
666 public function listTemplates() |
667 { |
667 { |
668 $this->logIn(); |
668 $this->logIn(); |
669 |
669 |
670 $ret = array(); |
670 $ret = array(); |
671 $result = $this->getSoapClient()->ListTemplates(); |
671 $result = $this->getSoapClient()->ListTemplates(); |
672 |
672 |
673 if (isset($result->ListTemplatesResult)) { |
673 if (isset($result->ListTemplatesResult)) { |
674 $ret = $this->_backendListArrayToMultiAssocArray($result->ListTemplatesResult); |
674 $ret = $this->_backendListArrayToMultiAssocArray($result->ListTemplatesResult); |
832 * @since LiveDocx 1.1 |
832 * @since LiveDocx 1.1 |
833 */ |
833 */ |
834 public function getDocumentFormats() |
834 public function getDocumentFormats() |
835 { |
835 { |
836 $this->logIn(); |
836 $this->logIn(); |
837 |
837 |
838 $ret = array(); |
838 $ret = array(); |
839 $result = $this->getSoapClient()->GetDocumentFormats(); |
839 $result = $this->getSoapClient()->GetDocumentFormats(); |
840 |
840 |
841 if (isset($result->GetDocumentFormatsResult->string)) { |
841 if (isset($result->GetDocumentFormatsResult->string)) { |
842 $ret = $result->GetDocumentFormatsResult->string; |
842 $ret = $result->GetDocumentFormatsResult->string; |
843 $ret = array_map('strtolower', $ret); |
843 $ret = array_map('strtolower', $ret); |
844 } |
844 } |
845 |
845 |
846 return $ret; |
846 return $ret; |
847 } |
847 } |
848 |
848 |
849 /** |
849 /** |
850 * Return the names of all fonts that are installed on backend server |
850 * Return the names of all fonts that are installed on backend server |
851 * |
851 * |
852 * @return array |
852 * @return array |
853 * @since LiveDocx 1.2 |
853 * @since LiveDocx 1.2 |
854 */ |
854 */ |
855 public function getFontNames() |
855 public function getFontNames() |
856 { |
856 { |
857 $this->logIn(); |
857 $this->logIn(); |
858 |
858 |
859 $ret = array(); |
859 $ret = array(); |
860 $result = $this->getSoapClient()->GetFontNames(); |
860 $result = $this->getSoapClient()->GetFontNames(); |
861 |
861 |
862 if (isset($result->GetFontNamesResult->string)) { |
862 if (isset($result->GetFontNamesResult->string)) { |
863 $ret = $result->GetFontNamesResult->string; |
863 $ret = $result->GetFontNamesResult->string; |
864 } |
864 } |
865 |
865 |
866 return $ret; |
866 return $ret; |
867 } |
867 } |
868 |
868 |
869 /** |
869 /** |
870 * Return supported document access options |
870 * Return supported document access options |
871 * |
871 * |
872 * @return array |
872 * @return array |
873 * @since LiveDocx 1.2 Premium |
873 * @since LiveDocx 1.2 Premium |
874 */ |
874 */ |
875 public function getDocumentAccessOptions() |
875 public function getDocumentAccessOptions() |
876 { |
876 { |
877 $this->logIn(); |
877 $this->logIn(); |
878 |
878 |
879 $ret = array(); |
879 $ret = array(); |
880 $result = $this->getSoapClient()->GetDocumentAccessOptions(); |
880 $result = $this->getSoapClient()->GetDocumentAccessOptions(); |
881 |
881 |
882 if (isset($result->GetDocumentAccessOptionsResult->string)) { |
882 if (isset($result->GetDocumentAccessOptionsResult->string)) { |
883 $ret = $result->GetDocumentAccessOptionsResult->string; |
883 $ret = $result->GetDocumentAccessOptionsResult->string; |
945 . "It has been replaced by %s::%s() (drop in replacement)", |
945 . "It has been replaced by %s::%s() (drop in replacement)", |
946 __CLASS__, __FUNCTION__, __CLASS__, $replacement); |
946 __CLASS__, __FUNCTION__, __CLASS__, $replacement); |
947 |
947 |
948 trigger_error($errorMessage, E_USER_NOTICE); |
948 trigger_error($errorMessage, E_USER_NOTICE); |
949 */ |
949 */ |
950 |
950 |
951 return $this->$replacement(); |
951 return $this->$replacement(); |
952 } |
952 } |
953 |
953 |
954 /** |
954 /** |
955 * Upload an image file to LiveDocx service |
955 * Upload an image file to LiveDocx service |
1060 /** |
1060 /** |
1061 * Convert LiveDocx service return value from list methods to consistent PHP array |
1061 * Convert LiveDocx service return value from list methods to consistent PHP array |
1062 * |
1062 * |
1063 * @param array $list |
1063 * @param array $list |
1064 * @return array |
1064 * @return array |
1065 * @since LiveDocx 1.0 |
1065 * @since LiveDocx 1.0 |
1066 */ |
1066 */ |
1067 protected function _backendListArrayToMultiAssocArray($list) |
1067 protected function _backendListArrayToMultiAssocArray($list) |
1068 { |
1068 { |
1069 $this->logIn(); |
1069 $this->logIn(); |
1070 |
1070 |
1071 $ret = array(); |
1071 $ret = array(); |
1072 if (isset($list->ArrayOfString)) { |
1072 if (isset($list->ArrayOfString)) { |
1073 foreach ($list->ArrayOfString as $a) { |
1073 foreach ($list->ArrayOfString as $a) { |
1074 if (is_array($a)) { // 1 template only |
1074 if (is_array($a)) { // 1 template only |
1075 $o = new stdClass(); |
1075 $o = new stdClass(); |