PageRenderTime 39ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/atk4-addons/crm/lib/Model/crm/CampaignMonitor/Request/generic.php

https://github.com/mahimarathore/mahi
PHP | 82 lines | 50 code | 8 blank | 24 comment | 9 complexity | da00e915613f8e637b40d37a7c3bb10f MD5 | raw file
Possible License(s): AGPL-3.0, MPL-2.0-no-copyleft-exception
  1. <?php
  2. /* {{{ vim:ts=4:sw=4:et
  3. About: This file is part of CRM integration framework implementing XXX
  4. Documentation: http://atk4.info/doc/billing/
  5. ---------------------------------------------------------------------
  6. Agile Toolkit 4
  7. (c) 1999-2010 Agile Technologies Limited
  8. See COPYRIGHT for details
  9. ---------------------------------------------------------------------
  10. Authors:
  11. Romans
  12. ---------------------------------------------------------------------
  13. }}} */
  14. class Model_crm_CampaignMonitor_Request_generic extends AbstractModel {
  15. public $soap;
  16. public $function;
  17. public $area;
  18. public $result;
  19. function init(){
  20. parent::init();
  21. $this->soap=new SoapClient($this->owner->url,array('trace'=>true,'exceptions'=>true));
  22. $this->set('ApiKey',$this->owner->key);
  23. $this->set('ClientID',$this->owner->client);
  24. }
  25. function set($key,$val=null){
  26. if(is_array($key)){
  27. foreach($key as $a=>$b){
  28. $this->set($a,$b);
  29. }
  30. return;
  31. }
  32. if(is_null($val))unset($this->arguments[$key]);
  33. $this->arguments[$key]=$val;
  34. return $this;
  35. }
  36. function setFunction($function){
  37. $this->function=$function;
  38. return $this;
  39. }
  40. function process(){
  41. if($this->api->getConfig('crm/campaignmonitor/demo_mode',false)){
  42. return $this;
  43. }
  44. $fn=$this->function;
  45. // handle return values and throw exceptions!
  46. $this->resp=$this->soap->$fn($this->arguments);
  47. if(isset($this->resp)){
  48. $fn=$this->area.'.'.$this->function;
  49. foreach($this->resp as $key=>$val){
  50. if(substr($key,-6)=='Result')$this->result=$val;
  51. }
  52. if($this->result){
  53. if(isset($this->result->enc_value))$this->result=$this->result->enc_value;
  54. if(isset($this->result->Code) && $this->result->Code>100){
  55. // Problem
  56. throw new BaseException("Received error (".$this->result->Code."): ".$this->result->Message." from
  57. <pre>".htmlentities($this->soap->__getLastRequest()).'</pre>');
  58. }
  59. }else var_dump('No Result: ',$this->resp);
  60. }
  61. $this->hook('request-complete',array($this,$this->resp));
  62. return $this;
  63. }
  64. }