diff --git a/VERSIONS_HOTLINE/114558 b/VERSIONS_HOTLINE/114558 new file mode 100644 index 0000000000000000000000000000000000000000..0a606fde3dd60828362603aced22cc7140d44f21 --- /dev/null +++ b/VERSIONS_HOTLINE/114558 @@ -0,0 +1 @@ + - ticket #114558 : Affichage de la notice : Correction de l'affichage du lien pour consulter les ressources Jumel \ No newline at end of file diff --git a/application/modules/opac/controllers/NoticeajaxController.php b/application/modules/opac/controllers/NoticeajaxController.php index fc9ce580532c4e27af01499945b5d44d89833e94..0b34514b8fadfbab08ce96ac66cd78fdd253c72c 100644 --- a/application/modules/opac/controllers/NoticeajaxController.php +++ b/application/modules/opac/controllers/NoticeajaxController.php @@ -499,11 +499,7 @@ class NoticeAjaxController extends ZendAfi_Controller_Action { if ((new Class_Notice_Sso($this->notice))->isValid()) return $this->_forward('sso-resources'); - $first_item = $this->notice->getExemplaires()[0]; - - if ($url = $first_item->getUrl()) - return $this->_forward('url-resources'); - + $first_item = $this->notice->getFirstExemplaire(); if ($bundle = $first_item->getBundle()) return $this->_forward('bundle-resources'); @@ -514,13 +510,20 @@ class NoticeAjaxController extends ZendAfi_Controller_Action { public function itemsResourcesAction() { - $callback = function() { - $items_loader = new Intonation_Library_Record_Items($this->notice); - return $this->view->RenderRecord_RenderItems($items_loader->findAll(), - $items_loader->findSameWork()); - }; + $record = new Intonation_Library_Record($this->notice); - return $this->_helper->ajax($callback); + if ($record->isExternalResource()) + return $this->_helper->ajax(function() use ($record) + { + return $this->_getLinkOnline($record->getUrl()); + }); + + + $this->_helper->ajax(function() use ($record) + { + return $this->view->RenderRecord_RenderItems($record->getItemsFromSIGB(), + $record->getSameWorkItemsFromSIGB()); + }); } @@ -540,13 +543,19 @@ class NoticeAjaxController extends ZendAfi_Controller_Action { } + protected function _getLinkOnline($url) { + return $this->view->tagAnchor($url, + $this->view->_('Description en ligne'), + ['class' => 'btn btn-lg btn-primary m-3']); + } + + public function urlResourcesAction() { $first_item = $this->notice->getExemplaires()[0]; $callback = function() use ($first_item) { - return $this->view->tagAnchor($first_item->getUrl(), - $this->view->_('Description en ligne'), - ['class' => 'btn btn-lg btn-primary m-3']); + return $this->_getLinkOnline($first_item->getUrl()); + }; return $this->_helper->ajax($callback); diff --git a/library/templates/Intonation/Library/Record.php b/library/templates/Intonation/Library/Record.php new file mode 100644 index 0000000000000000000000000000000000000000..0809f6f0f1e54dbf7f4477931b00f112c429747c --- /dev/null +++ b/library/templates/Intonation/Library/Record.php @@ -0,0 +1,66 @@ +<?php +/** + * Copyright (c) 2012-2020, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * 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 + */ + + +class Intonation_Library_Record { + protected + $_record, + $_items; + + public function __construct($record) { + $this->_record = $record; + + if (!$this->_record->isFirstItemTypeSerialArticle()) + return; + + if ($item = $this->_record->getFirstExemplaire()) + $this->_record = $item->getPMBSerialRecord(); + } + + + public function getItemsFromSIGB() { + if (!$this->_items) + $this->_items = (new Intonation_Library_Record_Items($this->_record))->getItemsFromSIGB(); + + return $this->_items; + } + + + public function getSameWorkItemsFromSIGB() { + $records = Class_Notice::findAllBy(['clef_oeuvre' => $this->_record->getClefOeuvre(), + 'id_notice not' => $this->_record->getId()]); + + return (new Intonation_Library_Record_Items($records))->getItemsFromSIGB(); + } + + + public function isExternalResource() { + return !empty($this->getUrl()); + } + + + public function getUrl() { + if (!$items = $this->getItemsFromSIGB()) + return null; + + return $items[0]->getUrl(); + } +} diff --git a/library/templates/Intonation/Library/Record/Items.php b/library/templates/Intonation/Library/Record/Items.php index ecb0ef5955ea007c6df21b9d607ebab620b72376..7bf64f681fe9a0a9282afaaa2db0314784441f03 100644 --- a/library/templates/Intonation/Library/Record/Items.php +++ b/library/templates/Intonation/Library/Record/Items.php @@ -21,69 +21,76 @@ class Intonation_Library_Record_Items { + protected + $_records, + $_items; - protected $_record; - - public function __construct($record) { - $this->_record = $record; - - if (!$this->_record->isFirstItemTypeSerialArticle()) - return; - - if ($item = $this->record->getFirstExemplaire()) - $this->_record = $item->getPMBSerialRecord(); + public function __construct($records) { + $this->_records = is_array($records) + ? $records + : [ $records ]; } - public function findAll() { - return $this->_record->hasExemplaires() - ? $this->_findItems($this->_record->getId()) - : []; + public function getItemsFromSIGB() { + return $this->_getItemsFromSIGB($this->findAll()); } - protected function _findItems($ids) { - if (!$ids) - return []; - - $session = Zend_Registry::get('session'); - - $cond = ['id_notice' => $ids, - 'order' => 'id desc']; - - if ($lib_ids = $session->id_bib) - $cond['id_bib'] = $lib_ids; + public function findAll() { + if (!$this->_items) { + $this->_items = $this->_findItems(); + $this->_updateRecordsFacetsFromItems(); + } - $items = ($items = Class_Exemplaire::findAllBy(array_filter($cond))) - ? $items - : Class_Exemplaire::findAllBy($params); + return $this->_items; + } - $items = (new Class_Profil_ItemsFilter()) - ->select(Class_Profil::getCurrentProfil(), $items); + protected function _getItemsFromSIGB($items) { foreach($items as $item) $item ->updateAvailabilityAndLocationFromSIGB() ->save(); - foreach( Class_Notice::findAllBy(['id_notice' => $ids]) as $record) + return (new Class_CommSigb())->getDispoExemplaires($items); + } + + + protected function _updateRecordsFacetsFromItems() { + foreach($this->_records as $record) $record ->updateFacetsFromExemplaires() ->save(); + return $this; + } - return (new Class_CommSigb())->getDispoExemplaires($items); + + protected function _getRecordIds() { + return array_map(function($record) + { + return $record->getId(); + }, + $this->_records); } - public function findSameWork() { - $records = Class_Notice::findAllBy(['clef_oeuvre' => $this->_record->getClefOeuvre(), - 'id_notice not' => $this->_record->getId()]); + protected function _findItems() { + $session = Zend_Registry::get('session'); - $ids = []; - foreach ($records as $record) - $ids [] = $record->getId(); + $cond = ['id_notice' => $this->_getRecordIds(), + 'order' => 'id desc']; - return $this->_findItems($ids); + if ($lib_ids = $session->id_bib) + $cond['id_bib'] = $lib_ids; + + $items = ($items = Class_Exemplaire::findAllBy(array_filter($cond))) + ? $items + : Class_Exemplaire::findAllBy($params); + + return (new Class_Profil_ItemsFilter()) + ->select(Class_Profil::getCurrentProfil(), $items); } + } diff --git a/tests/application/modules/opac/controllers/NoticeAjaxControllerCdScriptTest.php b/tests/application/modules/opac/controllers/NoticeAjaxControllerCdScriptTest.php index 7f65631e959bbc53fc7d7a86608a24f4a4ff4eeb..374266034416c927fed3bc12733d7272711d880b 100644 --- a/tests/application/modules/opac/controllers/NoticeAjaxControllerCdScriptTest.php +++ b/tests/application/modules/opac/controllers/NoticeAjaxControllerCdScriptTest.php @@ -19,20 +19,10 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +class FixtureCdScript { + use Storm_Test_THelpers; -abstract class NoticeAjaxControllerCdScriptRecordTestCase extends AbstractControllerTestCase { - protected - $_storm_default_to_volatile = true; - - public function setUp() { - parent::setUp(); - - ZendAfi_Auth::getInstance()->clearIdentity(); - - $config = Class_Profil::getCurrentProfil()->getCfgNoticeAsArray(); - $config['exemplaires']['grouper'] = '1'; - Class_Profil::getCurrentProfil()->setCfgNotice($config); - + public function createItem() { $this->fixture('Class_IntBib', ['id' => 31, 'libelle' => 'le kiosque library', @@ -60,10 +50,22 @@ abstract class NoticeAjaxControllerCdScriptRecordTestCase extends AbstractContro ::getService(['server_url' => 'www.jumel39.fr/docnum.php', 'remote_library_id' => 2]) ->setTimeSource(new TimeSourceForTest('2015-10-28 09:00:00')); + } +} - public function tearDown() { + +abstract class NoticeAjaxControllerCdScriptTestCase extends AbstractControllerTestCase{ + protected + $_storm_default_to_volatile = true; + + public function setup() { + parent::setup(); + (new FixtureCdScript)->createItem(); + } + + public function tearDown() { Class_WebService_SIGB_CdScript::resetService(); parent::tearDown(); } @@ -72,6 +74,51 @@ abstract class NoticeAjaxControllerCdScriptRecordTestCase extends AbstractContro +class NoticeAjaxControllerCdScriptTemplateRecordTest extends NoticeAjaxControllerCdScriptTestCase { + public function setUp() { + parent::setUp(); + Class_AdminVar::set('FEATURES_TRACKING_ENABLE', 0); + + $this->_buildTemplateProfil(['id' => 1, + 'libelle' => 'Dole in bootstrap land']) + ->beCurrentProfil(); + } + + + + /** @test */ + public function resourcesShouldRenderRenderItems() { + $this->dispatch('/opac/noticeajax/resources/id/2'); + $this->assertXPathContentContains('//a[contains(@class, "btn btn-lg")][contains(@href,"www.jumel39.fr/docnum.php?bib=2&res=kio&lien=456789")] ', 'Description en ligne'); + } + + + /** @test */ + public function resourcesNotConnectedShouldRenderUrlLogin() { + ZendAfi_Auth::getInstance()->clearIdentity(); + $this->dispatch('/opac/noticeajax/resources/id/2'); + $this->assertXPathContentContains('//a[contains(@href,"auth/ajax-login")] ', 'Description en ligne'); + } + +} + + + +abstract class NoticeAjaxControllerCdScriptRecordTestCase extends NoticeAjaxControllerCdScriptTestCase { + public function setUp() { + parent::setUp(); + + ZendAfi_Auth::getInstance()->clearIdentity(); + + $config = Class_Profil::getCurrentProfil()->getCfgNoticeAsArray(); + $config['exemplaires']['grouper'] = '1'; + Class_Profil::getCurrentProfil()->setCfgNotice($config); + } +} + + + + class NoticeAjaxControllerCdScriptRecordWithoutLoginTest extends NoticeAjaxControllerCdScriptRecordTestCase { public function setUp() { parent::setUp();