Skip to content
Snippets Groups Projects

Rm12332 Orphee Set Adh Dispo Anx

Merged Laurent requested to merge RM12332-Orphee-SetAdhDispoAnx into master
Compare and
+ 417
455
Preferences
Compare changes
Files
@@ -26,18 +26,6 @@ class Class_WebService_SIGB_Orphee_Service extends Class_WebService_SIGB_Abstrac
protected $_key;
protected $_soap_options;
protected static $SOAP_CLIENT_CLASS='Class_WebService_MappedSoapClient';
public static function newSoapClient($wsdl, $options) {
$soap_class = self::$SOAP_CLIENT_CLASS;
return new $soap_class($wsdl, $options);
}
public static function setSoapClientClass($soap_class) {
self::$SOAP_CLIENT_CLASS = $soap_class;
}
public static function getService($wsdl, $key=null) {
return new self($wsdl, $key,
@@ -54,12 +42,12 @@ class Class_WebService_SIGB_Orphee_Service extends Class_WebService_SIGB_Abstrac
$this->_wsdl = $wsdl;
$this->_key = $key;
$this->_soap_options = $soap_options;
$this->connect();
}
public function __destruct() {
$this->disconnect();
if ($this->isConnected())
$this->disconnect();
}
@@ -83,261 +71,241 @@ class Class_WebService_SIGB_Orphee_Service extends Class_WebService_SIGB_Abstrac
return $this->_search_client;
try {
$this->_search_client = self::newSoapClient($this->_wsdl, $this->_soap_options);
$this->_search_client = new Class_WebService_MappedSoapClient($this->_wsdl,
$this->_soap_options);
} catch (SoapFault $e) {
$this->_guid = null;
}
return $this->_search_client;
}
public function connect() {
/** @category testing */
public function setSearchClient($client) {
$this->_search_client = $client;
return $this;
}
public function getSessionStrategy() {
if (null === $this->_session_strategy) {
$this->_session_strategy = Class_WebService_SIGB_Orphee_SessionStrategy::newFrom($this->getSearchClient(),
$this->_key);
$this->_session_strategy->connect();
}
return $this->_session_strategy;
}
public function isConnected() {
try {
$this->getSearchClient();
$this->getSessionStrategy()->connect();
} catch (SoapFault $e) {
$this->_guid = null;
return $this->getSessionStrategy()->isConnected();
} catch(Exception $e) {
}
return $this;
return false;
}
public function getSessionStrategy() {
if (null === $this->_session_strategy)
$this->_session_strategy = Class_WebService_SIGB_Orphee_SessionStrategy::newFrom($this->_search_client, $this->_key);
return $this->_session_strategy;
}
public function isConnected() {
return $this->getSessionStrategy()->isConnected();
}
/** @codeCoverageIgnore */
protected function _dumpSoapTrace() {
var_dump($this->_search_client->__getLastRequestHeaders());
var_dump($this->_search_client->__getLastRequest());
var_dump($this->_search_client->__getLastResponseHeaders());
var_dump($this->_search_client->__getLastResponse());
}
public function getEmprunteur($user) {
return $this->willTry(
function() use ($user) {
$result = ($this->hasGetAdh()) ?
$this->_search_client->GetAdh(GetAdh::withNo($user->getLogin())):
$this->_search_client->GetInfoUserCarte(GetInfoUserCarte::withNo($user->getLogin()));
if (!$emprunteur = Class_WebService_SIGB_Orphee_GetInfoUserCarteResponseReader
::newInstance()
->getEmprunteurFromXML($result->getXml()))
return $this->newNullEmprunteur();
return $emprunteur->beValid()->setService($this);
});
}
protected function hasGetAdh() {
foreach ($this->_search_client->__getFunctions() as $function)
if (false !== strpos($function, 'GetAdh('))
return true;
return false;
}
public function newNullEmprunteur() {
return Class_WebService_SIGB_Emprunteur::newInstance()
->reservationsAddAll(array())
->empruntsAddAll(array());
}
public function getReservationsOf($emprunteur) {
return $this->willTry(
function() use ($emprunteur) {
return Class_WebService_SIGB_Orphee_GetLstRsvResponseReader::newInstance()
->getReservationsFromXML($this->getSearchClient()
->GetLstRsv(GetLstRsv::withAdh($emprunteur->getId()))
->getXml());
});
}
public function getEmpruntsOf($emprunteur) {
return $this->willTry(
function () use ($emprunteur) {
return Class_WebService_SIGB_Orphee_GetLstPretResponseReader::newInstance()
->getEmpruntsFromXML($this->getSearchClient()
->GetLstPret(GetLstPret::withAdh($emprunteur->getId()))
->getXml());
});
}
protected function withUserDo($user, $id, $serviceClosure, $errorClosure) {
try {
$emprunteur = $this->getEmprunteur($user);
} catch (Exception $e) {
return ['statut' => false, 'erreur' => $e->getMessage()];
}
try {
$result = $serviceClosure($id, $emprunteur);
} catch (SoapFault $e) {
return ['statut' => false,
'erreur' => 'Le SIGB Orphée a retourné l\'erreur suivante: '.$e->getMessage()];
}
if ($message = $errorClosure($result))
return ['statut' => false, 'erreur' => $message];
return ['statut' => true, 'erreur' => ''];
}
public function reserverExemplaire($user, $exemplaire, $code_annexe) {
$notice_id = $this->removeOrpheeNoticePrefix($exemplaire->getIdOrigine());
return $this->withUserDo(
$user, $notice_id,
function ($id, $emprunteur) {
return $this->getSearchClient()
->RsvNtcAdh(RsvNtcAdh::withNoticeUserNo($id, $emprunteur->getId()));
},
function ($result) {
$datas = simplexml_load_string($result->getXml());
return ($datas->msg->code == 1) ? false : (string)$datas->msg->libelle;
});
}
public function supprimerReservation($user, $notice_id) {
return $this->withUserDo(
$user, $notice_id,
function ($id, $emprunteur) {
return $this->getSearchClient()
->DelRsv(DelRsv::withNoticeUserNo($id, $emprunteur->getId()));
},
function ($result) {
return ($result->DelRsvResult == 1) ? false : 'La suppression a échoué';
});
}
public function prolongerPret($user, $document_id) {
return $this->withUserDo(
$user, $document_id,
function ($id, $emprunteur) {
return $this->getSearchClient()
->ProlongePret(ProlongePret::withDocumentUser($id, $emprunteur->getId()));
},
function ($result) {
$datas = simplexml_load_string($result->getXml());
return ($datas->msg->code == 1) ? false : (string)$datas->msg->libelle;
});
}
/** @codeCoverageIgnore */
protected function _dumpSoapTrace() {
var_dump($this->_search_client->__getLastRequestHeaders());
var_dump($this->_search_client->__getLastRequest());
var_dump($this->_search_client->__getLastResponseHeaders());
var_dump($this->_search_client->__getLastResponse());
}
public function getEmprunteur($user) {
return $this->willTry(
function() use ($user) {
if (!$this->isConnected())
return $this->newNullEmprunteur();
public function getExemplaire($notice_id, $code_barre){
if (!$item = Class_Exemplaire::findFirstBy(['code_barres' => $code_barre]))
return new Class_WebService_SIGB_Exemplaire(null);
$result = ($this->hasGetAdh()) ?
$this->_search_client->GetAdh(GetAdh::withNo($user->getLogin())):
$this->_search_client->GetInfoUserCarte(GetInfoUserCarte::withNo($user->getLogin()));
if (!$notice = $item->getNotice())
return new Class_WebService_SIGB_Exemplaire(null);
$tome = $notice->isPeriodique() ? (int)$notice->getTomeAlpha() : 0;
$id = $this->removeOrpheeNoticePrefix($notice_id);
if (!$emprunteur = Class_WebService_SIGB_Orphee_GetInfoUserCarteResponseReader
::newInstance()
->getEmprunteurFromXML($result->getXml()))
return $this->newNullEmprunteur();
return $emprunteur->beValid()->setService($this);
});
}
$result = $this->getSearchClient()->GetLstDmt(GetLstDmt::withNtcAndFas($id, $tome));
$xml = $result->getXml();
$notice = Class_WebService_SIGB_Orphee_GetLstDmtResponseReader::newInstance()->getNoticeFromXML($xml);
if (!isset($notice) || ($exemplaire = $notice->getExemplaireByCodeBarre($code_barre)) == null){
$exemplaire = new Class_WebService_SIGB_Exemplaire(null);
}
return $exemplaire;
protected function hasGetAdh() {
return $this->_search_client->hasFunction('GetAdh');
}
public function getNotice($id) {
// disabled - see getExemplaire
return new Class_WebService_SIGB_Notice($id);
}
public function newNullEmprunteur() {
return Class_WebService_SIGB_Emprunteur::newInstance()
->reservationsAddAll([])
->empruntsAddAll([]);
}
/** @return array */
public function getReservationsOf($emprunteur) {
return $this->willTry(
function() use ($emprunteur) {
if (!$this->isConnected())
return [];
return Class_WebService_SIGB_Orphee_GetLstRsvResponseReader::newInstance()
->getReservationsFromXML($this->getSearchClient()
->GetLstRsv(GetLstRsv::withAdh($emprunteur->getId()))
->getXml());
});
}
public function removeOrpheeNoticePrefix($id) {
return str_replace('frOr', '', $id);
}
/** @return array */
public function getEmpruntsOf($emprunteur) {
return $this->willTry(
function () use ($emprunteur) {
if (!$this->isConnected())
return [];
return Class_WebService_SIGB_Orphee_GetLstPretResponseReader::newInstance()
->getEmpruntsFromXML($this->getSearchClient()
->GetLstPret(GetLstPret::withAdh($emprunteur->getId()))
->getXml());
});
}
public function getGUID() {
return $this->_guid;
}
protected function withUserDo($user, $id, $serviceClosure, $errorClosure) {
try {
$emprunteur = $this->getEmprunteur($user);
} catch (Exception $e) {
return ['statut' => false, 'erreur' => $e->getMessage()];
}
try {
$result = $serviceClosure($id, $emprunteur);
} catch (SoapFault $e) {
return ['statut' => false,
'erreur' => 'Le SIGB Orphée a retourné l\'erreur suivante: '.$e->getMessage()];
}
public function _newOrpheeException($message) {
throw new Class_WebService_Exception('Le SIGB Orphée a retourné l\'erreur suivante: '.$message);
}
}
if ($message = $errorClosure($result))
return ['statut' => false, 'erreur' => $message];
return ['statut' => true, 'erreur' => ''];
}
public function reserverExemplaire($user, $exemplaire, $code_annexe) {
$notice_id = $this->removeOrpheeNoticePrefix($exemplaire->getIdOrigine());
$tome = $exemplaire->isPeriodique()
? $exemplaire->getTomeAlpha()
: 0;
return $this->withUserDo(
$user, $notice_id,
function ($id, $emprunteur) use ($code_annexe, $tome) {
if ($this->hasSetAdhDispoAnx())
$this->getSearchClient()
->setAdhDispoAnx(setAdhDispoAnx::with($code_annexe));
return $this->getSearchClient()
->RsvNtcAdh(RsvNtcAdh::withNoticeUserNo($id, $emprunteur->getId(), $tome));
},
function ($result) {
$datas = simplexml_load_string($result->getXml());
return ($datas->msg->code == 1) ? false : (string)$datas->msg->libelle;
});
}
protected function hasSetAdhDispoAnx() {
return $this->_search_client->hasFunction('setAdhDispoAnx');
}
public function supprimerReservation($user, $notice_id) {
return $this->withUserDo(
$user, $notice_id,
function ($id, $emprunteur) {
return $this->getSearchClient()
->DelRsv(DelRsv::withNoticeUserNo($id, $emprunteur->getId()));
},
function ($result) {
return ($result->DelRsvResult == 1) ? false : 'La suppression a échoué';
});
}
class Class_WebService_SIGB_Orphee_XMLFilter {
public static function filter($xml) {
$xml = trim($xml);
$xml = preg_replace('/<!\[CDATA\[+/', '', $xml);
$xml = preg_replace('/\]+>+/', '', $xml);
public function prolongerPret($user, $document_id) {
return $this->withUserDo(
$user, $document_id,
function ($id, $emprunteur) {
return $this->getSearchClient()
->ProlongePret(ProlongePret::withDocumentUser($id, $emprunteur->getId()));
},
function ($result) {
$datas = simplexml_load_string($result->getXml());
return ($datas->msg->code == 1) ? false : (string)$datas->msg->libelle;
});
}
return $xml;
if (substr($xml, 0, 9)== '<![CDATA[')
return substr($xml, 9, -3);
}
}
public function getExemplaire($notice_id, $code_barre){
if (!$this->isConnected()
|| (!$item = Class_Exemplaire::findFirstBy(['code_barres' => $code_barre]))
|| (!$notice = $item->getNotice()))
return new Class_WebService_SIGB_Exemplaire(null);
$tome = $notice->isPeriodique() ? (int)$notice->getTomeAlpha() : 0;
$id = $this->removeOrpheeNoticePrefix($notice_id);
$result = $this->getSearchClient()->GetLstDmt(GetLstDmt::withNtcAndFas($id, $tome));
$xml = $result->getXml();
$notice = Class_WebService_SIGB_Orphee_GetLstDmtResponseReader::newInstance()->getNoticeFromXML($xml);
class GetId {
public $str; // string
public $key; // string
}
return !isset($notice)
|| (null == ($exemplaire = $notice->getExemplaireByCodeBarre($code_barre)))
? new Class_WebService_SIGB_Exemplaire(null)
: $exemplaire;
}
class GetIdResponse {
public $GetIdResult; // string
/**
* @deprecated
* @see getExemplaire
*/
public function getNotice($id) {
return new Class_WebService_SIGB_Notice($id);
}
public static function withIdResult($id) {
$instance = new self();
$instance->GetIdResult = $id;
return $instance;
}
}
public function removeOrpheeNoticePrefix($id) {
return str_replace('frOr', '', $id);
}
class GetToken {
public $key;
public static function newWith($key) {
$instance = new self();
$instance->key = $key;
return $instance;
public function _newOrpheeException($message) {
throw new Class_WebService_Exception('Le SIGB Orphée a retourné l\'erreur suivante: '.$message);
}
}
class GetTokenResponse {
public $GetTokenResult;
class Class_WebService_SIGB_Orphee_XMLFilter {
public static function filter($xml) {
$xml = trim($xml);
$xml = preg_replace('/<!\[CDATA\[+/', '', $xml);
$xml = preg_replace('/\]+>+/', '', $xml);
return $xml;
if (substr($xml, 0, 9)== '<![CDATA[')
return substr($xml, 9, -3);
}
}
class GetLstDmt {
public $ntc; // string
public $fas; // int
public $ntc; // string
public $fas; // int
public static function withNtcAndFas($ntc, $fas) {
$instance = new self();
@@ -348,10 +316,8 @@ class GetLstDmt {
}
class GetLstDmtResponse {
public $GetLstDmtResult; // string
public $GetLstDmtResult; // string
public static function withResult($xml) {
$instance = new self();
@@ -366,10 +332,8 @@ class GetLstDmtResponse {
}
class GetInfoUserCarte {
public $cb;
public $cb;
public static function withNo($no) {
$instance = new self();
@@ -379,8 +343,6 @@ class GetInfoUserCarte {
}
class GetInfoUserCarteResponse {
public $GetInfoUserCarteResult; // String
@@ -397,7 +359,6 @@ class GetInfoUserCarteResponse {
}
class GetAdh {
public $carte;
@@ -412,7 +373,7 @@ class GetAdh {
class GetAdhResponse {
/** @var string */
public $GetAdhResult;
public $GetAdhResult;
public static function withResult($xml) {
$instance = new self();
@@ -427,14 +388,11 @@ class GetAdhResponse {
}
class GetLstPret {
public $adh; // int
public $scrit; // string
public $nb_res; // int
public $export; // short
public $adh; // int
public $scrit; // string
public $nb_res; // int
public $export; // short
public static function withAdh($adh) {
$instance = new self();
@@ -447,10 +405,8 @@ class GetLstPret {
}
class GetLstPretResponse {
public $GetLstPretResult; // string
public $GetLstPretResult; // string
public static function withResult($xml) {
$instance = new self();
@@ -465,11 +421,9 @@ class GetLstPretResponse {
}
class GetLstRsv {
public $adh; // int
public $nb_res; // int
public $adh; // int
public $nb_res; // int
public static function withAdh($adh) {
$instance = new self();
@@ -480,11 +434,8 @@ class GetLstRsv {
}
class GetLstRsvResponse {
public $GetLstRsvResult; // string
public $GetLstRsvResult; // string
public static function withResult($xml) {
$instance = new self();
@@ -495,32 +446,27 @@ class GetLstRsvResponse {
public function getXml() {
return Class_WebService_SIGB_Orphee_XMLFilter::filter($this->GetLstRsvResult);
}
}
}
class RsvNtcAdh {
public $ntc; // string
public $fas; // int
public $adh; // int
public $ntc; // string
public $fas; // int
public $adh; // int
public static function withNoticeUserNo($ntc, $adh) {
public static function withNoticeUserNo($ntc, $adh, $fas) {
$instance = new self();
$instance->ntc = $ntc;
$instance->adh = $adh;
$instance->fas = 0;
$instance->fas = $fas;
return $instance;
}
}
class RsvNtcAdhResponse {
public $RsvNtcAdhResult; // string
public $RsvNtcAdhResult; // string
public static function withResult($xml) {
$instance = new self();
@@ -528,18 +474,17 @@ class RsvNtcAdhResponse {
return $instance;
}
public function getXml() {
return Class_WebService_SIGB_Orphee_XMLFilter::filter($this->RsvNtcAdhResult);
}
}
class DelRsv {
public $adh; // int
public $ntc; // int
public $fas; // int
public $adh; // int
public $ntc; // int
public $fas; // int
public static function withNoticeUserNo($ntc, $adh) {
$instance = new self();
@@ -551,10 +496,8 @@ class DelRsv {
}
class DelRsvResponse {
public $DelRsvResult; // short
public $DelRsvResult; // short
public static function withResult($result) {
$instance = new self();
@@ -564,11 +507,9 @@ class DelRsvResponse {
}
class ProlongePret {
public $adh; // int
public $dmt; // string
public $adh; // int
public $dmt; // string
public static function withDocumentUser($dmt, $adh) {
$instance = new self();
@@ -580,10 +521,8 @@ class ProlongePret {
class ProlongePretResponse {
public $ProlongePretResult; // string
public $ProlongePretResult; // string
public static function withResult($result) {
$instance = new self();
@@ -597,14 +536,15 @@ class ProlongePretResponse {
}
class setAdhDispoAnx {
/** @var string */
public $anx;
class EndSession {
}
class EndSessionResponse {
public static function with($code) {
$instance = new self();
$instance->anx = $code;
return $instance;
}
}
?>
\ No newline at end of file