From 90dcecacf8f25778903748ae608db761d65588a8 Mon Sep 17 00:00:00 2001
From: efalcy <efalcy@afi-sa.fr>
Date: Tue, 12 Jun 2018 15:33:09 +0200
Subject: [PATCH] dev #72825 : add already booked information on user loan
 table

---
 FEATURES/72825                                |  10 ++
 VERSIONS_WIP/72825                            |   1 +
 .../SIGB/AbstractILSDIPatronInfoReader.php    |   5 +
 library/Class/WebService/SIGB/Emprunt.php     |   5 +
 library/Class/WebService/SIGB/Exemplaire.php  |  12 ++
 .../WebService/SIGB/ExemplaireOperation.php   |   6 +
 library/ZendAfi/View/Helper/Abonne/Loans.php  |  34 +++--
 tests/fixtures/ChamberyKohaFixtures.php       | 127 ++++++++++++++++++
 .../HandleBranchcode/HandleBranchcodeTest.php |  65 +++++++--
 9 files changed, 245 insertions(+), 20 deletions(-)
 create mode 100644 FEATURES/72825
 create mode 100644 VERSIONS_WIP/72825

diff --git a/FEATURES/72825 b/FEATURES/72825
new file mode 100644
index 00000000000..077cc050930
--- /dev/null
+++ b/FEATURES/72825
@@ -0,0 +1,10 @@
+        '72825' =>
+            ['Label' => $this->_('[contractuel] BDP64 -  afficher la colonne "Réservé par d'autres"'),
+             'Desc' => '',
+             'Image' => '',
+             'Video' => '',
+             'Category' => '',
+             'Right' => function($feature_description, $user) {return true;},
+             'Wiki' => '',
+             'Test' => '',
+             'Date' => '2018-06-12'],
\ No newline at end of file
diff --git a/VERSIONS_WIP/72825 b/VERSIONS_WIP/72825
new file mode 100644
index 00000000000..39e92bd28e4
--- /dev/null
+++ b/VERSIONS_WIP/72825
@@ -0,0 +1 @@
+ - ticket #72825 : [contractuel] BDP64 -  afficher la colonne "Réservé par d'autres"
\ No newline at end of file
diff --git a/library/Class/WebService/SIGB/AbstractILSDIPatronInfoReader.php b/library/Class/WebService/SIGB/AbstractILSDIPatronInfoReader.php
index 272ab457877..2fb866a0046 100644
--- a/library/Class/WebService/SIGB/AbstractILSDIPatronInfoReader.php
+++ b/library/Class/WebService/SIGB/AbstractILSDIPatronInfoReader.php
@@ -126,6 +126,11 @@ abstract class Class_WebService_SIGB_AbstractILSDIPatronInfoReader {
     $this->getEmprunteur()->empruntsAddAll($this->_loans);
   }
 
+  public function startOnhold($data) {
+    if ($data)
+      $this->_currentLoan->setOnHold($data);
+  }
+
 
   /**
    * @param array $attributes
diff --git a/library/Class/WebService/SIGB/Emprunt.php b/library/Class/WebService/SIGB/Emprunt.php
index 05901c3cb2d..b85125de296 100644
--- a/library/Class/WebService/SIGB/Emprunt.php
+++ b/library/Class/WebService/SIGB/Emprunt.php
@@ -59,6 +59,11 @@ class Class_WebService_SIGB_Emprunt extends Class_WebService_SIGB_ExemplaireOper
   }
 
 
+  public function setOnHold($onhold) {
+    $this->_exemplaire->setOnHold($onhold);
+  }
+
+
   public function onParseAttributes() {
     if( !$this->type = $this->getAttribute('Type'))
       $this->type = '';
diff --git a/library/Class/WebService/SIGB/Exemplaire.php b/library/Class/WebService/SIGB/Exemplaire.php
index f93a7ed0271..7206bfb8507 100644
--- a/library/Class/WebService/SIGB/Exemplaire.php
+++ b/library/Class/WebService/SIGB/Exemplaire.php
@@ -55,6 +55,7 @@ class Class_WebService_SIGB_Exemplaire {
   protected $_emplacement;
   protected $_issue_date;
   protected $consultation = false;
+  protected $onhold = false;
 
   public static function newInstance() {
     return new self(null);
@@ -367,6 +368,17 @@ class Class_WebService_SIGB_Exemplaire {
   }
 
 
+  public function setOnHold($onhold) {
+    $this->onhold = $onhold;
+    return $this;
+  }
+
+
+  public function onHold() {
+    return $this->onhold;
+  }
+
+
   public function getEdition() {
     return $this->edition;
   }
diff --git a/library/Class/WebService/SIGB/ExemplaireOperation.php b/library/Class/WebService/SIGB/ExemplaireOperation.php
index 71bcdd4aefb..c3790576d83 100644
--- a/library/Class/WebService/SIGB/ExemplaireOperation.php
+++ b/library/Class/WebService/SIGB/ExemplaireOperation.php
@@ -126,6 +126,12 @@ abstract class Class_WebService_SIGB_ExemplaireOperation {
   }
 
 
+  public function getBookedByOthers() {
+    return $this->_exemplaire->onHold();
+  }
+
+
+
   public function getIssueDate() {
     return $this->_exemplaire->getIssueDate();
   }
diff --git a/library/ZendAfi/View/Helper/Abonne/Loans.php b/library/ZendAfi/View/Helper/Abonne/Loans.php
index 8ffbe64dac8..e0ac6022122 100644
--- a/library/ZendAfi/View/Helper/Abonne/Loans.php
+++ b/library/ZendAfi/View/Helper/Abonne/Loans.php
@@ -52,14 +52,20 @@ class ZendAfi_View_Helper_Abonne_Loans extends ZendAfi_View_Helper_Abonne_Operat
 
 
   protected function _tableColumns() {
-    return [$this->_('Emprunté par'),
-            $this->_('Support'),
-            $this->_('Vignette'),
-            $this->_('Titre'),
-            $this->_('Auteur'),
-            $this->_('Bibliothèque'),
-            $this->_('Retour prévu'),
-            $this->_('Informations')];
+    return array_filter([$this->_('Emprunté par'),
+                         $this->_('Support'),
+                         $this->_('Vignette'),
+                         $this->_('Titre'),
+                         $this->_('Auteur'),
+                         $this->_('Bibliothèque'),
+                         $this->_('Retour prévu'),
+                         $this->_('Informations'),
+                         $this->displayBookedByOthers() ? $this->_('Document réservé par d\'autres') : null]);
+  }
+
+
+  protected function displayBookedByOthers() {
+    return true;
   }
 
 
@@ -74,6 +80,14 @@ class ZendAfi_View_Helper_Abonne_Loans extends ZendAfi_View_Helper_Abonne_Operat
 
 
   protected function renderLoan($loan) {
+
+    $tag_bookedbyothers = $this->displayBookedByOthers() ? $this->_tag('td',
+                                                                       '',
+                                                                       $loan->getBookedByOthers()?
+                                                                       ['class' => 'checkedbox'] :
+                                                                       ['class' => 'uncheckedbox'])
+      : '';
+
     return
       $this->_tag('tr',
                   $this->_tag('td',
@@ -91,7 +105,9 @@ class ZendAfi_View_Helper_Abonne_Loans extends ZendAfi_View_Helper_Abonne_Operat
                   . $this->_tag('td',
                                 $loan->getDateRetour() . ' ' . $this->view->abonne_LoanAction($loan), ['class' => 'date_retour'])
                   . $this->_tag('td',
-                                $loan->getType()),
+                                $loan->getType())
+                  .$tag_bookedbyothers,
                   ($loan->isLate()) ? ['class' => 'pret_en_retard'] : []);
+
   }
 }
\ No newline at end of file
diff --git a/tests/fixtures/ChamberyKohaFixtures.php b/tests/fixtures/ChamberyKohaFixtures.php
index cd25abd237e..20aa4e07d02 100644
--- a/tests/fixtures/ChamberyKohaFixtures.php
+++ b/tests/fixtures/ChamberyKohaFixtures.php
@@ -429,4 +429,131 @@ class ChamberyKohaFixtures {
   <privacy>1</privacy>
 </GetPatronInfo>';
   }
+
+  public function getLoans() {
+return '<?xml version="1.0" encoding="UTF-8" ?>
+<GetPatronInfo>
+  <city>Gotham City</city>
+  <altcontactaddress2></altcontactaddress2>
+  <B_address2></B_address2>
+  <altcontactfirstname></altcontactfirstname>
+  <sort2></sort2>
+  <borrowernumber>6871</borrowernumber>
+  <altcontactphone></altcontactphone>
+  <title></title>
+  <dateexpiry>2019-06-30</dateexpiry>
+  <mobile>06 01 02 03 04</mobile>
+  <cardnumber>90519000053165</cardnumber>
+  <B_streetnumber></B_streetnumber>
+  <dateenrolled>2014-04-29</dateenrolled>
+  <altcontactzipcode></altcontactzipcode>
+  <streettype></streettype>
+  <sort1>12</sort1>
+  <email>xxx@xxx.fr</email>
+  <contactfirstname></contactfirstname>
+  <B_country></B_country>
+  <B_email></B_email>
+  <phone>01 02 03 04 05</phone>
+  <B_address></B_address>
+  <branchcode>PUKA</branchcode>
+  <guarantorid>0</guarantorid>
+  <emailpro></emailpro>
+  <phonepro></phonepro>
+  <B_city></B_city>
+  <gonenoaddress>0</gonenoaddress>
+  <privacy_guarantor_checkouts>0</privacy_guarantor_checkouts>
+  <categorycode>J14</categorycode>
+  <dateofbirth>2004-11-10</dateofbirth>
+  <lost>0</lost>
+  <zipcode>1123</zipcode>
+  <lang>default</lang>
+  <altcontactaddress3></altcontactaddress3>
+  <checkprevcheckout>inherit</checkprevcheckout>
+  <fax>01 02 03 04 05</fax>
+  <streetnumber></streetnumber>
+  <altcontactaddress1></altcontactaddress1>
+  <address2></address2>
+  <updated_on>2017-03-23 13:22:49</updated_on>
+  <loans>
+    <loan>
+      <replacementpricedate>2009-10-01</replacementpricedate>
+      <issuedate>2016-05-24 00:00</issuedate>
+      <issues>3</issues>
+      <issue_id>272</issue_id>
+      <author>René Gouichoux, Pronto</author>
+      <permanent_location>Romans enfant</permanent_location>
+      <itemlost>0</itemlost>
+      <overdue>1</overdue>
+      <publishercode>F. Nathan</publishercode>
+      <surname>Aguetant</surname>
+      <biblioitemnumber>4107</biblioitemnumber>
+      <firstname>Agathe</firstname>
+      <notforloan>0</notforloan>
+      <holdingbranch>PUKA</holdingbranch>
+      <itemnumber>5111</itemnumber>
+      <auto_renew>0</auto_renew>
+      <frameworkcode></frameworkcode>
+      <barcode>00519000083096</barcode>
+      <onhold>1</onhold>
+      <publicationyear>2004</publicationyear>
+      <location>Romans enfant</location>
+      <withdrawn>0</withdrawn>
+      <date_due>2017-06-14 00:00</date_due>
+      <dateaccessioned>2014-06-26</dateaccessioned>
+      <itemtype>LIVR</itemtype>
+      <damaged>0</damaged>
+      <homebranch>PUKA</homebranch>
+      <more_subfields_xml>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
+&lt;collection
+  xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
+  xsi:schemaLocation=&quot;http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd&quot;
+  xmlns=&quot;http://www.loc.gov/MARC21/slim&quot;&gt;
+
+&lt;record&gt;
+  &lt;leader&gt;         a              &lt;/leader&gt;
+  &lt;datafield tag=&quot;999&quot; ind1=&quot; &quot; ind2=&quot; &quot;&gt;
+    &lt;subfield code=&quot;h&quot;&gt;8309&lt;/subfield&gt;
+    &lt;subfield code=&quot;j&quot;&gt;Librairie jeunesse au pays ble&lt;/subfield&gt;
+    &lt;subfield code=&quot;q&quot;&gt;Jeunes&lt;/subfield&gt;
+    &lt;subfield code=&quot;p&quot;&gt;5,35&lt;/subfield&gt;
+    &lt;subfield code=&quot;s&quot;&gt;24/04/2004&lt;/subfield&gt;
+  &lt;/datafield&gt;
+&lt;/record&gt;
+
+&lt;/collection&gt;</more_subfields_xml>
+      <itemcallnumber>E GOU</itemcallnumber>
+      <itype>LIVR</itype>
+      <branchcode>PUKA</branchcode>
+      <date_due_sql>2017-06-14 00:00:00</date_due_sql>
+      <biblionumber>4107</biblionumber>
+      <onloan>2016-06-14</onloan>
+      <datecreated>2014-06-26</datecreated>
+      <cardnumber>90519000053165</cardnumber>
+      <datelastborrowed>2016-05-24</datelastborrowed>
+      <timestamp>2017-03-23 13:24:14</timestamp>
+      <title>Quel bazar, Léonard !</title>
+      <borrowernumber>6871</borrowernumber>
+      <datelastseen>2016-05-24</datelastseen>
+      <isbn>2092502611</isbn>
+      <onsite_checkout>0</onsite_checkout>
+      <cn_sort>E_GOU</cn_sort>
+    </loan>
+  </loans>
+  <firstname>Agathe</firstname>
+  <B_zipcode></B_zipcode>
+  <sex></sex>
+  <othernames></othernames>
+  <privacy>1</privacy>
+  <surname>Aguetant</surname>
+  <B_streettype></B_streettype>
+  <altcontactsurname></altcontactsurname>
+  <login_attempts>0</login_attempts>
+  <initials></initials>
+  <branchname>Pukapuka</branchname>
+  <contactname></contactname>
+  <address>6871 rue de Agathe</address>
+  <B_phone></B_phone>
+</GetPatronInfo>
+';
+  }
 }
\ No newline at end of file
diff --git a/tests/scenarios/HandleBranchcode/HandleBranchcodeTest.php b/tests/scenarios/HandleBranchcode/HandleBranchcodeTest.php
index c72b5c7adcb..052ca462d68 100644
--- a/tests/scenarios/HandleBranchcode/HandleBranchcodeTest.php
+++ b/tests/scenarios/HandleBranchcode/HandleBranchcodeTest.php
@@ -27,7 +27,18 @@ abstract class HandleBranchcodeTestCase extends AbstractControllerTestCase {
     $service,
     $user,
     $ilsdi;
+  protected function _setMockWebClient() {
+    $this->mock_web_client
+      ->whenCalled('open_url')
+      ->with($this->ilsdi . '?service=AuthenticatePatron&username=Chambelle&password=upw')
+      ->answers(ChamberyKohaFixtures::authenticatePatronChambelle())
 
+      ->whenCalled('open_url')
+      ->with($this->ilsdi . '?service=GetPatronInfo&patron_id=18&show_contact=1&show_loans=1&show_holds=1')
+      ->answers(ChamberyKohaFixtures::getPatronInfoChambelle());
+
+
+  }
   public function setUp() {
     parent::setUp();
     Class_WebService_SIGB_Koha::reset();
@@ -39,15 +50,7 @@ abstract class HandleBranchcodeTestCase extends AbstractControllerTestCase {
                                                              'type' => Class_IntBib::COM_KOHA]);
     $this->service->setWebClient($this->mock_web_client);
 
-    $this->mock_web_client
-      ->whenCalled('open_url')
-      ->with($this->ilsdi . '?service=AuthenticatePatron&username=Chambelle&password=upw')
-      ->answers(ChamberyKohaFixtures::authenticatePatronChambelle())
-
-      ->whenCalled('open_url')
-      ->with($this->ilsdi . '?service=GetPatronInfo&patron_id=18&show_contact=1&show_loans=1&show_holds=1')
-      ->answers(ChamberyKohaFixtures::getPatronInfoChambelle());
-
+    $this->_setMockWebClient();
     $this->fixture('Class_CodifAnnexe',
                    ['id' => 58,
                     'libelle' => 'Bibliothèque Georges Brassens',
@@ -70,7 +73,8 @@ abstract class HandleBranchcodeTestCase extends AbstractControllerTestCase {
                             'password' => 'upw',
                             'idabon' => '93658',
                             'id_site' => 12,
-                            'int_bib' => $sigb_gb]);
+                            'int_bib' => $sigb_gb,
+                           'role_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB]);
 
     ZendAfi_Auth::getInstance()->logUser($this->user);
   }
@@ -126,4 +130,43 @@ class HandleBranchcodeSuggestionTest extends HandleBranchcodeTestCase {
   }
 
 }
-?>
\ No newline at end of file
+
+
+class HandleBranchcodeDisplayLoanByOthersTest extends HandleBranchcodeTestCase {
+  protected $expected_call = false;
+  public function setUp() {
+    parent::setUp();
+
+  }
+
+  protected function _setMockWebClient() {
+    $this->mock_web_client
+      ->whenCalled('open_url')
+      ->with($this->ilsdi . '?service=AuthenticatePatron&username=Chambelle&password=upw')
+      ->answers(ChamberyKohaFixtures::authenticatePatronChambelle())
+
+      ->whenCalled('open_url')
+      ->with($this->ilsdi . '?service=GetPatronInfo&patron_id=18&show_contact=1&show_loans=1&show_holds=1')
+      ->answers(ChamberyKohaFixtures::getLoans());
+
+
+  }
+
+
+  /** @test */
+  public function ilsdiHoldTitleShouldBeCallWithCHYMinusGB() {
+    $this->borrower = $this->service->getEmprunteur($this->user);
+    $this->dispatch('/opac/abonne/prets', true);
+    $this->assertXPathContentContains('//div', 'réservé par d\'autres', $this->_response->getBody());
+  }
+
+
+  /** @test */
+  public function onHoldShouldDisplayBookedByOther() {
+    $this->borrower = $this->service->getEmprunteur($this->user);
+    $this->dispatch('/opac/abonne/prets', true);
+    $this->assertXPathContentContains('//div', 'réservé par d\'autres', $this->_response->getBody());
+  }
+
+}
+?>
-- 
GitLab