From 5b097f1648e7e78cf9cc5cf97ddf69d47a348316 Mon Sep 17 00:00:00 2001 From: Ghislain Loas <ghislo@sandbox.pergame.net> Date: Wed, 16 Mar 2016 17:10:17 +0100 Subject: [PATCH] dev #40158 split items table when bookmarked libraries items are found --- VERSIONS_WIP/40158 | 1 + .../opac/controllers/AbonneController.php | 2 - library/Class/Bib.php | 5 + library/Class/CodifAnnexe.php | 8 +- library/Class/IntBib.php | 1 + library/Class/User/Settings.php | 7 + library/Class/Users.php | 5 + .../View/Helper/Notice/Exemplaires.php | 69 +++++- .../View/Helper/Notice/ExemplairesTable.php | 2 +- public/opac/skins/original/css/recherche.css | 2 +- .../View/Helper/Notice/ExemplairesTest.php | 225 +++++++++++++++--- 11 files changed, 283 insertions(+), 44 deletions(-) create mode 100644 VERSIONS_WIP/40158 diff --git a/VERSIONS_WIP/40158 b/VERSIONS_WIP/40158 new file mode 100644 index 00000000000..d5af0ff05c0 --- /dev/null +++ b/VERSIONS_WIP/40158 @@ -0,0 +1 @@ + - ticket #40158 : (36/40) Option 2 : Mise en favori des bibliotheques : demande fille \ No newline at end of file diff --git a/application/modules/opac/controllers/AbonneController.php b/application/modules/opac/controllers/AbonneController.php index 027e3426e86..4066f42d338 100644 --- a/application/modules/opac/controllers/AbonneController.php +++ b/application/modules/opac/controllers/AbonneController.php @@ -311,8 +311,6 @@ class AbonneController extends ZendAfi_Controller_Action { public function tagnoticeAction() { - xdebug_break(); - if (!$this->_request->isPost()) { $this->view->titre = $this->_('Proposer des tags pour cette notice'); $this->view->id = $this->_request->getParam('id_notice', 0); diff --git a/library/Class/Bib.php b/library/Class/Bib.php index a4050864852..08a2927c991 100644 --- a/library/Class/Bib.php +++ b/library/Class/Bib.php @@ -884,4 +884,9 @@ class Class_Bib extends Storm_Model_Abstract { public function getJsonLabel() { return $this->getFacetLabel(); } + + + public function includeItem($item) { + return $this->getId() == $item->getIdBib(); + } } diff --git a/library/Class/CodifAnnexe.php b/library/Class/CodifAnnexe.php index fa6288518ff..17f05f25902 100644 --- a/library/Class/CodifAnnexe.php +++ b/library/Class/CodifAnnexe.php @@ -27,7 +27,8 @@ class Class_CodifAnnexe extends Storm_Model_Abstract { protected $_table_name = 'codif_annexe', $_table_primary = 'id_annexe', - $_default_attribute_values = ['libelle' => '']; + $_default_attribute_values = ['libelle' => '', + 'id_bib' => 0]; protected $_belongs_to = [ @@ -78,5 +79,10 @@ class Class_CodifAnnexe extends Storm_Model_Abstract { public function getJsonLabel() { return $this->getLibelle(); } + + + public function includeItem($item) { + return $this->getCode() == $item->getAnnexe(); + } } ?> diff --git a/library/Class/IntBib.php b/library/Class/IntBib.php index 213b9ea1bf8..8ebef6bb466 100644 --- a/library/Class/IntBib.php +++ b/library/Class/IntBib.php @@ -75,6 +75,7 @@ class Class_IntBib extends Storm_Model_Abstract { protected $_default_attribute_values = ['nom_court' => '', 'comm_params' => '', + 'comm_sigb' => 0, 'qualite' => 0, 'sigb' => 0, 'planif_mode' => 0]; diff --git a/library/Class/User/Settings.php b/library/Class/User/Settings.php index 59b56552016..a006dd203c5 100644 --- a/library/Class/User/Settings.php +++ b/library/Class/User/Settings.php @@ -76,6 +76,13 @@ class Class_User_Settings { } + public function setBookmarkedLibraries($libraries_ids) { + $this->_user_settings[self::BOOKMARKED_LIBRARIES] = implode('-', $libraries_ids); + $this->_user->setSettings(static::serializeSettings($this->_user_settings)); + return $this->_user; + } + + public function getBookmarkedDomains() { if(!isset($this->_user_settings[self::BOOKMARKED_DOMAINS])) return []; diff --git a/library/Class/Users.php b/library/Class/Users.php index 93476584cee..b6c865abca6 100644 --- a/library/Class/Users.php +++ b/library/Class/Users.php @@ -1674,6 +1674,11 @@ class Class_Users extends Storm_Model_Abstract { } + public function setBookmarkedLibraries($libraries_ids) { + return $this->getSettingsModel()->setBookmarkedLibraries($libraries_ids); + } + + public function getRedmineLibrary() { return $this->getSettingsModel()->getRedmineLibrary(); } diff --git a/library/ZendAfi/View/Helper/Notice/Exemplaires.php b/library/ZendAfi/View/Helper/Notice/Exemplaires.php index b3e55090987..9dfd4c9adbf 100644 --- a/library/ZendAfi/View/Helper/Notice/Exemplaires.php +++ b/library/ZendAfi/View/Helper/Notice/Exemplaires.php @@ -24,26 +24,72 @@ class ZendAfi_View_Helper_Notice_Exemplaires extends ZendAfi_View_Helper_BaseHel public function Notice_Exemplaires($exemplaires, $nb_notices_oeuvre=0, $aff="normal") { $preferences = Class_Profil::getCurrentProfil()->getCfgNoticeAsArray()['exemplaires']; + if (!$exemplaires) return false; - $render = ($preferences['grouper'] == 0) ? - $this->view->Notice_Exemplaires_RenderByGroup($exemplaires, $preferences, $nb_notices_oeuvre, $aff) + return ($preferences['grouper'] == 0) + ? $this->view->Notice_Exemplaires_RenderByGroup($exemplaires, $preferences, $nb_notices_oeuvre, $aff) : $this->view->Notice_Exemplaires_RenderByItem($exemplaires, $preferences, $nb_notices_oeuvre, $aff); - - return $render; } - public function renderExemplairesTable($exemplaires, $preferences, $aff) { + protected function renderExemplairesTable($exemplaires, $preferences, $aff) { $renderers = $this->_getRenderers($exemplaires, $preferences, $aff); + $html = ''; + $bookmarked_items = $this->_getItemsInBookmarkedLibraries($exemplaires); + $other_items = array_diff($exemplaires, $bookmarked_items); + + if((!$bookmarked_items) || (!$other_items)) + return $this->_itemsTable($exemplaires, $renderers); + + + + return + $this->_decoratedItemsTable($this->_('Les exemplaires de vos bibliothèques favorites'), + $this->_itemsTable($bookmarked_items, $renderers)) + + . $this->_decoratedItemsTable($this->_('Afficher les exemplaires de cette notice dans les autres bibliothèques'), + $this->_itemsTable($other_items, $renderers, ['style' => 'display: none']), + ['onclick' => '$(this).closest(\'div\').find(\'table\').toggle();']); + } + - return $this->view - ->table($this->_renderItems($exemplaires, $renderers), - ['class' => 'exemplaires', - 'summary' => $this->_('Liste des exemplaires'), - 'cellpadding' => 5, - 'cellspacing' => 1]); + protected function _decoratedItemsTable($title, $content, $attribs = []) { + return $this->_tag('div', + $this->_tag('h3', + $title, + array_merge(['class' => 'notice_bloc_titre'], + $attribs)) + . $content); + } + + + protected function _itemsTable($items, $renderers, $attribs = []) { + return $this->view->table($this->_renderItems($items, $renderers), + array_merge(['class' => 'exemplaires', + 'summary' => $this->_('Liste des exemplaires'), + 'cellpadding' => 5, + 'cellspacing' => 1], + $attribs)); + } + + + protected function _getItemsInBookmarkedLibraries($items) { + if(!$user = Class_Users::getIdentity()) + return []; + + if(!$user_libraries = $user->getBookmarkedLibraries()) + return []; + + $selected_items = []; + foreach($items as $item) { + foreach($user_libraries as $annex_or_lib) { + if ($annex_or_lib->includeItem($item)) + $selected_items []= $item; + } + } + return $selected_items; } @@ -163,7 +209,6 @@ class ZendAfi_View_Helper_Notice_Exemplaires_RenderByGroup extends ZendAfi_View_ $group_exemplaires[$group_key]->incrementGroupCount(); } - return $this->render($group_exemplaires, $preferences, $nb_notices_oeuvre, $aff); } } diff --git a/library/ZendAfi/View/Helper/Notice/ExemplairesTable.php b/library/ZendAfi/View/Helper/Notice/ExemplairesTable.php index ce9d2f1e59b..30b41fec978 100644 --- a/library/ZendAfi/View/Helper/Notice/ExemplairesTable.php +++ b/library/ZendAfi/View/Helper/Notice/ExemplairesTable.php @@ -224,7 +224,7 @@ class ZendAfi_View_Helper_Notice_Exemplaires_Localisation extends ZendAfi_View_H $id = $exemplaire->getIdBib(); - if ($annexe=Class_CodifAnnexe::findFirstBy(['code' => $exemplaire->getAnnexe()])) + if ($annexe = Class_CodifAnnexe::findFirstBy(['code' => $exemplaire->getAnnexe()])) $id = $annexe->getIdBib(); $url = CLass_Url::absolute(['module' => 'opac', diff --git a/public/opac/skins/original/css/recherche.css b/public/opac/skins/original/css/recherche.css index 140211081c2..8b6d145542c 100644 --- a/public/opac/skins/original/css/recherche.css +++ b/public/opac/skins/original/css/recherche.css @@ -17,7 +17,7 @@ div.notice border:1px solid; border-color:#bfbfbf; } -div.notice_bloc_titre +.notice_bloc_titre { margin-top:3px; padding-left:7px; diff --git a/tests/library/ZendAfi/View/Helper/Notice/ExemplairesTest.php b/tests/library/ZendAfi/View/Helper/Notice/ExemplairesTest.php index 59228ae50f6..7ab44ac8cf3 100644 --- a/tests/library/ZendAfi/View/Helper/Notice/ExemplairesTest.php +++ b/tests/library/ZendAfi/View/Helper/Notice/ExemplairesTest.php @@ -53,16 +53,16 @@ class NoticeHtmlGetExemplairesWithOneExemplaireNoWebServiceTest extends ZendAfi_ Class_Profil::getLoader() ->newInstanceWithId(4) ->setCfgNotice(['exemplaires' => [ - 'grouper' => 0, - 'bib' => 1, - 'annexe' => 1, - 'section' => 1, - 'emplacement' => 0, - 'dispo' => 1, - 'date_retour' => 1, - 'localisation' => 1, - 'plan' => 1, - 'resa' => 1]]) + 'grouper' => 0, + 'bib' => 1, + 'annexe' => 1, + 'section' => 1, + 'emplacement' => 0, + 'dispo' => 1, + 'date_retour' => 1, + 'localisation' => 1, + 'plan' => 1, + 'resa' => 1]]) ->beCurrentProfil(); $exemplaires = [$this->fixture('Class_Exemplaire', @@ -149,7 +149,7 @@ class NoticeHtmlGetExemplairesWithOneExemplaireNoWebServiceTest extends ZendAfi_ public function pageShouldContainsLinkToDisplaySameWork() { $this->assertXPath($this->html, '//div[@class="notice_bloc_titre"][contains(@onclick, "/exemplaires-same-work/id/222")]', - $this->html); + $this->html); } /** @test **/ @@ -184,19 +184,19 @@ abstract class NoticeHtmlGetExemplairesWithOneExemplaireAndWebServiceTestCase ex ->beReservable() ->setNbReservations(4); - Class_Profil::getLoader() + Class_Profil::getLoader() ->newInstanceWithId(4) ->setCfgNotice(['exemplaires' => [ - 'grouper' => 1, - 'bib' => 1, - 'annexe' => 1, - 'section' => 1, - 'emplacement' => 1, - 'dispo' => 1, - 'date_retour' => 1, - 'localisation' => 1, - 'plan' => 1, - 'resa' => 1]]) + 'grouper' => 1, + 'bib' => 1, + 'annexe' => 1, + 'section' => 1, + 'emplacement' => 1, + 'dispo' => 1, + 'date_retour' => 1, + 'localisation' => 1, + 'plan' => 1, + 'resa' => 1]]) ->beCurrentProfil(); @@ -238,7 +238,7 @@ abstract class NoticeHtmlGetExemplairesWithOneExemplaireAndWebServiceTestCase ex class NoticeHtmlGetExemplairesWithOneExemplaireAndWebServiceTest -extends NoticeHtmlGetExemplairesWithOneExemplaireAndWebServiceTestCase { + extends NoticeHtmlGetExemplairesWithOneExemplaireAndWebServiceTestCase { public function setUp() { parent::setUp(); @@ -269,13 +269,15 @@ extends NoticeHtmlGetExemplairesWithOneExemplaireAndWebServiceTestCase { - /** @test **/ + /** @test **/ public function withOutEditionCoteColonneTitleShoudBeCote() { $this->assertNotXPathContentContains($this->html, '//th', utf8_encode('<span>(Edition)</span>'),$this->html); } } + + class NoticeHtmlGetExemplairesWithOneExemplairesAndWebServiceAndEditionTest extends NoticeHtmlGetExemplairesWithOneExemplaireAndWebServiceTestCase { public function setup() { @@ -300,9 +302,8 @@ class NoticeHtmlGetExemplairesWithOneExemplairesAndWebServiceAndEditionTest exte - class NoticeHtmlGetExemplairesWithOneExemplaireAndWebServiceAndPickupActiveTest -extends NoticeHtmlGetExemplairesWithOneExemplaireAndWebServiceTestCase { + extends NoticeHtmlGetExemplairesWithOneExemplaireAndWebServiceTestCase { public function setUp() { @@ -321,4 +322,174 @@ extends NoticeHtmlGetExemplairesWithOneExemplaireAndWebServiceTestCase { } } -?> \ No newline at end of file + + +class ExemplairesWithBookmarkedLibraryTest extends ViewHelperTestCase { + protected $_storm_default_to_volatile = true; + + public function setUp() { + parent::setUp(); + + $this->_helper = new ZendAfi_View_Helper_Notice_Exemplaires(); + $this->_helper->setView(new ZendAfi_Controller_Action_Helper_View()); + + $this->fixture('Class_Bib', + ['id' => 654321, + 'libelle' => 'Admo Library']); + + $this->fixture('Class_Bib', + ['id' => 12389, + 'libelle' => 'Bilo Library']); + + $user = $this->fixture('Class_Users', + ['id' => 89, + 'login' => 'Once upon a time', + 'password' => 'A nude monkey ... ?', + 'id_site' => '654321', + 'idabon' => '456789', + 'role_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB]); + + $user->setBookmarkedLibraries([654321]); + + ZendAfi_Auth::getInstance()->logUser($user); + + $items = [ $this->fixture('Class_Exemplaire', + ['id' => 12, + 'id_bib' => 654321, + 'id_int_bib' => 1, + 'id_notice' => '24765', + 'id_origine' => '666', + 'annexe' => 'MOUL', + 'cote' => 'DSEM', + 'dispo' => "Disponible", + 'code_barres' => "12345", + 'section' => 3, + 'emplacement' => 2, + 'nb_resas'=>0]), + + $this->fixture('Class_Exemplaire', + ['id' => 65, + 'id_bib' => 12389, + 'id_int_bib' => 1, + 'id_notice' => '24765', + 'id_origine' => '666', + 'annexe' => 'MOUL', + 'cote' => 'DSEM', + 'dispo' => "Disponible", + 'code_barres' => "12345", + 'section' => 3, + 'emplacement' => 2, + 'nb_resas'=> 0]) + ]; + + $this->html = $this->_helper->Notice_Exemplaires($items); + } + + + + /** @test */ + public function pageShouldContainsTwoItemsTable() { + $this->assertXPathCount($this->html, '//div/table', 2); + } +} + + + + +class ExemplairesWithBookmarkedAnnexTest extends ViewHelperTestCase { + protected $_storm_default_to_volatile = true; + + public function setUp() { + parent::setUp(); + + $profil = Class_Profil::getCurrentProfil(); + $profil->setCfgNotice(['exemplaires' => [ + 'grouper' => 0, + 'bib' => 0, + 'annexe' => 1, + 'section' => 1, + 'emplacement' => 0, + 'dispo' => 1, + 'date_retour' => 1, + 'localisation' => 1, + 'plan' => 1, + 'resa' => 1]]); + + $this->_helper = new ZendAfi_View_Helper_Notice_Exemplaires(); + $this->_helper->setView(new ZendAfi_Controller_Action_Helper_View()); + + $this->fixture('Class_CodifAnnexe', + ['id' => 654321, + 'code' => 'Admo', + 'libelle' => 'Admo Library']); + + $this->fixture('Class_CodifAnnexe', + ['id' => 12389, + 'libelle' => 'Bilo Library']); + + $this->fixture('Class_IntBib', + ['id' => 654321, + 'libelle' => 'Admo Library']); + + $this->fixture('Class_IntBib', + ['id' => 12389, + 'libelle' => 'Bilo Library']); + + $user = $this->fixture('Class_Users', + ['id' => 89, + 'login' => 'Once upon a time', + 'password' => 'A nude monkey ... ?', + 'id_site' => '654321', + 'idabon' => '456789', + 'role_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB]); + + $user->setBookmarkedLibraries([654321]); + + ZendAfi_Auth::getInstance()->logUser($user); + + $first_item = $this->fixture('Class_Exemplaire', + ['id' => 12, + 'id_bib' => '', + 'id_int_bib' => 12389, + 'id_notice' => '24765', + 'id_origine' => '666', + 'annexe' => 'Admo', + 'cote' => 'DSEM', + 'dispo' => "Disponible", + 'code_barres' => "12345", + 'section' => 3, + 'emplacement' => 2, + 'nb_resas'=>0]); + + $second_item = $this->fixture('Class_Exemplaire', + ['id' => 65, + 'id_bib' => '', + 'id_int_bib' => 654321, + 'id_notice' => '24765', + 'id_origine' => '666', + 'annexe' => 'MOUL', + 'cote' => 'COTE', + 'dispo' => "Disponible", + 'code_barres' => "12345", + 'section' => 3, + 'emplacement' => 2, + 'nb_resas'=> 0]); + + $items = [$first_item, + $second_item]; + + $this->html = $this->_helper->Notice_Exemplaires($items); + } + + + /** @test */ + public function pageShouldContainsTwoItemsTable() { + $this->assertXPathCount($this->html, '//div/table', 2); + } + + + /** @test */ + public function pageShouldContainsTwoNoticeBlocTitre() { + $this->assertXPathCount($this->html, '//div/h3[@class="notice_bloc_titre"]', 2); + } +} \ No newline at end of file -- GitLab