From 72ea8b2f752041baea6a65ce8214c529aa77d40e Mon Sep 17 00:00:00 2001 From: Ghislain Loas <ghislo@sandbox.pergame.net> Date: Mon, 2 Nov 2015 15:06:28 +0100 Subject: [PATCH] dev #5524 move analytics to onglet_analytics --- library/Class/Onglet.php | 51 +------------------ .../ZendAfi/View/Helper/Notice/Analytics.php | 34 +------------ .../controllers/RechercheControllerTest.php | 2 +- 3 files changed, 4 insertions(+), 83 deletions(-) diff --git a/library/Class/Onglet.php b/library/Class/Onglet.php index 4f62278dc45..ae8e5c57be0 100644 --- a/library/Class/Onglet.php +++ b/library/Class/Onglet.php @@ -23,10 +23,6 @@ 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'; @@ -125,52 +121,7 @@ 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; + return !empty(Class_Onglet_Analytics::getRecounts($record)); } diff --git a/library/ZendAfi/View/Helper/Notice/Analytics.php b/library/ZendAfi/View/Helper/Notice/Analytics.php index 761e149a42e..c54dd282642 100644 --- a/library/ZendAfi/View/Helper/Notice/Analytics.php +++ b/library/ZendAfi/View/Helper/Notice/Analytics.php @@ -24,11 +24,11 @@ class ZendAfi_View_Helper_Notice_Analytics extends Zend_View_Helper_HtmlElement use Trait_Translator; public function notice_analytics($notice) { - $items = Class_Onglet::getRecounts($notice); + $items = Class_Onglet_Analytics::getRecounts($notice); if (empty($items)) return ''; - $html = '<h3 class"notice_info_ligne_titre">' . $this->_('Contient') . '</h3><ul><li>'; + $html = '<ul><li>'; $items_html = array_map(function ($item) {return $item->html();}, $items); $html .= implode('</li><li>', $items_html); @@ -36,34 +36,4 @@ class ZendAfi_View_Helper_Notice_Analytics extends Zend_View_Helper_HtmlElement return $html; } } - - -class ZendAfi_View_Helper_Notice_AnalyticsItem { - protected $_title, $_authors=[]; - - public function setTitle($title) { - $this->_title = $title; - } - - - public function addAuthor($author) { - $this->_authors[] = $author; - } - - - public function isValid() { - return '' != $this->_title; - } - - - public function html() { - if (!$this->isValid()) - return ''; - - return $this->_title - . ((!empty($this->_authors)) - ? ' / ' . implode(' / ', $this->_authors) - : ''); - } -} ?> \ 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 ba408de6c6c..497aa0e35a8 100644 --- a/tests/application/modules/opac/controllers/RechercheControllerTest.php +++ b/tests/application/modules/opac/controllers/RechercheControllerTest.php @@ -1037,7 +1037,7 @@ class RechercheControllerViewNoticeAndRecountsTest extends RechercheControllerNo /** @test */ public function recountsTabShouldBePresent() { - $this->assertXpathContentContains('//div', 'Dépouillements', $this->_response->getBody()); + $this->assertXpathContentContains('//div//h2', 'Depouillements', $this->_response->getBody()); } } -- GitLab