Commit 5fae0fd5 authored by Ghislain Loas's avatar Ghislain Loas
Browse files

hotline #50082 mixed record links: refactoring / WIP

parent 4d3f5378
......@@ -988,7 +988,7 @@ class AbonneController extends ZendAfi_Controller_Action {
$datas = [];
$emprunts = $this->_user->getLoansWithoutPNB();
foreach($emprunts as $emprunt) {
if (!$exemplaire = $emprunt->getExemplaireOPAC())
if (!$exemplaire = Class_Exemplaire::findFromSIGBOperation($this->_user, $emprunt))
continue;
$datas[] = $exemplaire->toUnimarcIso2709();
......
......@@ -657,7 +657,7 @@ class RechercheController extends ZendAfi_Controller_Action {
$current_hold = null;
foreach($user->getReservations() as $hold) {
if (!$opac_item = $hold->getExemplaire()->getExemplaireOPAC())
if (!$opac_item = Class_Exemplaire::findFromSIGBOperation($user, $hold))
continue;
if ($item_id == $opac_item->getId()) {
......
......@@ -22,11 +22,10 @@ class Class_CommSigb {
use Trait_Translator;
protected static $_instance = null;
protected $_int_bib;
public static function getInstance() {
if (null === self::$_instance)
self::$_instance = new self();
return new self();
return self::$_instance;
}
......@@ -225,7 +224,6 @@ class Class_CommSigb {
if (!$sigb->isConnected())
return $this->_error($this->_("Une erreur de communication avec le serveur a fait échouer la requête. Merci de signaler ce problème à la bibliothèque."));
$this->_int_bib = $user->getIntBib();
return $sigb;
}
......@@ -239,11 +237,6 @@ class Class_CommSigb {
}
public function getIntBib() {
return $this->_int_bib;
}
protected function _error($message) {
return ['erreur' => $message];
}
......
......@@ -19,12 +19,21 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class Class_ExemplaireLoader extends Storm_Model_Loader {
public function findFromSIGBOperation($user, $operation) {
return $operation->getExemplaire()->getExemplaireOPAC();
}
}
class Class_Exemplaire extends Storm_Model_Abstract {
use Trait_Translator, Trait_TimeSource;
protected $_table_name = 'exemplaires';
protected $_table_primary = 'id';
protected $_group_count = 0;
protected
$_table_name = 'exemplaires',
$_table_primary = 'id',
$_loader_class = 'Class_ExemplaireLoader',
$_group_count = 0;
protected $_belongs_to = [
'notice' => ['model' => 'Class_Notice',
......
......@@ -34,10 +34,10 @@ class IntBibLoader extends Storm_Model_Loader {
public static function findAllByCommSIGB() {
if(!$comm_sigb = Class_CommSigb::getInstance())
return [0];
return null;
if(!$live_int_bib = $comm_sigb->getIntBib())
return [0];
return null;
return ($int_bibs = (new Storm_Model_Collection(Class_IntBib::findAll()))
->select(function($int_bib) use($live_int_bib)
......@@ -50,7 +50,7 @@ class IntBibLoader extends Storm_Model_Loader {
->collect('id_bib')
->getArrayCopy())
? $int_bibs
: [0];
: null;
}
}
......
......@@ -23,8 +23,8 @@ class Class_WebService_SIGB_Emprunteur {
protected
$_id,
$_name,
$_emprunts,
$_reservations,
$_emprunts = [],
$_reservations = [],
$_waiting_holds,
$_email = '',
$_nom = null,
......@@ -98,10 +98,10 @@ class Class_WebService_SIGB_Emprunteur {
* @param string $name
*/
function __construct($id, $name){
$this->_id=$id;
$this->_name=$name;
$this->_emprunts=null;
$this->_reservations=null;
$this->_id = $id;
$this->_name = $name;
$this->_emprunts = [];
$this->_reservations = [];
}
/**
......@@ -292,9 +292,6 @@ class Class_WebService_SIGB_Emprunteur {
* @return Class_WebService_SIGB_Emprunteur
*/
public function empruntsAddAll($emprunts){
if (null === $this->_emprunts)
$this->_emprunts = [];
$this->_emprunts = array_merge($this->_emprunts, $emprunts);
$this->_nb_emprunts = null;
$this->_nb_retards = null;
......@@ -315,16 +312,13 @@ class Class_WebService_SIGB_Emprunteur {
* @return Class_WebService_SIGB_Emprunteur
*/
public function reservationsAddAll($reservations){
if (null === $this->_reservations)
$this->_reservations = array();
$this->_reservations = array_merge($this->_reservations, $reservations);
$this->_nb_reservations = count($this->_reservations);
return $this;
}
/**
* @param Class_WebService_SIGB_Reservation $reservation
* @param Class_WebService_SIGB_eservation $reservation
*/
public function reservationsAdd($reservation) {
$this->reservationsAddAll(array($reservation));
......@@ -339,6 +333,7 @@ class Class_WebService_SIGB_Emprunteur {
if (!isset($this->_service))
return [];
$this->reservationsAddAll($this->_service->getReservationsOf($this));
return $this->_reservations;
}
......
......@@ -100,7 +100,7 @@ class Class_WebService_SIGB_Exemplaire {
public function getExemplaireOPAC() {
if (isset($this->_exemplaire_opac))
return $this->_exemplaire_opac;
return null;
$params = [];
if ($no_notice = $this->getNoNotice())
......@@ -109,10 +109,11 @@ class Class_WebService_SIGB_Exemplaire {
if ($this->code_barre)
$params['code_barres'] = $this->code_barre;
return ($params = array_merge($params,
['id_int_bib' => Class_IntBib::findAllByCommSIGB()]))
? Class_Exemplaire::findFirstBy($params)
: null;
if (!$int_bibs = Class_IntBib::findAllByCommSIGB())
return null;
return Class_Exemplaire::findFirstBy(array_merge($params,
['id_int_bib' => $int_bibs]));
}
......
......@@ -158,7 +158,7 @@ abstract class Class_WebService_SIGB_ExemplaireOperation {
* @return string
*/
public function getNoticeOPACId() {
if ($notice = $this->getNoticeOpac())
if ($notice = $this->getNoticeOPAC())
return $notice->getId();
return 0;
}
......
......@@ -55,7 +55,6 @@ class ZendAfi_View_Helper_Abonne_ReservationsTable extends ZendAfi_View_Helper_B
$html = '';
$html .= (isset($fiche['message']) && $fiche['message'] ? $this->_renderError($fiche['message']) : '');
$html .= (isset($fiche['erreur']) && $fiche['erreur'] ? $this->_renderError($fiche['erreur']) : '');
$this->_line_no = 1;
foreach($reservations as $reservation)
$html .= $this->_renderReservation($reservation);
......
......@@ -108,7 +108,17 @@ abstract class AbonneControllerPretsListThreePretsTestCase extends AbstractAbonn
public function setUp() {
parent::setUp();
$potter = new Class_WebService_SIGB_Emprunt('12', new Class_WebService_SIGB_Exemplaire(123));
$potter->getExemplaire()->setTitre('Potter');
$potter->getExemplaire()
->setTitre('Potter')
->setExemplaireOPAC($this->fixture('Class_Exemplaire',
['id' => 967,
'id_origine' => 1234,
'zone995' => serialize([['clef' => 'a', 'valeur' => 'PotterItem']]),
'notice' => $this->fixture('Class_Notice',
['id' => 889,
'titre_principal' => 'Potter',
'unimarc' => '00577nam0 2200181 450 001001500000010001800015100004100033101000800074200010700082210003000189215001100219461002000230606002900250676000800279700004500287801005600332940000700388frOr1314913787 a9781408812792 a20140320 0103  aEng1 aHarry Potter and the deathly hallowsdHarry Potter et les reliques de la mortfJoanne Kathleen Rowling aLondrescBloomsburyd2010 a831 p. 1tHarry Potterv7 aAnglais (langue)2Rameau a420 1aRowlingbJoanne Kathleenf1965-....4070 aFRbBibliothèque de l\'agglomération de Saint-Omer apm'])]));
$potter->parseExtraAttributes(['Dateretourprevue' => '29/10/2022',
'Section' => 'Espace jeunesse',
'Auteur' => 'JK Rowling',
......@@ -116,31 +126,26 @@ abstract class AbonneControllerPretsListThreePretsTestCase extends AbstractAbonn
'N° de notice' => '1234',
'Type' => 'P1']);
$this->fixture('Class_Exemplaire',
['id' => 967,
'id_origine' => 1234,
'zone995' => serialize([['clef' => 'a', 'valeur' => 'PotterItem']]),
'notice' => $this->fixture('Class_Notice',
['id' => 889,
'titre_principal' => 'Potter',
'unimarc' => '00577nam0 2200181 450 001001500000010001800015100004100033101000800074200010700082210003000189215001100219461002000230606002900250676000800279700004500287801005600332940000700388frOr1314913787 a9781408812792 a20140320 0103  aEng1 aHarry Potter and the deathly hallowsdHarry Potter et les reliques de la mortfJoanne Kathleen Rowling aLondrescBloomsburyd2010 a831 p. 1tHarry Potterv7 aAnglais (langue)2Rameau a420 1aRowlingbJoanne Kathleenf1965-....4070 aFRbBibliothèque de l\'agglomération de Saint-Omer apm'])]);
$alice = new Class_WebService_SIGB_Emprunt('13', new Class_WebService_SIGB_Exemplaire(456));
$alice->getExemplaire()->setTitre('Alice');
$alice->getExemplaire()
->setTitre('Alice')
->setExemplaireOPAC($this->fixture('Class_Exemplaire',
['id' => 918,
'id_origine' => 5678,
'zone995' => serialize([['clef' => 'a', 'valeur' => 'AliceItem']]),
'notice' => $this->fixture('Class_Notice',
['id' => 827,
'titre_principal' => 'Alice',
'unimarc' => '01175cam0 22002771 450 001001500000010003700015100004100052101000800093102000700101105001800108106000600126200009300132210002400225211001300249215006400262300002400326307002900350330027300379345001800652461005600670700001800726701003000744801003300774856008300807940000700890frOr0354235228 a978-2-35592-635-8bbr.d7,65 EUR a20140225d2014 | |0fre|0103||||ba afre aFR a 0||y| ar1 aAlice au royaume de TrèfleeCheshire cat Waltzh5fQuinRosegdessin Mamenosuke Fujimaru aPariscKi-oond2014 1a20140227 a1 vol. (164 p.)cillustrations en noir et blancd18 x 13 cm aTraduit du japonais aSens de lecture japonais aPerdue dans la forêt aux portes, Alice tombe nez à nez avec Ace. Devenue malgré elle la confidente du chevalier, elle ne sait comment repousser ses avances. Lorsque le chat du Cheshire, qui a assisté à la scène, intervient, la rencontre tourne à l\'affrontement. b9782355926358 1tAlice au royaume de Trèfle : Cheshire cat Waltzv5 1aQuinRose4070 1aFujimarubMamenosuke4440 aFRbElectrec20140225gAFNOR uhttp://www.electre.com//GetBlob.ashx?Ean=9782355926358,0-1913692&Size=Original aLR'])]));
$alice->parseExtraAttributes(['Dateretourprevue' => '21/10/2010',
'Section' => 'Espace jeunesse',
'Auteur' => 'Lewis Caroll',
'Bibliotheque' => 'Almont',
'N° de notice' => '5678']);
$this->fixture('Class_Exemplaire',
['id' => 918,
'id_origine' => 5678,
'zone995' => serialize([['clef' => 'a', 'valeur' => 'AliceItem']]),
'notice' => $this->fixture('Class_Notice',
['id' => 827,
'titre_principal' => 'Alice',
'unimarc' => '01175cam0 22002771 450 001001500000010003700015100004100052101000800093102000700101105001800108106000600126200009300132210002400225211001300249215006400262300002400326307002900350330027300379345001800652461005600670700001800726701003000744801003300774856008300807940000700890frOr0354235228 a978-2-35592-635-8bbr.d7,65 EUR a20140225d2014 | |0fre|0103||||ba afre aFR a 0||y| ar1 aAlice au royaume de TrèfleeCheshire cat Waltzh5fQuinRosegdessin Mamenosuke Fujimaru aPariscKi-oond2014 1a20140227 a1 vol. (164 p.)cillustrations en noir et blancd18 x 13 cm aTraduit du japonais aSens de lecture japonais aPerdue dans la forêt aux portes, Alice tombe nez à nez avec Ace. Devenue malgré elle la confidente du chevalier, elle ne sait comment repousser ses avances. Lorsque le chat du Cheshire, qui a assisté à la scène, intervient, la rencontre tourne à l\'affrontement. b9782355926358 1tAlice au royaume de Trèfle : Cheshire cat Waltzv5 1aQuinRose4070 1aFujimarubMamenosuke4440 aFRbElectrec20140225gAFNOR uhttp://www.electre.com//GetBlob.ashx?Ean=9782355926358,0-1913692&Size=Original aLR'])]);
$emprunteur = new Class_WebService_SIGB_Emprunteur('1234', 'Florence');
$emprunteur->empruntsAddAll([$potter, $alice]);
......@@ -232,6 +237,7 @@ class AbonneControllerPretsExportThreePretsTest extends AbonneControllerPretsLis
class AbonneControllerPretsListThreePretsTest extends AbonneControllerPretsListThreePretsTestCase {
public function setUp() {
parent::setUp();
......@@ -437,15 +443,22 @@ class AbonneControllerPretsListReservationTest extends AbstractAbonneControllerP
Class_Exemplaire::beVolatile();
$exemplaire_potter = $this->fixture('Class_Exemplaire',
['id' => 120,
'notice' => $this->fixture('Class_Notice',
['id' => 820,
'titre_principal' => 'Potter'])]);
$potter =
(new Class_WebService_SIGB_Reservation('12',
(new Class_WebService_SIGB_Exemplaire(123))->setTitre('Potter')))
(new Class_WebService_SIGB_Exemplaire(123))
->setTitre('Potter')
->setExemplaireOPAC($exemplaire_potter)))
->parseExtraAttributes(['Etat' => 'Réservation émise',
'Rang' => '2',
'Bibliotheque' => 'Tombouctou',
'N° de notice' => 564]);
// This item has no library: non-regression test.
// This item has no library: non-regression test. @see http://forge.afi-sa.fr/issues/12864
$dobby =
(new Class_WebService_SIGB_Reservation('13',
(new Class_WebService_SIGB_Exemplaire(124))->setTitre('Dobby')))
......@@ -453,42 +466,11 @@ class AbonneControllerPretsListReservationTest extends AbstractAbonneControllerP
'Rang' => '2',
'N° de notice' => 565]);
$this->fixture('Class_Notice',
['id' => 820,
'titre_principal' => 'Potter']);
$this->fixture('Class_Notice',
['id' => 824,
'titre_principal' => 'Dobby']);
$this->fixture('Class_Exemplaire',
['id' => 120,
'id_origine' => 564,
'id_notice' => 820]);
$this->fixture('Class_Exemplaire',
['id' => 13,
'id_origine' => 565,
'id_notice' => 820,
'id_int_bib' => 565]);
$this->fixture('Class_Exemplaire',
['id' => 9,
'id_origine' => 565,
'id_notice' => 820,
'id_int_bib' => 0]);
$this->fixture('Class_Exemplaire',
['id' => 130,
'id_origine' => 565,
'id_notice' => '824',
'zone995' => '']);
$this->florence
->setPseudo('FloFlo')
->setFicheSigb(['type_comm' => Class_IntBib::COM_OPSYS,
'fiche' => (new Class_WebService_SIGB_Emprunteur('1234', 'Florence'))
->reservationsAddAll([$potter, $dobby]),
->reservationsAddAll([$potter, $dobby]),
'message' => '',
'erreur' => '']);
......@@ -565,8 +547,7 @@ class AbonneControllerPretsListReservationTest extends AbstractAbonneControllerP
/** @test */
public function secondReservationTitleShouldBeDobby() {
$this->assertXPathContentContains('//tbody/tr[2]//td', 'Dobby',
$this->_response->getBody());
$this->assertXPathContentContains('//tbody/tr[2]//td', 'Dobby');
}
......@@ -831,10 +812,19 @@ class AbonneControllerPretsPeriodicalTitleTest extends AbstractAbonneControllerP
->setTitre('Avril-mai-juin 2013')
->setDateRetour('30-12-2015')
->setNoNotice(13340)
->setBibliotheque('Espace Culturel Franois-Mitterrand');
->setBibliotheque('Espace Culturel Franois-Mitterrand')
->setExemplaireOPAC(
$this->fixture('Class_Exemplaire',
['id' => 967,
'id_origine' => 13340,
'zone995' => serialize([['clef' => 'a', 'valeur' => 'Espace Culturel'],
['clef' => 'f', 'valeur' => '0720028863'],
['clef' => 'k', 'valeur' => 'J-REV 10-N90']]),
'notice' => $this->fixture('Class_Notice',
['id' => 889,
'unimarc' => file_get_contents(__DIR__.'/petites_mains.mrc')])]));
$loan = new Class_WebService_SIGB_Emprunt(12387, $item);
$patron->empruntsAdd($loan);
Class_CommSigb::setInstance($this->mock()
......@@ -843,19 +833,6 @@ class AbonneControllerPretsPeriodicalTitleTest extends AbstractAbonneControllerP
->whenCalled('getIntBib')
->answers(null));
$record = $this->fixture('Class_Notice',
['id' => 889,
'unimarc' => file_get_contents(__DIR__.'/petites_mains.mrc')]);
$z995 = [['clef' => 'a', 'valeur' => 'Espace Culturel'],
['clef' => 'f', 'valeur' => '0720028863'],
['clef' => 'k', 'valeur' => 'J-REV 10-N90']];
$this->fixture('Class_Exemplaire',
['id' => 967,
'id_origine' => 13340,
'zone995' => serialize($z995),
'notice' => $record]);
$identity->setIdabon('007');
......
......@@ -410,10 +410,10 @@ class RechercheControllerReservationWithWebServiceKohaTest extends AbstractContr
/** @test */
public function withoutMatchingHoldMessageShouldNotContainsPickupLocation() {
public function withoutMatchingHoldMessageShouldContainsDocumentNotFound() {
$this->_dispatchWithEmprunteurAndAssertContentEquals(
$this->_prepareEmprunteurHolding(null, 'Valensole'),
'Votre réservation est enregistrée.<br>Nous vous informerons quand le document sera disponible');
'Document introuvable');
}
......@@ -456,6 +456,9 @@ class RechercheControllerReservationWithWebServiceKohaTest extends AbstractContr
public function popupResultContentWithWebServiceErrorShouldContainsErreurDeCommunication() {
$this->jajm->setIdabon(395749);
$this->_prepareEmprunteurHolding($this->fixture('Class_Exemplaire', ['id' => 456]),
'Valensole');
$this->koha->whenCalled('isConnected')->answers(false);
$this->dispatchAndCheckContentEquals("Une erreur de communication avec le serveur a fait échouer la requête. Merci de signaler ce problème à la bibliothèque.");
......
......@@ -702,8 +702,9 @@ class CommSigbWithNotAbonneTest extends ModelTestCase {
/** @test */
public function reserverExemplaireShouldReturnError() {
$this->fixture('Class_Exemplaire', ['id' => 12]);
$this->assertEquals(['erreur' => 'Communication SIGB indisponible'],
$this->comm_sigb->reserverExemplaire(0, 0, 0));
$this->comm_sigb->reserverExemplaire(0, 12, 0));
}
......
......@@ -940,7 +940,8 @@ class OrpheeServiceGetInfoUserCarteHenryDupontTest extends OrpheeServiceTestCase
* @depends firstReservationShouldNotBeEmpty
*/
public function firstReservationExemplaireOpacShouldBeLeChemin($reservation) {
$this->assertEquals('Le Chemin', $reservation->getExemplaire()->getExemplaireOPAC()->getTitrePrincipal());
$this->assertEquals('Le Chemin',
$reservation->getExemplaire()->getExemplaireOPAC()->getTitrePrincipal());
}
......
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