diff --git a/library/Class/CommSigb.php b/library/Class/CommSigb.php index 01bf7adcfb1cf8177c93d821e50a4c09969742f0..45e4e2f6aaaaea84b57cdc1524f481305a201317 100644 --- a/library/Class/CommSigb.php +++ b/library/Class/CommSigb.php @@ -29,7 +29,7 @@ class Class_CommSigb { const COM_MICROBIB = 9; const COM_BIBLIXNET = 10; - protected static $_instance; + private $COM_CLASSES = array(self::COM_PERGAME => 'Class_WebService_SIGB_Pergame', self::COM_OPSYS => 'Class_WebService_SIGB_Opsys', @@ -41,6 +41,8 @@ class Class_CommSigb { self::COM_MICROBIB => 'Class_WebService_SIGB_Microbib', self::COM_BIBLIXNET => 'Class_WebService_SIGB_BiblixNet'); + protected static $_instance; + private $mode_comm; // memo de modes de comm pour les bibs private $msg_erreur_comm; // Message d'erreur pour la connexion au service de communication private $_translate; @@ -197,37 +199,14 @@ class Class_CommSigb { * @return array */ public function supprimerReservation($std_user, $id_reservation) { - $user = Class_Users::getLoader()->find($std_user->ID_USER); - Class_WebService_SIGB_EmprunteurCache::newInstance()->remove($user); + $supprimer = function ($user, $sigb) use ($id_reservation) { + if ($sigb->isPergame()) + return (new Class_Systeme_PergameService($user))->supprimerReservation($id_reservation); - $mode_comm = $this->getModeComm($user->getIdSite()); - $ret = array(); - switch ($mode_comm["type"]) { - // Pergame - case self::COM_PERGAME: - $pergame = new Class_Systeme_PergameService($user); - $ret = $pergame->supprimerReservation($id_reservation); - break; + return $sigb->supprimerReservation($user, $id_reservation); + }; - // Autres - case self::COM_OPSYS: - case self::COM_VSMART: - case self::COM_KOHA: - case self::COM_CARTHAME: - case self::COM_NANOOK: - case self::COM_ORPHEE: - case self::COM_MICROBIB: - case self::COM_BIBLIXNET: - $user = Class_Users::getLoader()->find($user->ID_USER); - $sigb = $this->getSIGBComm($mode_comm); - if ($sigb == false) { - $ret['erreur'] = $this->msg_erreur_comm; - } else { - $ret = $sigb->supprimerReservation($user, $id_reservation); - } - break; - } - return $ret; + return $this->withUserAndSIGBDo($std_user, $supprimer); } @@ -237,26 +216,28 @@ class Class_CommSigb { * @return array */ public function prolongerPret($std_user, $id_pret) { + $prolonger = function($user, $sigb) use ($std_user, $id_pret) { + if ($sigb->isPergame()) + return (new Class_Systeme_PergameService($std_user))->prolongerPret($id_pret); + + return $sigb->prolongerPret($user, $id_pret); + }; + + return $this->withUserAndSIGBDo($std_user, $prolonger); + } + + + public function withUserAndSIGBDo($std_user, $closure) { $user = Class_Users::getLoader()->find($std_user->ID_USER); Class_WebService_SIGB_EmprunteurCache::newInstance()->remove($user); - $mode_comm = $this->getModeComm($user->getIdSite()); - if (!$mode_comm['type']) - return array(); - - if (false == $sigb = $this->getSIGBComm($mode_comm)) - return array('erreur' => $this->msg_erreur_comm); + if (null == $sigb = $user->getSIGBComm()) + return []; - switch ($mode_comm["type"]) - { - // Pergame - case self::COM_PERGAME: - $pergame = new Class_Systeme_PergameService($std_user); - $ret = $pergame->prolongerPret($id_pret); - return $ret; - default: - return $sigb->prolongerPret($user, $id_pret); - } + if (!$sigb->isConnected()) + return array('erreur' => $this->msg_erreur_comm); + + return $closure($user, $sigb); } @@ -279,16 +260,8 @@ class Class_CommSigb { * @return Class_WebService_SIGB_AbstractService */ private function getSIGBComm($mode_comm) { - if (!array_key_exists($mode_comm['type'], $this->COM_CLASSES)) - return null; - - $service_class = $this->COM_CLASSES[$mode_comm['type']]; - $sigb_com = call_user_func(array($service_class, 'getService'), - $mode_comm); - - if(!$sigb_com->isConnected()) - return false; - - return $sigb_com; + if ($bib = Class_IntBib::find($mode_comm['id_bib'])) + return $bib->getSIGBComm(); + return false; } } \ No newline at end of file diff --git a/library/Class/IntBib.php b/library/Class/IntBib.php index 5f1da873e3cf71429f492a5cf79b8d4fb4c9a86c..8b6df0ef7af0b38d393eb2ab3a4430e3485b8d8e 100644 --- a/library/Class/IntBib.php +++ b/library/Class/IntBib.php @@ -24,6 +24,28 @@ */ class Class_IntBib extends Storm_Model_Abstract { + const COM_PERGAME = 1; + const COM_OPSYS = 2; + const COM_VSMART = 4; + const COM_KOHA = 5; + const COM_CARTHAME = 6; + const COM_NANOOK = 7; + const COM_ORPHEE = 8; + const COM_MICROBIB = 9; + const COM_BIBLIXNET = 10; + + + + private $COM_CLASSES = array(self::COM_PERGAME => 'Class_WebService_SIGB_Pergame', + self::COM_OPSYS => 'Class_WebService_SIGB_Opsys', + self::COM_VSMART => 'Class_WebService_SIGB_VSmart', + self::COM_KOHA => 'Class_WebService_SIGB_Koha', + self::COM_CARTHAME => 'Class_WebService_SIGB_Carthame', + self::COM_NANOOK => 'Class_WebService_SIGB_Nanook', + self::COM_ORPHEE => 'Class_WebService_SIGB_Orphee', + self::COM_MICROBIB => 'Class_WebService_SIGB_Microbib', + self::COM_BIBLIXNET => 'Class_WebService_SIGB_BiblixNet'); + protected $_table_name = 'int_bib'; protected $_table_primary = 'id_bib'; @@ -52,6 +74,16 @@ class Class_IntBib extends Storm_Model_Abstract { 'type' => $this->getCommSigb()]); } + + public function getSIGBComm() { + $type_comm = $this->getCommSigb(); + if (!isset($this->COM_CLASSES[$type_comm])) + return null; + + return call_user_func([$this->COM_CLASSES[$type_comm], 'getService'], + $this->getModeComm()); + + } } ?> \ No newline at end of file diff --git a/library/Class/Users.php b/library/Class/Users.php index f726817976d646c30872cff2e1ad133a5e8c4369..b8d7ddfb7b3db621c3a794df3a1c4490e9411eee 100644 --- a/library/Class/Users.php +++ b/library/Class/Users.php @@ -178,8 +178,10 @@ class Class_Users extends Storm_Model_Abstract { protected $_belongs_to = array('bib' => array('model' => 'Class_Bib', - 'referenced_in' => 'id_site'), - 'zone' => array('through' => 'bib')); + 'referenced_in' => 'id_site'), + 'int_bib' => array('model' => 'Class_IntBib', + 'referenced_in' => 'id_site'), + 'zone' => array('through' => 'bib')); protected $_default_attribute_values = array('id_site' => 0, 'role_level' => 0, @@ -827,6 +829,13 @@ class Class_Users extends Storm_Model_Abstract { } + public function getSIGBComm() { + if (null == $int_bib = $this->getIntBib()) + return null; + return $int_bib->getSIGBComm(); + } + + public function updateSIGBOnSave() { $this->getFicheSigb(); return $this; diff --git a/library/Class/WebService/SIGB/AbstractService.php b/library/Class/WebService/SIGB/AbstractService.php index 6efae1afee4a347a0c5e48d0fec09b5008951312..1844e9dbcb17e2b96a93cf93e78bf33d22ee8852 100644 --- a/library/Class/WebService/SIGB/AbstractService.php +++ b/library/Class/WebService/SIGB/AbstractService.php @@ -87,6 +87,10 @@ abstract class Class_WebService_SIGB_AbstractService { return array('statut' => false, 'erreur' => $message); } + + public function isPergame() { + return false; + } } ?> \ No newline at end of file diff --git a/library/Class/WebService/SIGB/Pergame/Service.php b/library/Class/WebService/SIGB/Pergame/Service.php index 9e9a6a959b092680af1e78d62e9f0503f4db36f5..2d655601c898fc55c0e1181ee5c06a8d95e6e24f 100644 --- a/library/Class/WebService/SIGB/Pergame/Service.php +++ b/library/Class/WebService/SIGB/Pergame/Service.php @@ -31,6 +31,10 @@ class Class_WebService_SIGB_Pergame_Service extends Class_WebService_SIGB_Abstra return self::newInstance()->setIdBib($id_bib); } + public function isPergame() { + return true; + } + public function setIdBib($id_bib) { $this->_id_bib = $id_bib; return $this;