initial commit
[namibia] / module / Valuation / src / Valuation / Controller / XmlRpcController.php
1 <?php
2 namespace Valuation\Controller;
3
4
5
6
7 class XmlRpcController extends \Zend\Mvc\Controller\AbstractActionController
8 {
9
10         /**
11          * @var \Zend\Session\Container
12          */
13         protected $session;
14         /**
15          * @var array
16          */
17         protected $request;
18         /**
19          * @var array
20          */
21         protected $response;
22         /**
23          * @var \Zend\ServiceManager\ServiceManager
24          */
25         protected $sm;
26
27         protected $em;
28         /**
29          * @var boolean
30          */
31         protected $authenticated = false;
32         /**
33          * @var \User\Service\Authentication
34          */
35         protected $authDetails;
36
37
38         public function xmlRpcServerAction()
39         {
40                 ini_set('memory_limit','512M');
41                 \Utility\Registry::setServiceManager($this->serviceLocator);
42                 \Utility\Registry::addDynamicConfig(
43                                 \Utility\Cache::fetchEntity(
44                                                 'Config\Entity\Config', 1, \Utility\Registry::getEntityManager(), 600
45                                 )
46                 );
47                 $server = new \Zend\XmlRpc\Server();
48                 $server->setClass('Valuation\Service\XmlRpc');
49                 echo $server->handle();
50                 $response = $this->getResponse();
51                 $response->setStatusCode(200);
52                 return $response;
53         }
54
55         public function callbackAction()
56         {
57                 if (IS_LIVE_ENV)
58                 {
59                         return;
60                 }
61                 ini_set('memory_limit','512M');
62                 \Utility\Registry::setServiceManager($this->serviceLocator);
63                 \Utility\Registry::addDynamicConfig(
64                                 \Utility\Cache::fetchEntity(
65                                                 'Config\Entity\Config', 1, \Utility\Registry::getEntityManager(), 600
66                                 )
67                 );
68                 try
69                 {
70                         $server = new \Zend\XmlRpc\Server();
71                         $server->setClass('Valuation\Service\XmlRpcCallback');
72                         echo $server->handle();
73                         $response = $this->getResponse();
74                         $response->setStatusCode(200);
75                 } catch (\Exception $e)
76                 {
77                         error_log("$e");
78                 }
79                 return $response;
80         }
81
82         public function xmlRpcClientAction()
83         {
84                 if (IS_LIVE_ENV)
85                 {
86                         return;
87                 }
88                 ini_set('memory_limit','512M');
89                 try {
90                         $url = IS_DEV_ENV
91                                 ? 'http://bid4cars.local/xmlrpc/1.0'
92                                 : 'http://bid4cars.nirph.com/xmlrpc/1.0';
93                         $client = new \Zend\XmlRpc\Client($url);
94                         //$client = new \Zend\XmlRpc\Client($url . '/callback');
95                         $arg1 = '4afb4a290f971186654f18dd6a13a7d7';
96                         $arg2 = 'Kia123';
97                         $authToken = $client->call('Authenticate', array($arg1, $arg2));
98                         /* $arg1 = 'b@imperial.com';
99                         $arg2 = array('freakin' => 'moo');
100                         var_dump($client->call('SentToSales', array($arg1, $arg2))); */
101                         //$authToken = '80f6de496cac332ab704a52bd427bab4';
102                         $email = 'a@b.com';
103                         $valuation = array(
104                                         'ItemId'                                        => '123qweasdzxc!QAZ',
105                                         'CustomerName'                          => 'Qwerty i10',
106                                         'CustomerSurname'                       => 'Poiuytre',
107                                         'CustomerMobile'                        => '27112223333',
108                                         'Km'                                            => 456,
109                                         'VehicleYearId'                         => 41,
110                                         'VehicleTypeId'                         => 6085,
111                                         'VehicleFuelTypeId'             => 2,
112                                         'VehicleTransmissionTypeId' => 2,
113                                         'RegistrationNumber'            => 'SomeRegNr',
114                                         'VehiclePhoto1URL'                      => 'http://bid4cars.nirph.com/img/bin/235785.jpg',
115                                         'VehiclePhoto2URL'                      => 'http://bid4cars.nirph.com/img/bin/235786.jpg',
116                                         'Damages'                                       => array(
117                                                         array('VehicleComponentId' => 1, 'Amount' => 2000),
118                                                         array('VehicleComponentId' => 3, 'Amount' => 2500)
119                                         ),
120                                         'Accessories'                           => array(
121                                                         array('VehicleAccessoryId' => 2),
122                                                         array('VehicleAccessoryId' => 3),
123                                                         array('VehicleAccessoryId' => 4)
124                                         )
125                         );
126                         echo '<pre>';
127                         var_dump($client->call('CreateValuation', array($authToken, $email, $valuation)));
128                         echo '</pre>';
129                 } catch (\Zend\XmlRpc\Client\Exception\HttpException $e) {
130                         echo  $e->getCode() . ":" . $e->getMessage();
131                 }
132
133                 // Disabling view
134                 $response = $this->getResponse();
135                 $response->setStatusCode(200);
136                 return $response;
137         }
138
139         public function triggerSentToSalesAction()
140         {
141                 \Utility\Registry::setServiceManager($this->serviceLocator);
142                 \Utility\Registry::addDynamicConfig(
143                                 \Utility\Cache::fetchEntity(
144                                                 'Config\Entity\Config', 1, \Utility\Registry::getEntityManager(), 600
145                                 )
146                 );
147                 $service = new \Valuation\Service\XmlRpcCallback();
148                 $valuationId = $this->getRequest()->getParam('valuationId');
149                 $service->triggerSentToSales($valuationId);
150                 return "\n";
151         }
152
153         public function retryCallbacksAction()
154         {
155                 \Utility\Registry::setServiceManager($this->serviceLocator);
156                 \Utility\Registry::addDynamicConfig(
157                                 \Utility\Cache::fetchEntity(
158                                                 'Config\Entity\Config', 1, \Utility\Registry::getEntityManager(), 600
159                                 )
160                 );
161                 $service = new \Valuation\Service\XmlRpcCallback();
162                 $service->retryCallbacks();
163                 return "\n";
164         }
165
166 }