From d50d9163de9347d6945212a9715fc9f48b9ccd09 Mon Sep 17 00:00:00 2001 From: Ghislain Loas <ghislo@sandbox.pergame.net> Date: Mon, 2 Nov 2015 14:14:50 +0100 Subject: [PATCH] dev #5524 start implementing --- .../opac/controllers/NoticeajaxController.php | 16 ++- library/Class/Codification.php | 57 ++++----- library/Class/Onglet.php | 57 +++++++++ .../ZendAfi/View/Helper/Notice/Analytics.php | 44 +------ .../controllers/NoticeAjaxControllerTest.php | 15 ++- .../controllers/RechercheControllerTest.php | 108 ++++++++++++++++++ 6 files changed, 221 insertions(+), 76 deletions(-) diff --git a/application/modules/opac/controllers/NoticeajaxController.php b/application/modules/opac/controllers/NoticeajaxController.php index 1d1c1a69cc5..7d0b6cbf738 100644 --- a/application/modules/opac/controllers/NoticeajaxController.php +++ b/application/modules/opac/controllers/NoticeajaxController.php @@ -175,11 +175,6 @@ class NoticeAjaxController extends Zend_Controller_Action { return; } - if ('' != ($html = $this->view->Notice_Analytics($notice))) { - $this->_sendResponseWithScripts($html); - return; - } - if ($notice->isPeriodique()) { $periodiques = $this->notice->getArticlesPeriodique($this->id_notice); $this->_sendResponseWithScripts($this->notice_html->getArticlesPeriodique($periodiques)); @@ -190,6 +185,17 @@ class NoticeAjaxController extends Zend_Controller_Action { } + public function recountsAction() { + if (!$notice = Class_Notice::find($this->id_notice)) { + $this->_sendResponse(''); + return; + } + + $this->_sendResponseWithScripts($this->view->Notice_Analytics($notice)); + return; + } + + public function similairesAction() { $notices = $this->notice->getNoticesSimilaires(); $html = $this->notice_html->getListeNotices($notices, $this->view); diff --git a/library/Class/Codification.php b/library/Class/Codification.php index 647bde19676..2a1fb7ffd4e 100644 --- a/library/Class/Codification.php +++ b/library/Class/Codification.php @@ -91,14 +91,14 @@ class Class_Codification { if($tous == true) $combo.='<option value="">tous</option>'; $v=explode(chr(13).chr(10),$data); for($i=0; $i<count($v); $i++) - { - $elem=explode(":",$v[$i]); - if(trim($elem[0])>"") { - if($valeur==$elem[0]) $selected=" selected"; else $selected=""; - $combo.='<option value="'.$elem[0].'"'.$selected.'>'.stripSlashes($elem[1]).'</option>'; + $elem=explode(":",$v[$i]); + if(trim($elem[0])>"") + { + if($valeur==$elem[0]) $selected=" selected"; else $selected=""; + $combo.='<option value="'.$elem[0].'"'.$selected.'>'.stripSlashes($elem[1]).'</option>'; + } } - } $combo.='</select>'; return $combo; } @@ -240,23 +240,24 @@ class Class_Codification { $translate = Zend_Registry::get('translate'); $this->_nom_onglets = [ - "detail" => Class_Onglet::forLibelleAndType($translate->_("Description du document"),'detail'), - "avis" => Class_Onglet::forLibelleAndType($translate->_("Critiques"),'avis'), - "exemplaires" => Class_Onglet::forLibelleAndType($translate->_("Exemplaires"),'exemplaires'), - "resume" => Class_Onglet::forLibelleAndType($translate->_("Résumés"),'resume'), - "tags" => Class_Onglet::forLibelleAndType($translate->_("Rebondir dans le catalogue"),'tags'), - "biographie" => Class_Onglet::forLibelleAndType($translate->_("Biographie de l'auteur"),'biographie'), - "series" => Class_Onglet::forLibelleAndType($translate->_("Documents de la même série"),'series')->setDisplayMethod('checkIfClefChapeauExists'), + "detail" => Class_Onglet::forLibelleAndType($translate->_("Description du document"),'detail'), + "avis" => Class_Onglet::forLibelleAndType($translate->_("Critiques"),'avis'), + "exemplaires" => Class_Onglet::forLibelleAndType($translate->_("Exemplaires"),'exemplaires'), + "resume" => Class_Onglet::forLibelleAndType($translate->_("Résumés"),'resume'), + "tags" => Class_Onglet::forLibelleAndType($translate->_("Rebondir dans le catalogue"),'tags'), + "biographie" => Class_Onglet::forLibelleAndType($translate->_("Biographie de l'auteur"),'biographie'), + "series" => Class_Onglet::forLibelleAndType($translate->_("Documents de la même série"),'series')->setDisplayMethod('checkIfClefChapeauExists'), // "auteur" => Class_Onglet::forLibelleAndType($translate->_("Documents du même auteur"),'auteur'), - "similaires" => Class_Onglet::forLibelleAndType($translate->_("Documents similaires"),'similaires'), - "bibliographie" => Class_Onglet::forLibelleAndType($translate->_("Discographie"),'bibliographie'), - "morceaux" => Class_Onglet::forLibelleAndType($translate->_("Morceaux"),'morceaux'), - "bandeAnnonce" => Class_Onglet::forLibelleAndType($translate->_("Bande-annonce"),'bandeAnnonce'), - "photos" => Class_Onglet::forLibelleAndType($translate->_("Photos"),'photos'), - "videos" => Class_Onglet::forLibelleAndType($translate->_("Archives vidéo"),'videos'), - "resnumeriques" => Class_Onglet::forLibelleAndType($translate->_("Ressources numériques"),'resnumeriques')->setDisplayMethod('checkIfHasRessourcesNumeriques'), - "babeltheque" => Class_Onglet::forLibelleAndType($translate->_('Babelthèque'),'babeltheque'), - 'frbr' => Class_Onglet::forLibelleAndType($translate->_('Notices liées'),'frbr')->setDisplayMethod('checkIfHasNoticesLiees')]; + "similaires" => Class_Onglet::forLibelleAndType($translate->_("Documents similaires"),'similaires'), + "bibliographie" => Class_Onglet::forLibelleAndType($translate->_("Discographie"),'bibliographie'), + "morceaux" => Class_Onglet::forLibelleAndType($translate->_("Morceaux"),'morceaux'), + "bandeAnnonce" => Class_Onglet::forLibelleAndType($translate->_("Bande-annonce"),'bandeAnnonce'), + "photos" => Class_Onglet::forLibelleAndType($translate->_("Photos"),'photos'), + "videos" => Class_Onglet::forLibelleAndType($translate->_("Archives vidéo"),'videos'), + "resnumeriques" => Class_Onglet::forLibelleAndType($translate->_("Ressources numériques"),'resnumeriques')->setDisplayMethod('checkIfHasRessourcesNumeriques'), + "babeltheque" => Class_Onglet::forLibelleAndType($translate->_('Babelthèque'),'babeltheque'), + 'frbr' => Class_Onglet::forLibelleAndType($translate->_('Notices liées'),'frbr')->setDisplayMethod('checkIfHasNoticesLiees'), + 'recounts' => Class_Onglet::forLibelleAndType($this->_('Dépouillements'), 'recounts')->setDisplayMethod('checkIfHasRecounts')]; } @@ -283,12 +284,12 @@ class Class_Codification { $message = 'Voir tous les tomes'; switch ($notice->getTypeDoc()) { - case Class_TypeDoc::PERIODIQUE: - $message = 'Voir tous les numéros'; - break; - case Class_TypeDoc::DVD: - $message = 'Voir tous les épisodes'; - break; + case Class_TypeDoc::PERIODIQUE: + $message = 'Voir tous les numéros'; + break; + case Class_TypeDoc::DVD: + $message = 'Voir tous les épisodes'; + break; } return self::concatLibelleWithTitreChapeau($message, $notice->getTitreChapeau()); diff --git a/library/Class/Onglet.php b/library/Class/Onglet.php index 73e66fad924..4f62278dc45 100644 --- a/library/Class/Onglet.php +++ b/library/Class/Onglet.php @@ -23,6 +23,13 @@ class Class_Onglet { use Trait_Singleton, Trait_Translator; + const PREF_ANALYTICS = 'analytics'; + const PREF_ANALYTICS_TITLE = 'analytics_title'; + const PREF_ANALYTICS_AUTHORS = 'analytics_authors'; + + const FIELD_NAME = 'code'; + const FIELD_VALUE= 'valeur'; + protected $libelle; protected $function_name = 'alwaysDisplay'; @@ -117,6 +124,56 @@ class Class_Onglet { } + public function checkIfHasRecounts($record) { + return !empty(self::getRecounts($record)); + } + + + public static function getRecounts($record) { + if (!$record) + return []; + + $profil = Class_Profil::getCurrentProfil(); + $preferences = $profil + ->getCfgModulesPreferences('recherche', 'viewnotice', $record->getTypeDoc()); + + xdebug_break(); + + $analytics_field = $preferences[self::PREF_ANALYTICS]; + $title_field = $preferences[self::PREF_ANALYTICS_TITLE]; + $authors_field = explode(';', $preferences[self::PREF_ANALYTICS_AUTHORS]); + + if (!$analytics_field || !is_array($authors_field)) + return ''; + + $analytics = $record->get_subfield($analytics_field); + if (empty($analytics)) + return ''; + + $items = []; + foreach ($analytics as $analytic) { + $item = new ZendAfi_View_Helper_Notice_AnalyticsItem(); + $subfields = $record->decoupe_bloc_champ($analytic); + foreach ($subfields as $subfield) { + if ($title_field == $subfield[self::FIELD_NAME]) { + $item->setTitle($subfield[self::FIELD_VALUE]); + continue; + } + + if (in_array($subfield[self::FIELD_NAME], $authors_field)) + $item->addAuthor($subfield[self::FIELD_VALUE]); + } + if ($item->isValid()) + $items[] = $item; + } + + if (empty($items)) + return []; + + return $items; + } + + public function setDisplayMode($display) { $this->display = $display; return $this; diff --git a/library/ZendAfi/View/Helper/Notice/Analytics.php b/library/ZendAfi/View/Helper/Notice/Analytics.php index 5f8cb1275d5..761e149a42e 100644 --- a/library/ZendAfi/View/Helper/Notice/Analytics.php +++ b/library/ZendAfi/View/Helper/Notice/Analytics.php @@ -16,55 +16,15 @@ * * 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 ZendAfi_View_Helper_Notice_Analytics extends Zend_View_Helper_HtmlElement { use Trait_Translator; - const PREF_ANALYTICS = 'analytics'; - const PREF_ANALYTICS_TITLE = 'analytics_title'; - const PREF_ANALYTICS_AUTHORS = 'analytics_authors'; - - const FIELD_NAME = 'code'; - const FIELD_VALUE= 'valeur'; - public function notice_analytics($notice) { - if (!$notice) - return ''; - - $preferences = Class_Profil::getCurrentProfil() - ->getCfgModulesPreferences('recherche', 'viewnotice', $notice->getTypeDoc()); - - $analytics_field = $preferences[self::PREF_ANALYTICS]; - $title_field = $preferences[self::PREF_ANALYTICS_TITLE]; - $authors_field = explode(';', $preferences[self::PREF_ANALYTICS_AUTHORS]); - - if (!$analytics_field || !is_array($authors_field)) - return ''; - - $analytics = $notice->get_subfield($analytics_field); - if (empty($analytics)) - return ''; - - $items = []; - foreach ($analytics as $analytic) { - $item = new ZendAfi_View_Helper_Notice_AnalyticsItem(); - $subfields = $notice->decoupe_bloc_champ($analytic); - foreach ($subfields as $subfield) { - if ($title_field == $subfield[self::FIELD_NAME]) { - $item->setTitle($subfield[self::FIELD_VALUE]); - continue; - } - - if (in_array($subfield[self::FIELD_NAME], $authors_field)) - $item->addAuthor($subfield[self::FIELD_VALUE]); - } - if ($item->isValid()) - $items[] = $item; - } - + $items = Class_Onglet::getRecounts($notice); if (empty($items)) return ''; diff --git a/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php b/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php index 71713966f8d..6c41c5e6635 100644 --- a/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php +++ b/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php @@ -2146,4 +2146,17 @@ class NoticeAjaxControllerRessourceEpubPictoTypeTest extends AbstractControllerT } } -?> \ No newline at end of file + + +class NoticeAjaxControllerRecountsTest extends AbstractControllerTestCase { + public function setUp() { + parent::setUp(); + $this->dispatch('/noticeajax/recounts/'); + } + + + /** @test */ + public function recountsShouldBePresent() { + $this->assertXpath('//ul/li'); + } +} \ No newline at end of file diff --git a/tests/application/modules/opac/controllers/RechercheControllerTest.php b/tests/application/modules/opac/controllers/RechercheControllerTest.php index edd9cb8db69..ba408de6c6c 100644 --- a/tests/application/modules/opac/controllers/RechercheControllerTest.php +++ b/tests/application/modules/opac/controllers/RechercheControllerTest.php @@ -856,6 +856,10 @@ class RechercheControllerViewNoticeAndResnumeriqueTabAsAdminTest extends Recherc 'aff' => '1', 'ordre' => 1, 'largeur' => 10], + 'recounts' => ['titre' => 'Dépouillements', + 'aff' => '1', + 'ordre' => '190', + 'largeur' => 12], 'avis' => ['titre' => 'avis', 'aff' => '1', 'ordre' => 2, @@ -936,6 +940,108 @@ class RechercheControllerViewNoticeAndResnumeriqueTabAsAdminTest extends Recherc +class RechercheControllerViewNoticeAndRecountsTest extends RechercheControllerNoticeTestCase { + public function setUp() { + parent::setUp(); + Class_Users::getIdentity()->beAdminPortail(); + + $preferences = ['barre_nav' => 'Document', + 'entete' =>"ABCDEFGIKLMNOPRSTtYZ8v9", + 'analytics' => '464', + 'analytics_title' => 'a', + 'analytics_authors' => 'f', + 'onglets' => ['detail' => ['titre' => 'Details', + 'aff' => '1', + 'ordre' => 1, + 'largeur' => 10], + 'recounts' => ['titre' => 'Depouillements', + 'aff' => '1', + 'ordre' => '190', + 'largeur' => 12], + 'avis' => ['titre' => 'avis', + 'aff' => '1', + 'ordre' => 2, + 'largeur' => 10], + 'exemplaires' => ['titre' => 'exemplaires', + 'aff' => '2', + 'ordre' => 3, + 'largeur' => 10], + 'resume' => ['titre' => 'resume', + 'aff' => '2', + 'ordre' => 4, + 'largeur' => 10], + 'tags' => ['titre' => 'tags', + 'aff' => '2', + 'ordre' => 5, + 'largeur' => 10], + 'biographie' => ['titre' => 'biographie', + 'aff' => '2', + 'ordre' => 6, + 'largeur' => 10], + 'similaires' => ['titre' => 'similaires', + 'aff' => '2', + 'ordre' => 7, + 'largeur' => 10], + 'bibliographie' => ['titre' => 'bibliographie', + 'aff' => '3', + 'ordre' => 7, + 'largeur' => 10], + 'morceaux' => ['titre' => 'morceaux', + 'aff' => '3', + 'ordre' => 8, + 'largeur' => 10], + 'bandeAnnonce' => ['titre' => 'bande annonce', + 'aff' => '3', + 'ordre' => 9, + 'largeur' => 10], + 'photos' => ['titre' => 'photos', + 'aff' => '3', + 'ordre' => 14, + 'largeur' => 10], + 'videos' => ['titre' => 'videos', + 'aff' => '3', + 'ordre' => 11, + 'largeur' => 10], + 'resnumeriques' => ['titre' => 'ressources n', + 'aff' => '2', + 'ordre' => 12, + 'largeur' => 10], + 'babeltheque' => ['titre' => 'babeltheque', + 'aff' => '3', + 'ordre' => 13, + 'largeur' => 10], + 'frbr' => ['titre' => 'frbr', + 'aff' => '0', + 'ordre' => 10, + 'largeur' => 10], + 'serie' => ['titre' => 'serie', + 'aff' => '0', + 'ordre' => 11, + 'largeur' => 10]], + 'boite' => null]; + + Class_Profil::beVolatile(); + $this->fixture('Class_Profil', ['id' => 1, + 'libelle' => 'Afibre']) + ->setBarreNavOn(true) + ->setCfgModules(['recherche' => ['viewnotice1' => $preferences]]) + ->beCurrentProfil(); + + $this->fixture('Class_Notice', + ['id' => 12, + 'type_doc' => Class_TypeDoc::LIVRE, + 'unimarc' => '00490nls0 2200193 450 0010003000000050009000030110013000121000041000251010008000661100008000742000026000822070018001082100013001263000041001393260015001804610017001954640050002128010034002629420051221 a12928429 a20051221a20059999m 0fre 0103 0 afre aaga1 aMobiClici21/06/2005 0a74,21/06/2005 d20050621 amagazine de connaissances sur CD-ROM aBimestriel tMobiClicv74 1aUne journée avec les orquesfNior, Annabelle 1aFRbc20051221wBiblixNet 2.0']); + $this->dispatch('recherche/viewnotice/id/12', true); + } + + + /** @test */ + public function recountsTabShouldBePresent() { + $this->assertXpathContentContains('//div', 'Dépouillements', $this->_response->getBody()); + } +} + + class RechercheControllerReadNoticeTest extends RechercheControllerNoticeTestCase { public function setUp() { @@ -2874,6 +2980,8 @@ class RechercheControlleSimpleActionWithEmptyDomainSettingsAndArticlesLinkedTest } } + + class RechercheControllerSimpleActionDisableSuggestionTest extends RechercheControllerNoticeTestCase { -- GitLab