PageRenderTime 102ms CodeModel.GetById 40ms app.highlight 4ms RepoModel.GetById 56ms app.codeStats 1ms

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