diff --git a/VERSIONS_HOTLINE/92524 b/VERSIONS_HOTLINE/92524 new file mode 100644 index 0000000000000000000000000000000000000000..ee32b454ad8b34bf9ac8203800e5936e85e05c1b --- /dev/null +++ b/VERSIONS_HOTLINE/92524 @@ -0,0 +1 @@ + - ticket #92524 : SIGB PMB : Correction des requêtes de disponibilité et de réservation des exemplaires de périodiques \ No newline at end of file diff --git a/cosmogramme/php/fonctions/objets_saisie.php b/cosmogramme/php/fonctions/objets_saisie.php index bf55c80338cdadd95d8deb579efc9a6610374695..ec0985d0990bfbe674185d9a5bc4a091da6afb0c 100644 --- a/cosmogramme/php/fonctions/objets_saisie.php +++ b/cosmogramme/php/fonctions/objets_saisie.php @@ -108,6 +108,11 @@ function getBlocsParams($id_bib, $type, $valeurs) { if (in_array($clef, [COM_PMB, COM_VSMART, COM_MICROBIB, COM_BIBLIXNET, COM_WATERBEAR])) $champs_params[0] = ['url_serveur']; + if (COM_PMB == $clef) + $champs_params[0][] = ['exp_bulletin_is_exp_notice' => function($id, $valeur) { + return getOuiNon($id, $valeur); + }]; + if (in_array($clef, [COM_CARTHAME])) $champs_params[0] = ['url_serveur', 'key','sigb_field_name']; diff --git a/library/Class/WebService/SIGB/PMB.php b/library/Class/WebService/SIGB/PMB.php index 885a74d9b9c12c323146d944ddb7e015af421f51..b86338875c7a131242e60dd5ab31c62295f238b7 100644 --- a/library/Class/WebService/SIGB/PMB.php +++ b/library/Class/WebService/SIGB/PMB.php @@ -21,19 +21,25 @@ class Class_WebService_SIGB_PMB { - protected static $service; + protected static $services = []; public static function getService($params) { - if (!isset(self::$service)) { - $instance = new self(); - self::$service = Class_WebService_SIGB_PMB_Service::getService($params['url_serveur']); - } - return self::$service; + $key = md5(serialize($params)); + if (isset(static::$services[$key])) + return static::$services[$key]; + + $service = Class_WebService_SIGB_PMB_Service::getService($params['url_serveur']); + + if (isset($params['exp_bulletin_is_exp_notice']) + && '1' == $params['exp_bulletin_is_exp_notice']) + $service->bePeriodicIdWithoutBull(); + + return static::$services[$key] = $service; } - public static function setService($service) { - self::$service = $service; + public static function resetServices() { + static::$services = []; } } \ No newline at end of file diff --git a/library/Class/WebService/SIGB/PMB/Service.php b/library/Class/WebService/SIGB/PMB/Service.php index 97633ca6f5ddff1585a6955d11f37bfc0765b784..5589c87502d19bd13a1840f9ab1792be0996c637 100644 --- a/library/Class/WebService/SIGB/PMB/Service.php +++ b/library/Class/WebService/SIGB/PMB/Service.php @@ -30,6 +30,7 @@ class Class_Webservice_SIGB_PMB_Service extends Class_WebService_SIGB_AbstractSe protected $_json_web_client, $_pmb_url, + $_periodic_id_without_bull = false, $_user; @@ -63,6 +64,12 @@ class Class_Webservice_SIGB_PMB_Service extends Class_WebService_SIGB_AbstractSe } + public function bePeriodicIdWithoutBull() { + $this->_periodic_id_without_bull = true; + return $this; + } + + public function providesAuthentication() { return true; } @@ -84,20 +91,27 @@ class Class_Webservice_SIGB_PMB_Service extends Class_WebService_SIGB_AbstractSe public function reserverExemplaire($user, $exemplaire, $code_annexe) { $session_token = $this->openSessionForUser($user); - $json = $this->httpPost('pmbesOPACEmpr_add_resa', [$session_token, - $exemplaire->getIdOrigine()]); + $json = $this->httpPost('pmbesOPACEmpr_add_resa', + [$session_token, $this->_sanitizeRecordId($exemplaire->getIdOrigine())]); $result = (array) $this->_getJsonData($json, 'result'); if (!$result) return $this->_error($this->_('Réservation impossible : le service de réservation PMB via webservice est indisponible')); if(isset($result['error'])) - return $this->_error($this->_('Réservation impossible : Vous avez déjà réservé cette exemplaire')); + return $this->_error($this->_('Réservation impossible : Vous avez déjà réservé cet exemplaire')); return $this->_success(); } + protected function _sanitizeRecordId($id) { + return $this->_periodic_id_without_bull + ? preg_replace('/^(.*)-bull$/', '$1', $id) + : $id; + } + + public function supprimerReservation($user, $reservation_id) { $session_token = $this->openSessionForUser($user); $json = $this->httpPost('pmbesOPACEmpr_delete_resa', [$session_token, @@ -164,9 +178,11 @@ class Class_Webservice_SIGB_PMB_Service extends Class_WebService_SIGB_AbstractSe } - public function getExemplaire($notice_id, $code_barre){ - $json = $this->httpPost('pmbesItems_fetch_notice_items', [$notice_id]); + public function getExemplaire($notice_id, $code_barre) { + $json = $this->httpPost('pmbesItems_fetch_notice_items', + [$this->_sanitizeRecordId($notice_id)]); $items = $this->_getItemsFromJson($json); + return $this->_getItemByBarCode($items, $code_barre); } diff --git a/tests/application/modules/opac/controllers/NoticeAjaxControllerPMBTest.php b/tests/application/modules/opac/controllers/NoticeAjaxControllerPMBTest.php index 8c79f97eb5a45675e21ae3057f4c39c97eb211f8..3de06bd92aecf5a2873574bc966b69728d2172c6 100644 --- a/tests/application/modules/opac/controllers/NoticeAjaxControllerPMBTest.php +++ b/tests/application/modules/opac/controllers/NoticeAjaxControllerPMBTest.php @@ -48,10 +48,12 @@ class NoticeAjaxControllerPMBRecordTest extends AbstractControllerTestCase { $config['exemplaires']['grouper'] = '1'; Class_Profil::getCurrentProfil()->setCfgNotice($config); - $this->fixture('Class_IntBib', - ['id' => 31, - 'libelle' => 'PMB library', - 'comm_sigb' => Class_IntBib::COM_PMB]); + $comm_params = ['url_serveur' => 'http://mon-pmb.net/ws/connector_out.php?source_id=2']; + $int_bib = $this->fixture('Class_IntBib', + ['id' => 31, + 'libelle' => 'PMB library', + 'comm_sigb' => Class_IntBib::COM_PMB, + 'comm_params' => $comm_params]); $this->fixture('Class_Bib', ['id' => 3, @@ -78,7 +80,7 @@ class NoticeAjaxControllerPMBRecordTest extends AbstractControllerTestCase { ->answers('') ->beStrict(); - $this->_service = Class_WebService_SIGB_PMB::getService(['url_serveur' => 'http://mon-pmb.net/ws/connector_out.php?source_id=2']); + $this->_service = Class_WebService_SIGB_PMB::getService($int_bib->getModeComm()); $this->_service->setJsonWebClient($this->http_client); $this->dispatch('/opac/noticeajax/exemplaires/id_notice/2', true); @@ -86,7 +88,7 @@ class NoticeAjaxControllerPMBRecordTest extends AbstractControllerTestCase { public function tearDown() { - Class_WebService_SIGB_PMB::setService(null); + Class_WebService_SIGB_PMB::resetServices(); parent::tearDown(); } diff --git a/tests/library/Class/WebService/SIGB/PMBTest.php b/tests/library/Class/WebService/SIGB/PMBTest.php index 7c7f28ff07efdcd84f01370b0173b7c1bcf14599..041c69f515ea1706e9f93e7aea62db322e8c902d 100644 --- a/tests/library/Class/WebService/SIGB/PMBTest.php +++ b/tests/library/Class/WebService/SIGB/PMBTest.php @@ -67,20 +67,21 @@ abstract class PMBTestCase extends ModelTestCase { ->beStrict(); - $this->_service = Class_WebService_SIGB_PMB::getService(['url_serveur' => 'http://cedre.proxience.net/ws/connector_out.php?source_id=2']); + $this->_service = Class_WebService_SIGB_PMB::getService(['url_serveur' => 'http://cedre.proxience.net/ws/connector_out.php?source_id=2', + 'exp_bulletin_is_exp_notice' => '1']); $this->_service->setJsonWebClient($this->_json_web_client); } public function tearDown() { - Class_WebService_SIGB_PMB::setService(null); + Class_WebService_SIGB_PMB::resetServices(); parent::tearDown(); } } -class PMBServiceTest extends PMBTestCase { +class PMBSimpleServiceTest extends PMBTestCase { protected $_paul, $_le_kiosque, @@ -233,6 +234,59 @@ class PMBServiceTest extends PMBTestCase { +class PMBPeriodicServiceTest extends ModelTestCase { + public function tearDown() { + Class_WebService_SIGB_PMB::resetServices(); + parent::tearDown(); + } + + + /** @test */ + public function periodicItemShouldQueryWithoutDashBull() { + $service = Class_WebService_SIGB_PMB::getService(['url_serveur' => 'http://cedre.proxience.net/ws/connector_out.php?source_id=2', + 'exp_bulletin_is_exp_notice' => '1']); + $service->setJsonWebClient($client = $this->mock()->whenCalled('httpPost')->answers('')); + $service->getExemplaire('18390-bull', '000159'); + $this->assertEquals(['18390'], $client->getAttributesForLastCallOn('httpPost')[1]); + } + + + /** @test */ + public function periodicItemHoldShouldQueryWithoutDashBull() { + $service = Class_WebService_SIGB_PMB::getService(['url_serveur' => 'http://cedre.proxience.net/ws/connector_out.php?source_id=2', + 'exp_bulletin_is_exp_notice' => '1']); + $service->setJsonWebClient($client = $this->mock()->whenCalled('httpPost')->answers('')); + $service->reserverExemplaire((new Class_Entity), + (new Class_Entity)->setIdOrigine('18390-bull'), + ''); + $this->assertEquals([null, '18390'], $client->getAttributesForLastCallOn('httpPost')[1]); + } + + + /** @test */ + public function periodicItemShouldQueryWithDashBull() { + $service = Class_WebService_SIGB_PMB::getService(['url_serveur' => 'http://cedre.proxience.net/ws/connector_out.php?source_id=2']); + $service->setJsonWebClient($client = $this->mock()->whenCalled('httpPost')->answers('')); + $service->getExemplaire('18390-bull', '000159'); + $this->assertEquals(['18390-bull'], $client->getAttributesForLastCallOn('httpPost')[1]); + } + + + /** @test */ + public function periodicItemHoldShouldQueryWithDashBull() { + $service = Class_WebService_SIGB_PMB::getService(['url_serveur' => 'http://cedre.proxience.net/ws/connector_out.php?source_id=2']); + $service->setJsonWebClient($client = $this->mock()->whenCalled('httpPost')->answers('')); + $service->reserverExemplaire((new Class_Entity), + (new Class_Entity)->setIdOrigine('18390-bull'), + ''); + $this->assertEquals([null, '18390-bull'], $client->getAttributesForLastCallOn('httpPost')[1]); + } + +} + + + + /** @see http://forge.afi-sa.fr/issues/102712 */ class PMBNotPreviouslyConnectedTest extends PMBTestCase { protected $_patron;