From 5b54c9634f5a21479839e803e089266f0f14592f Mon Sep 17 00:00:00 2001
From: Ghislain Loas <ghislo@sandbox.pergame.net>
Date: Tue, 3 Feb 2015 16:00:27 +0100
Subject: [PATCH] 
 hotline_#18504_pergame_exemplaire_same_id_origine_between_album_and_sigb

---
 .../hotline_#18504_pergame_subscriptions      |  2 +
 library/Class/Reservation.php                 |  7 +--
 .../controllers/AbonneControllerPretsTest.php | 44 +++++++++++--------
 3 files changed, 31 insertions(+), 22 deletions(-)
 create mode 100644 VERSIONS_STABLE/hotline_#18504_pergame_subscriptions

diff --git a/VERSIONS_STABLE/hotline_#18504_pergame_subscriptions b/VERSIONS_STABLE/hotline_#18504_pergame_subscriptions
new file mode 100644
index 00000000000..4022d240bf0
--- /dev/null
+++ b/VERSIONS_STABLE/hotline_#18504_pergame_subscriptions
@@ -0,0 +1,2 @@
+ - ticket : #18504
+   - SIGB Pergame: correction d'un bug dans l'affichage des réservations en cours qui affichait une ressource numérique.
\ No newline at end of file
diff --git a/library/Class/Reservation.php b/library/Class/Reservation.php
index 4f72f781044..63a62441585 100644
--- a/library/Class/Reservation.php
+++ b/library/Class/Reservation.php
@@ -16,12 +16,12 @@
  *
  * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
  * along with BOKEH; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA 
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
  */
 
 class Class_Reservation extends Storm_Model_Abstract {
 	protected $_table_name = 'reservations';
-	protected $_table_primary = 'id_resa'; 
+	protected $_table_primary = 'id_resa';
 
 	protected $_belongs_to = array('bib' => array('model' => 'Class_Bib',
 																								'referenced_in' => 'id_site'));
@@ -33,7 +33,8 @@ class Class_Reservation extends Storm_Model_Abstract {
 		if (isset($this->_notice))
 			return $this->_notice;
 
-		if ($exemplaire = Class_Exemplaire::getLoader()->findFirstBy(array('id_origine' => $this->getIdNoticeOrigine())))
+		if ($exemplaire = Class_Exemplaire::findFirstBy(['id_origine' => $this->getIdNoticeOrigine(),
+																										 'order' => 'zone995 desc']))
 			return $this->_notice = $exemplaire->getNotice();
 
 		return null;
diff --git a/tests/application/modules/opac/controllers/AbonneControllerPretsTest.php b/tests/application/modules/opac/controllers/AbonneControllerPretsTest.php
index d1515d1f422..d6c27d9b87b 100644
--- a/tests/application/modules/opac/controllers/AbonneControllerPretsTest.php
+++ b/tests/application/modules/opac/controllers/AbonneControllerPretsTest.php
@@ -298,31 +298,37 @@ class AbonneControllerPretsListReservationTest extends AbstractAbonneControllerP
 		$potter =
 			(new Class_WebService_SIGB_Reservation('12',
 																						 (new Class_WebService_SIGB_Exemplaire(123))->setTitre('Potter')))
-			->parseExtraAttributes(array('Etat' => 'Réservation émise',
-																	 'Rang' => '2',
-																	 'Bibliotheque' => 'Tombouctou',
-																	 'N° de notice' => 564));
-
-		Class_Exemplaire::newInstance(['id_origine' => 564,
-																	 'notice' => $this->fixture('Class_Notice',
-																															 ['id' => 823,
-																																'titre_principal' => 'Potter'])
-																		])->assertSave();
+			->parseExtraAttributes(['Etat' => 'Réservation émise',
+															'Rang' => '2',
+															'Bibliotheque' => 'Tombouctou',
+															'N° de notice' => 564]);
 
 		// This item has no library: non-regression test.
 		$dobby =
 			(new Class_WebService_SIGB_Reservation('13',
 																						 (new Class_WebService_SIGB_Exemplaire(124))->setTitre('Dobby')))
-			->parseExtraAttributes(array('Etat' => 'Réservation émise',
-																	 'Rang' => '2',
-																	 'N° de notice' => 565));
+			->parseExtraAttributes(['Etat' => 'Réservation émise',
+															'Rang' => '2',
+															'N° de notice' => 565]);
+
+		$this->fixture('Class_Notice',
+									 ['id' => 820,
+										'titre_principal' => 'Potter']);
 
-		Class_Exemplaire::newInstance(['id_origine' => 565,
-																	 'notice' => $this->fixture('Class_Notice',
-																															['id' => 824,
-																															 'titre_principal' => 'Dobby'])
-																		])->assertSave();
+		$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' => 130,
+										'id_origine' => 565,
+										'id_notice' => '824',
+										'zone995' => '']);
 
 		$this->florence
 			->setFicheSigb(['type_comm' => Class_IntBib::COM_OPSYS,
@@ -374,7 +380,7 @@ class AbonneControllerPretsListReservationTest extends AbstractAbonneControllerP
 
 	/** @test */
 	public function titreShouldBePotterAndLinkToNotice() {
-		$this->assertXPathContentContains('//tbody/tr[1]//td//a[contains(@href, "recherche/viewnotice/id/823/retour_abonne/reservations")]',
+		$this->assertXPathContentContains('//tbody/tr[1]//td//a[contains(@href, "recherche/viewnotice/id/820/retour_abonne/reservations")]',
 																			'Potter',
 																			$this->_response->getBody());
 	}
-- 
GitLab