Commit c7314a07 authored by Patrick Barroca's avatar Patrick Barroca 😁
Browse files

Merge branch 'pairing-pcoly-pbarroca' into 'hotline'

hotline #92524 : pmb fix periodic item hols and availability queries

See merge request !3382
parents 78852a65 e6ada77f
Pipeline #9269 passed with stage
in 50 minutes and 46 seconds
- 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
......@@ -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'];
......
......@@ -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
......@@ -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);
}
......
......@@ -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();
}
......
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment