From 74b047a8e97b5dc471595417db6398e72a3d64f6 Mon Sep 17 00:00:00 2001 From: gloas <gloas@afi-sa.fr> Date: Mon, 6 Mar 2017 15:59:22 +0100 Subject: [PATCH] hotline #56622 fix rt comment --- library/Class/CodifAuteur.php | 19 +++++++++++ library/ZendAfi/View/Helper/AuthorAnchor.php | 12 +++---- .../ZendAfi/View/Helper/AuthorAnchorTest.php | 32 +++++++++++++------ 3 files changed, 46 insertions(+), 17 deletions(-) diff --git a/library/Class/CodifAuteur.php b/library/Class/CodifAuteur.php index 759737f2bb8..b6b0c088d0a 100644 --- a/library/Class/CodifAuteur.php +++ b/library/Class/CodifAuteur.php @@ -21,6 +21,25 @@ class CodifAuteurLoader extends Storm_Model_Loader { + public function findWithFullName($author) { + if(!$author) + return null; + + $indexation = new Class_Indexation(); + $alpha_author = $indexation->alphaMaj($author); + + if(1 == count(($names = explode(' ', $author)))) + return Class_CodifAuteur::findByCodeAlpha($alpha_author); + + if(2 < count($names)) + return Class_CodifAuteur::findFirstBy(['libelle' => $alpha_author]); + + return ($found = Class_CodifAuteur::findByLastNameFirstName($names[0], $names[1])) + ? $found + : Class_CodifAuteur::findByLastNameFirstName($names[1], $names[0]); + } + + public function findByLastNameFirstName($lastname, $firstname) { $code_alpha = str_replace(' ', 'x', diff --git a/library/ZendAfi/View/Helper/AuthorAnchor.php b/library/ZendAfi/View/Helper/AuthorAnchor.php index c0fe579e12b..73d83fa7121 100644 --- a/library/ZendAfi/View/Helper/AuthorAnchor.php +++ b/library/ZendAfi/View/Helper/AuthorAnchor.php @@ -26,13 +26,11 @@ class ZendAfi_View_Helper_AuthorAnchor extends ZendAfi_View_Helper_BaseHelper { if(!$author) return ''; - if(!$facet = Class_CodifAuteur::findFirstBy(['libelle' => (new Class_Indexation())->alphaMaj($author)])) - return $author; - - $params = array_merge(['controller' => 'recherche', - 'action' => 'simple', - 'facette' => Class_CodifAuteur::CODE_FACETTE . $facet->getId()], - $params); + if($facet = Class_CodifAuteur::findWithFullName($author)) + $params = array_merge(['controller' => 'recherche', + 'action' => 'simple', + 'facette' => Class_CodifAuteur::CODE_FACETTE . $facet->getId()], + $params); return $this->view->tagAnchor($this->view->url($params, null, true), $author); diff --git a/tests/library/ZendAfi/View/Helper/AuthorAnchorTest.php b/tests/library/ZendAfi/View/Helper/AuthorAnchorTest.php index 0cb81ecc94f..6b508ab7d5d 100644 --- a/tests/library/ZendAfi/View/Helper/AuthorAnchorTest.php +++ b/tests/library/ZendAfi/View/Helper/AuthorAnchorTest.php @@ -27,13 +27,26 @@ class ZendAfi_View_Helper_AnchorAuthorSimpleTest extends ViewHelperTestCase { public function setup() { parent::setUp(); - $this->fixture('Class_CodifAuteur', - ['id' => 10, - 'libelle' => 'STEPHANIE BRISSON']); + $brisson = $this->fixture('Class_CodifAuteur', + ['id' => 10, + 'libelle' => 'Stéphanie BRISSON', + 'formes' => 'BRISSONxSTEPHANIE']); + + $kondu = $this->fixture('Class_CodifAuteur', + ['id' => 11, + 'libelle' => 'Marie Kond?', + 'formes' => 'KONDxxMARIE']); + + $this->onLoaderOfModel('Class_CodifAuteur') + + ->whenCalled('findByLastNameFirstName') + ->with('Stéphanie', 'BRISSON') + ->answers($brisson) + + ->whenCalled('findByLastNameFirstName') + ->with('Marie', 'KondÅ') + ->answers($kondu); - $this->fixture('Class_CodifAuteur', - ['id' => 11, - 'libelle' => 'MARIE KOND?']); $this->_helper = new ZendAfi_View_Helper_AuthorAnchor(); $this->_helper->setView(new ZendAfi_Controller_Action_Helper_View()); @@ -47,8 +60,7 @@ class ZendAfi_View_Helper_AnchorAuthorSimpleTest extends ViewHelperTestCase { /** @test */ - public function shouldNotReturnAnchor() { - $this->assertEquals('Marie KondÅ', $this->_helper->authorAnchor('Marie KondÅ')); + public function shouldReturnAnchorWithFacetA11() { + $this->assertContains('/recherche/simple/facette/A11">Marie KondÅ</a>', $this->_helper->authorAnchor('Marie KondÅ')); } -} -?> \ No newline at end of file +} \ No newline at end of file -- GitLab