Created
May 7, 2015 10:17
-
-
Save aleayr/de79995554c09695cde0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace Acme\Backend\VSM; | |
use Acme\Backend\BackendService; | |
use Exception; | |
class VSMService extends BackendService { | |
private $wsdl_url = 'http://dev/address/ServiceManager.svc?wsdl'; | |
private $wsdl_user = 'user'; | |
private $wsdl_pass = 'password'; | |
private $wsdl_db = 'database'; | |
private $wsdl_session_id = NULL; | |
private $error_generic = 'Attempts to submit this form were not successful (%s). Please try again or contact the Service Centre.'; | |
public function __construct() | |
{ | |
if($_SERVER['HTTP_HOST'] == 'intranet') { | |
$this->wsdl_url = 'http://production/address/ServiceManager.svc?wsdl'; | |
$this->wsdl_user = 'username'; | |
$this->wsdl_pass = 'password'; | |
$this->wsdl_db = 'database'; | |
} | |
try | |
{ | |
$this->initialiseClient(); | |
} | |
catch (Exception $e) | |
{ | |
//failed | |
throw new Exception(sprintf($this->error_generic, $e->getMessage())); | |
} | |
} | |
public function initialiseClient() | |
{ | |
require_once('../../lib/nusoap/lib/nusoap.php'); | |
$client = new \nusoap_client($this->wsdl_url, true); | |
$client->soap_defencoding = 'UTF-8'; | |
$client->setCredentials('', '', 'ntlm'); | |
$client->setUseCurl(true); | |
$client->useHTTPPersistentConnection(); | |
$client->setCurlOption(CURLOPT_USERPWD, 'domain\user:password'); | |
$err = $client->getError(); | |
if($err) { | |
// throw error | |
throw new Exception('Could not create connection to backend.'); | |
} | |
$this->wsdl_client = $client; | |
return true; | |
} | |
public function createTicket($user, $action_description, $problem_description, $service_id, $group, $tier_type) | |
{ | |
if(empty($user->mail)) { | |
throw new Exception('Your staff account is missing an email address, without which, this form cannot be submitted. Please try again or contact the Service Centre.'); | |
} | |
// create call | |
$params = array( | |
'sLoginUserID' => $this->wsdl_user, | |
'sLoginPassword' => $this->wsdl_pass, | |
'sDatabase' => $this->wsdl_db, | |
'sActionDescription' => $action_description, | |
'sProblemDescription' => $problem_description, | |
'yPortal' => 'Y', | |
//'lImpact' => 'High', | |
'lCustomer' => strtolower($user->mail), | |
'lService' => $service_id, | |
//'lPriority' => 'Severity 3', | |
//'lUrgency' => 'Medium', | |
'lFwdGroup' => $group, | |
'lIPKStatus' => 'Service Request', | |
'lType' => $tier_type, | |
'lCallStatus' => 'Pending Approval', | |
); | |
try { | |
$result = $this->sendRequest('CallCreate', $params); | |
} | |
catch (Exception $e) { | |
//print_r($e); | |
throw new Exception(sprintf('Attempting to create call failed: %s', $e->getMessage())); | |
} | |
return $result; | |
} | |
public function updateTicket($ticket_id) | |
{ | |
// update call | |
$params = array( | |
'sID' => $this->wsdl_session_id, | |
'lEntityRef' => $ticket_id, | |
'lCallStatus' => 'In Progress', | |
); | |
$result = $this->sendRequest('CallUpdate', $params); | |
return $result; | |
} | |
private function sendRequest($name, $params) | |
{ | |
$result = $this->wsdl_client->call($name, array($params), 'http://schemas.xmlsoap.org/wsdl/soap/'); | |
if($this->wsdl_client->fault) { | |
// throw error | |
//die($this->wsdl_client->faultcode); | |
throw new Exception($this->wsdl_client->faultcode); | |
} | |
else { | |
// Check for errors | |
$err = $this->wsdl_client->getError(); | |
if ($err) { | |
// throw error | |
throw new Exception($err); | |
} | |
} | |
return $result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment