From cf5b8a790139a3446c859ff9eaf0e1c72c2153dc Mon Sep 17 00:00:00 2001
From: jpkanter <kanter@ub.uni-leipzig.de>
Date: Wed, 7 Feb 2024 11:00:13 +0100
Subject: [PATCH] refs #25129 [fid_bbi] release/fid_bbi/2024_01 GetItBox->links
 changed the way links for certain sources will be displayed

* additionally to getting automatically resolved there will also be a notice if the user does not have the appropriate rights to view the ressource
* fixed some ancient bug in resolverlinks-print that used an deprecated language strings
* while writing new get it rules slightly polished the formatting of a few rules while sipping coffee
* new language strings and a way to complicated way to achive something that would have worked via brute force
---
 fid_bbi/config/vufind/GetItRules.yaml         | 35 ++++++++++++-------
 fid_bbi/languages/de.ini                      |  6 ++++
 fid_bbi/languages/en.ini                      |  8 ++++-
 themes/fid_bbi/scss/blocks/record.scss        |  5 +++
 .../fid_bbi/templates/get-it-box/links.phtml  | 28 +++++++++++++++
 .../fid_bbi/templates/get-it-box/notice.phtml | 21 +++++------
 6 files changed, 79 insertions(+), 24 deletions(-)

diff --git a/fid_bbi/config/vufind/GetItRules.yaml b/fid_bbi/config/vufind/GetItRules.yaml
index 61a73bcfdc7..ecc1eefebd2 100644
--- a/fid_bbi/config/vufind/GetItRules.yaml
+++ b/fid_bbi/config/vufind/GetItRules.yaml
@@ -13,7 +13,7 @@ var_source9_vkfilm2: [ 183 ]
 var_source_10_mediawb: [ 159 ]
 var_source_11_base: [ 126 ]
 var_source_12_gvi: [ 17, 35, 173, 180, 181, 182, 183, 186, 193, 198 ]
-var_source_13_doi_proxy: [ 220 ]
+var_source_13_doi_proxy: [ 219, 220, 220 ]
 var_ger_network: [swb, bvb, kobv, gbv, hebis, hbz] # german library networks
 var_media1: [ "Book, E-Book", Book, eBook, BookComponentPart, ElectronicBookComponentPart, IllustratedBook, ComicBook, E-Book, Thesis, ElectronicThesis ]
 var_media2: [ "Article, E-Article", Article, ElectronicArticle, E-Article, Map, Unknown, Manuscript, ManuscriptFragement, WorkingManuscripts, VisualMedia, ElectronicVisualMedia, Microform, OtherMicroformCarrier ]
@@ -203,11 +203,11 @@ rules:
   isLogonDemand_function:
     - 'isLogonRequired'  # this defines the positive when to set Headline to "register" but it is that by default
     - >
-      (is_source3) or 
-      (is_source5) or 
-      (is_source8 and is_source9 and is_collection2) or
+      (is_source3)                                                                        or 
+      (is_source5)                                                                        or 
+      (is_source8 and is_source9 and is_collection2)                                      or
       (is_source8 and is_facetLocal and ( (is_media1 and !is_institute1) or is_media3 ) ) or
-      (is_source8 and is_facetOnline and not is_facetFree and is_media1) or
+      (is_source8 and is_facetOnline and not is_facetFree and is_media1)                  or
       allowDirectDelivery
   boxHeadline_function: # refacot 1.1  --- actually, this seems to no be used in bbi anyway
     - 'boxHeadline_function'
@@ -215,7 +215,7 @@ rules:
       ( allowDirectDelivery and !is_loggedOn )                                                                or
       ( is_source9 and is_collection2 and !is_loggedOn )                                                      or
       ( !is_source9 and is_facetLocal and ( (is_media1 and is_institute1) or is_media1) and !is_loggedOn )    or 
-      ( !is_source9 and !is_facetLocal and not ( (is_media1 and is_institute1) or is_media1) and
+      ( !is_source9 and !is_facetLocal and not ( (is_media1 and is_institute1) or is_media1)                  and
         is_facetOnline and !is_facetFree and !is_media1 and !is_loggedOn
       )
   boxHeadline_decider: [ 'boxHeadline', 'boxHeadline_function ? this.translate("getit_logged_not") : this.translate("Get it")' ]
@@ -226,8 +226,8 @@ rules:
   show_print_order_button_function:
     - 'show_print_order_button'
     - >
-      conf_allowPDA                               and
-      allowDirectDelivery                         and
+      conf_allowPDA                              and
+      allowDirectDelivery                        and
       is_loggedOn                                and 
       is_authorized_for_fid_acquisitions
   show_print_order_button_decider: [ 'showOrderButton', 'show_print_order_button' ]
@@ -236,8 +236,8 @@ rules:
   show_digitization_button_function:
     - 'show_digitization_button'
     - >
-      conf_allowDigitizationOnDemand              and
-      allowDigitizationOnDemand                   and
+      conf_allowDigitizationOnDemand             and
+      allowDigitizationOnDemand                  and
       is_loggedOn                                and 
       is_authorized_for_fid_acquisitions
   show_digitization_button_decider: [ 'showDigitizationOnDemandButton', 'show_digitization_button' ]
@@ -247,8 +247,8 @@ rules:
     - 'show_part_copy_button'
     - >
       conf_allowSubitoPartialCopy                 and
-      !is_facetFree and !is_collection2                                 and
-      not is_facetOnline and is_media1 and
+      !is_facetFree and !is_collection2           and
+      not is_facetOnline and is_media1            and
       is_collection                               and
       is_loggedOn and is_authorized_for_fid_acquisitions
   show_part_copy_button_decider: [ 'showPartCopyButton', 'show_part_copy_button' ]
@@ -257,7 +257,7 @@ rules:
   show_article_button_function:
     - 'show_article_button'
     - >
-      conf_allowSubitoArticleCopy                 and
+      conf_allowSubitoArticleCopy             and
       is_source3                              and
       is_loggedOn and is_authorized_for_fid_acquisitions
   show_article_button_decider: [ 'showArticleButton', 'show_article_button' ]
@@ -388,4 +388,13 @@ rules:
       is_loggedOn and
       is_licensed
   #############################################################################################
+  # licensed link decider #####################################################################
+  license_link_decider:
+    - 'lic_notice'
+    - >
+      !is_source13 ? '' :
+      followProxy ? this.out('lic_access') :
+      is_loggedOn and !is_licensed ? this.out('lic_noaccess') :
+      this.out('lic_req')
+  #############################################################################################
 stopFlags: 'break'
\ No newline at end of file
diff --git a/fid_bbi/languages/de.ini b/fid_bbi/languages/de.ini
index 895e48029b4..871c65b2ca2 100644
--- a/fid_bbi/languages/de.ini
+++ b/fid_bbi/languages/de.ini
@@ -51,6 +51,7 @@ Questions And Notes = "allgemeine Fragen / Anmerkungen"
 Privacy Policy = "Datenschutzerklärung"
 Report an error = "Fehler melden"
 Terms of Use = "Nutzungsbedingungen"
+BBI Groups = Nutzer*innengruppe
 # cf. #15230
 email_subject = "Betreff"
 email_contact_policy = "Ich akzeptiere die %%policy_link%%."
@@ -498,6 +499,11 @@ getit_text_fidbbi_licence = "Dieses E-Book ist für Sie über eine FID BBI-Lizen
 getit_text_media_typ_limitation = "Einige Medientypen (wie z. B. Manuskripte, Schallplatten, CDs, Videos) können von der Fernleihe ausgeschlossen sein."
 getit_text_access_ebook_hint = "Wenn dieser Titel bei Ihrer Heimatbibliothek als vorhanden gekennzeichnet ist, sollte der direkte Zugang über den Link ohne weiteres möglich sein."
 getit_text_digi_demand = "Möglicherweise ist dieses Buch gemeinfrei und kann von uns kostenlos für Sie digitalisiert werden."
+getit_text_lic_req = "Diese Ressource wird Ihnen vom FID BBI zur Verfügung gestellt. Für den Zugriff müssen Forschende sich anmelden. Noch keinen Account? %%req%%"
+getit_text_lic_noaccess = "Diese Ressource wird Ihnen vom FID BBI zur Verfügung gestellt. Für den Zugriff sind Sie derzeit nicht berechtigt. Eine Änderung Ihrer %%groups%% beantragen Sie bitte über eine Mail an %%mail%%."
+getit_text_lic_access = "Diese Ressource wird Ihnen vom FID BBI zur Verfügung gestellt. Über den Link erhalten Sie Zugriff!"
+getit_text_lic_bonus = "Möglicherweise sehen Sie hier dennoch einen Link, der Zugriff auf den Volltext ist ohne Berechtigung jedoch nicht möglich."
+fid_bbi_mail = "fid@hab.de"
 
 sources_explanatory_line = "Das Rechercheportal des FID BBI vereint Titeldaten aus verschiedensten Datenquellen, die - vollständig oder gefiltert nach dem Fächerprofil des FID BBI - in das Portal übernommen werden. Die wichtigsten Informationen darüber, was in den einzelnen Quellen recherchiert werden kann, haben wir an dieser Stelle zusammengefasst. Um unsere Erläuterungen zu den einzelnen Datenquellen einzusehen, klicken Sie einfach auf den entsprechenden Listeneintrag."
 
diff --git a/fid_bbi/languages/en.ini b/fid_bbi/languages/en.ini
index ab2d3cb827d..36a94cc0971 100644
--- a/fid_bbi/languages/en.ini
+++ b/fid_bbi/languages/en.ini
@@ -33,6 +33,7 @@ Privacy Policy = "Privacy Policy"
 Remove all Filters = "Remove all Filters"
 Report an error = "Report an Error"
 Username = "E-Mail address"
+BBI Groups = user group
 email_contact_policy = "I hereby accept the %%policy_link%%."
 Send = "Submit"
 Book Suggestion = Acquisition Request
@@ -489,7 +490,12 @@ getit_text_direct_delivery = "Order a loan copy of this new publication via the
 getit_text_fidbbi_licence = "This e-book is free to access for you via an FID BBI license."
 getit_text_media_typ_limitation = "Some media types (e.g. manuscripts, records, CDs, videos) may be excluded from interlibrary loan."
 getit_text_access_ebook_hint = "If this title is marked as available in your home library, you should be able to access it directly via the link."
-getit_text_digi_demand = "This book may be in the public domain. In this case, we can digitize it for you free of charge. "
+getit_text_digi_demand = "This book may be in the public domain. In this case, we can digitize it for you free of charge."
+getit_text_lic_req = "This resource is available to you via the FID BBI. To gain access, researchers must log in. No account yet? %%req%%"
+getit_text_lic_noaccess = "This resource is available via the FID BBI, but you are currently not authorised to access it. Please request a change of your %%groups%% by sending an email to %%mail%%."
+getit_text_lic_access = "This resource is available to you via the FID BBI. Click on the link to gain access!"
+getit_text_lic_bonus = "You may still see a link here, but access to the full text is not possible without authorisation."
+fid_bbi_mail = "fid@hab.de"
 
 #19737
 toolbar_add-to = "Save to ..."
diff --git a/themes/fid_bbi/scss/blocks/record.scss b/themes/fid_bbi/scss/blocks/record.scss
index 0f88369b19a..adf28dba01c 100644
--- a/themes/fid_bbi/scss/blocks/record.scss
+++ b/themes/fid_bbi/scss/blocks/record.scss
@@ -281,3 +281,8 @@
     display: block;
   }
 }
+
+.bonus-info { /*this small (i) for abbr information*/
+  margin: 5px;
+  padding: 2px;
+}
diff --git a/themes/fid_bbi/templates/get-it-box/links.phtml b/themes/fid_bbi/templates/get-it-box/links.phtml
index 832b89ef0d3..e7cd398889a 100644
--- a/themes/fid_bbi/templates/get-it-box/links.phtml
+++ b/themes/fid_bbi/templates/get-it-box/links.phtml
@@ -3,6 +3,34 @@
   <div id="side-collapse-links-data">
     <?php if (!empty($urls)): ?>
       <h3 lang="en" link id="h3_solrurls"><?=$this->translate("Weblinks")?></h3>
+      <?php /* #refs 25129 - licensed links in get it box */?>
+      <?php if (!empty($getitConfig['lic_notice'])): ?>
+        <?php // i srsly question the wisdom of building these here like that
+            $account = $this->auth()->getManager();
+            $req = '<a href="' .
+              $this->url('myresearch-account') . '?auth_method=' . $account->getAuthMethod() . '">' .
+              $this->translate("getit_text_req_now") . "</a>";
+            $groups= '<a href="/Content/faq#groups-1">'.
+              $this->translate("BBI Groups") . '</a>';
+            $mail = '<a href="mailto: '.$this->translate("fid_bbi_mail").'">'.$this->translate("fid_bbi_mail").'</a>';
+            ?>
+        <p>
+          <?=str_replace(['%%req%%', '%%groups%%', '%%mail%%'],
+                          [$req, $groups, $mail],
+                          $getitConfig['lic_notice']);?>
+
+          <?php if (!$getitConfig['followProxy']): /*link might there but not proxied*/?>
+            <?php
+              /* This tiny code snipped might be subject of discussion. The logic here is implicit which, in principle
+              breaks our previously established rule set. This only works because the combination of 'there is something'
+              and it's not privileged access creates a condition in itself. By sequencing it like this no additional
+              rule has to be written but the overall clarity has to suffer. On the other the getitrules.yaml can be
+              free of rules bloat which it already has a lot while it screams "refactor me!"*/
+            ?>
+            <sup><abbr title="<?=$this->translate('getit_text_lic_bonus')?>"><?=$this->icon('info', 'icon bonus-info')?></abbr></sup>
+          <?php endif; ?>
+        </p>
+      <?php endif; ?>
       <ul class="unstyled-list">
         <?php foreach ($urls as $url): ?>
           <li>
diff --git a/themes/fid_bbi/templates/get-it-box/notice.phtml b/themes/fid_bbi/templates/get-it-box/notice.phtml
index 355cd708a31..de7e65924a3 100644
--- a/themes/fid_bbi/templates/get-it-box/notice.phtml
+++ b/themes/fid_bbi/templates/get-it-box/notice.phtml
@@ -19,16 +19,6 @@
  * configured in: getitbox.yaml
  */
 ?>
-<?php if ($getitConfig['hideNotice']): ?>
-  <?php $script = <<<JS
-$(document).ready(function() {
-  $('.getitbox-notices').addClass('hidden');
-});
-JS;
-  ?>
-  <?=$this->inlineScript(\Laminas\View\Helper\HeadScript::SCRIPT, $script, 'SET');?>
-<?php endif; ?>
-
 <?php if ($openUrlActive): ?>
   <div class="getitbox-notices">
     <div class="openUrlPrint"></div>
@@ -68,4 +58,15 @@ JS;
   </div>
 <?php endif; ?>
 <?=$this->render('get-it-box/interlibraryloan.phtml');?>
+
+<?php if ($getitConfig['hideNotice']): ?>
+    <?php $script = <<<JS
+$(document).ready(function() {
+  $('.getitbox-notices').addClass('hidden');
+});
+JS;
+    ?>
+    <?=$this->inlineScript(\Laminas\View\Helper\HeadScript::SCRIPT, $script, 'SET');?>
+<?php endif; ?>
+
 <!-- fid_bbi: get-it-box - notice - END -->
-- 
GitLab