diff --git a/library/Class/Notice.php b/library/Class/Notice.php index 7d31ff9c4673be8bc8cab75dd48dfafcf2d4301e..b0a5c00a1ef1bf6497e94b7e68235be590938c9c 100644 --- a/library/Class/Notice.php +++ b/library/Class/Notice.php @@ -89,7 +89,8 @@ class Class_Notice extends Storm_Model_Abstract { $_resume, $_matieres, $_editeur, - $_langueCodes; + $_langueCodes, + $_first_exemplaire; protected $_default_attribute_values = ['type_doc' => 0, 'annee' => null, @@ -154,9 +155,9 @@ class Class_Notice extends Storm_Model_Abstract { * @return Class_Exemplaire */ public function getFirstExemplaire() { - if (!$this->hasExemplaires()) - return null; - return array_first($this->getExemplaires()); + return isset($this->_first_exemplaire) + ? $this->_first_exemplaire + : $this->_first_exemplaire = Class_Exemplaire::findFirstBy(['id_notice' => $this->getId()]); } diff --git a/library/Class/NoticeUnimarc.php b/library/Class/NoticeUnimarc.php index 0a0fac0a7613fc57ea00b42e3fea4ed1e3daa5e7..5f503c8de29c8f3ec40371343a91ecd2e04b16cd 100644 --- a/library/Class/NoticeUnimarc.php +++ b/library/Class/NoticeUnimarc.php @@ -131,11 +131,15 @@ class Class_NoticeUnimarc { $tmp_dir = explode('|', chunk_split($this->directory, $m, '|')); $tmp_dir_count = count($tmp_dir); + + $dm1 = $this->inner_guide['dm1']; + $dm2 = $this->inner_guide['dm2']; + $adress_length = 3 + $dm1; for ($i = 0; $i < $tmp_dir_count; $i++) { if ($tmp_dir[$i]) { $this->inner_directory[$i] = array('label' => substr($tmp_dir[$i], 0, 3), - 'length' => intval(substr($tmp_dir[$i], 3, $this->inner_guide['dm1'])), - 'adress' => intval(substr($tmp_dir[$i], 3 + $this->inner_guide['dm1'], $this->inner_guide['dm2']))); + 'length' => intval(substr($tmp_dir[$i], 3, $dm1)), + 'adress' => intval(substr($tmp_dir[$i], $adress_length, $dm2))); } } @@ -145,10 +149,11 @@ class Class_NoticeUnimarc { strlen($this->full_record) - $this->inner_guide['ba']); if ($m) { + $ba = $this->inner_guide['ba']; foreach($this->inner_directory as $cle => $valeur) { $this->inner_data[$cle] = array('label' => $this->inner_directory[$cle]['label'], 'content' => substr($this->full_record, - $this->inner_guide['ba'] + $valeur['adress'], + $ba + $valeur['adress'], $valeur['length'])); } } else { diff --git a/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php b/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php index e6c76bfc49be07b9f6a5de0bd489f32998514457..7fafa0ddc53b43e70e829903daf5cf029912363a 100644 --- a/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php +++ b/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php @@ -185,10 +185,15 @@ class NoticeAjaxControllerResumeAlbumTest extends AbstractControllerTestCase { $this->_notice = Class_Notice::getLoader() ->newInstanceWithId(123) ->beLivreNumerique() - ->setExemplaires(array(Class_Exemplaire::getLoader() + ->setExemplaires(array($exemplaire = Class_Exemplaire::getLoader() ->newInstanceWithId(34) ->setIdOrigine(2))); + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Exemplaire') + ->whenCalled('findFirstBy') + ->with(['id_notice' => 123]) + ->answers($exemplaire); + Class_Album::getLoader() ->newInstanceWithId(2) ->setDescription('Lucky Luke est un grand cow-boy'); diff --git a/tests/library/Class/DecodageUnimarcTest.php b/tests/library/Class/DecodageUnimarcTest.php index 3d7c2a8a91d954e231fb1f5bba0db7745fe91e52..62d2ed3cb0bdc93342feb5d0e8a32e8502726d9d 100644 --- a/tests/library/Class/DecodageUnimarcTest.php +++ b/tests/library/Class/DecodageUnimarcTest.php @@ -113,7 +113,7 @@ class DecodageUnimarcDVDLaJeuneFilleTest extends PHPUnit_Framework_TestCase { class DecodageUnimarcLivreCinemaDAnimationTest extends PHPUnit_Framework_TestCase { public function setUp() { - $this->livre_cinema = new Class_Notice(); + $this->livre_cinema = Class_Notice::newInstanceWithId(2); $this->livre_cinema->setUnimarc("01570nam0 2200325 450 0010007000000100033000070200017000400210027000571000041000841010008001251020007001331050018001401060006001582000106001642100075002702150044003452250023003893000125004123000020005373000137005573300265006943450018009594100051009775120027010286060033010556060060010886760012011487000045011608010039012052218529 a2-86642-370-4bbr.d8,95 EUR aFRb00347575 aFRbDLE-20031204-51138 a20031107d2003 m h0frey0103 ba| afre aFR ay z 000y| ar1 aCinéma d'animationbTexte impriméedessin animé, marionnettes, images de synthèsefBernard Génin a[Paris]c\"Cahiers du cinéma\"cSCEREN-CNDPdcop. 2003gimpr. en Italie a95 p.cill., couv. ill. en coul.d19 cm2 aLes petits cahiers aLa couv. porte en plus : \"du crayon à l'ordinateur, pour ou contre Disney, Europe-Japon : le dessin animé aujourd'hui\" aBibliogr. p. 93 aSCEREN = Services, cultures, éditions, ressources pour l'éducation nationale. CNDP = Centre national de documentation pédagogique aPrésente un historique du cinéma d'animation, un survol des différentes productions nationales à travers le monde (Etats-Unis, Japon, France, Canada), les techniques du volume animé, l'image de synthèse, mais aussi l'oeuvre de Disney et le film d'auteur. b9782866423704 032525826tLes Petits cahiers (Paris)x1633-90531 aLe cinéma d'animation| 31053394aAnimation (cinéma)| 31031625aDessins animés32195497xHistoire et critique a791.431 |32547161aGéninbBernardf1946-....4070 0aFRbBNFc20031107gAFNOR2intermrc"); } @@ -141,7 +141,7 @@ class DecodageUnimarcLivreCinemaDAnimationTest extends PHPUnit_Framework_TestCas class DecodageUnimarcLittleSenegalTest extends PHPUnit_Framework_TestCase { public function setUp() { - $this->little_senegal = new Class_Notice(); + $this->little_senegal = Class_Notice::newInstanceWithId(4); $this->little_senegal->setUnimarc("01494ngm0 2200337 450 0010007000000710012000071000041000191010038000601020007000981150042001052000052001472100035001992150053002343000109002873000071003963050034004673300201005013450027007026060031007296060036007606060043007966060039008397000048008787020043009267020031009697020038010007020035010387020033010738010023011068010027011292371272|0aEDV1441 a20070320i20042001b-ey0frey0103 ba0 afreaengcfrecengjfrejengjger aFR ac093baz|zba||||zz||cb|||||||||||||||1 aLittle SénégalbDVDfRachid Bouchareb, réal. cBlaq outcParamountdcop. 2004 a1 DVD vidéo monoface zone 2 (1 h 33 min)cCoul. aVersion originale franco-anglaise, Version française, avec sous-titrage en français, anglais, allemand aBonus : court-métrage \"Peut-être la mer\" (14 min), bande-annonce aDate de sortie du film : 2001 aUn vieil Africain, guide à la maison des esclaves de l'île de Gorée, part à la rencontre des descendants de ses ancêtres à Harlem... Quête identitaire et exploration d'un fossé culturel... b3333973136023d44,73 ?| 31047449aCinémayAlgérie| 32243366aCinémayFrancez1990-| 32163808aNoirs américainsxAu cinéma| 32243367aCinéma30076549yAfrique 132371273aBoucharebbRachidf1953-43704690 132371260aKouyatébSotiguif1936-4590 132371274aHopebSharon4590 131073585aZembRoschdyf1965-4590 132371277aLorellebOlivier4690 131089718aBoutellabSafy4230 0aFRbADAVc20070320 0aFRbBM Melunc20070510"); Class_CodifLangue::getLoader() ->newInstanceWithId('fre')->setLibelle(''); diff --git a/tests/library/Class/Notice/DublinCoreVisitorTest.php b/tests/library/Class/Notice/DublinCoreVisitorTest.php index 3dd8e0e3b27734004b0350254543768728aefba9..fb9d9759899ebf5aaf33fcc9338fed2b439db079 100644 --- a/tests/library/Class/Notice/DublinCoreVisitorTest.php +++ b/tests/library/Class/Notice/DublinCoreVisitorTest.php @@ -237,10 +237,17 @@ class DublinCoreVisitorSouvignyTest extends DublinCoreVisitorTestCase { ->setDateMaj('2012-04-23') ->setUrlVignette('http://server.fr/vignette.png') ->setIsbn('') - ->setExemplaires([Class_Exemplaire::newInstanceWithId(22, ['id_origine' => 33])]) + ->setExemplaires([$exemplaire = Class_Exemplaire::newInstanceWithId(22, ['id_origine' => 33])]) ->setEan('4719-5120-0288-9') ->beLivreNumerique(); + + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Exemplaire') + ->whenCalled('findFirstBy') + ->with(['id_notice' => 5]) + ->answers($exemplaire); + + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_TypeDoc') ->whenCalled('find') ->with(Class_TypeDoc::LIVRE_NUM)