From 9b7b740b21ec18f76afe5639c90f93efd152f469 Mon Sep 17 00:00:00 2001 From: pbarroca <pbarroca@afi-sa.fr> Date: Mon, 8 Dec 2014 18:49:43 +0100 Subject: [PATCH] fix #16741 : give priority to 330$a that contains html tags while detecting summary to display --- ...ine_#17941_fix_noreply_adress_workflow_cms | 3 -- library/Class/Notice.php | 47 +++++++++++++++---- .../controllers/NoticeAjaxControllerTest.php | 18 +++++++ 3 files changed, 55 insertions(+), 13 deletions(-) delete mode 100644 VERSIONS_HOTLINE/hotline_#17941_fix_noreply_adress_workflow_cms diff --git a/VERSIONS_HOTLINE/hotline_#17941_fix_noreply_adress_workflow_cms b/VERSIONS_HOTLINE/hotline_#17941_fix_noreply_adress_workflow_cms deleted file mode 100644 index b8e811d20b5..00000000000 --- a/VERSIONS_HOTLINE/hotline_#17941_fix_noreply_adress_workflow_cms +++ /dev/null @@ -1,3 +0,0 @@ -- ticket hotline #17941 - - Workflow de création des articles - - correction de l'adresse email utilisée pour envoyer les messages de trnasition d'état (no-reply@afi-sa.fr) \ No newline at end of file diff --git a/library/Class/Notice.php b/library/Class/Notice.php index 67b81992a84..0b62a560662 100644 --- a/library/Class/Notice.php +++ b/library/Class/Notice.php @@ -1341,9 +1341,6 @@ class Class_Notice extends Storm_Model_Abstract { } -// ---------------------------------------------------------------- -// Résumé -// ---------------------------------------------------------------- public function getResume() { if (isset($this->_resume)) return $this->_resume; @@ -1351,15 +1348,45 @@ class Class_Notice extends Storm_Model_Abstract { if ($album = $this->getAlbum()) return $album->getDescription(); - $resume = ''; - $data = $this->get_subfield("330", "a"); - foreach ($data as $item) - if (strlen($item) > strlen($resume)) $resume = trim($item); + $data = $this->get_subfield('330', 'a'); + return $this->_resume = ($resume = $this->_getHtmlSummary($data)) ? + $resume : $this->_getTextSummary($data); + } + + + protected function _getHtmlSummary($values) { + return $this->_getSummaryWith( + $values, + function($value) { + return $this->_containsTags($value); + }); + } + + + protected function _getTextSummary($values) { + $summary = $this->_getSummaryWith( + $values, + function($value) { + return !$this->_containsTags($value); + }); + + if ($summary && substr($summary, -1) != '.') + $summary .= '.'; + return $summary; + } + + + protected function _getSummaryWith($values, $closure) { + $summary = ''; + foreach($values as $value) + if ($closure($value) && strlen($value) > strlen($summary)) + $summary = $value; + return $summary; + } - if ($resume && substr($resume, -1) != ".") - $resume.="."; - return $this->_resume = $resume; + protected function _containsTags($value) { + return $value != (new Zend_Filter_StripTags())->filter($value); } diff --git a/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php b/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php index 1933eb0f69d..f89d9e5c1a0 100644 --- a/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php +++ b/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php @@ -386,6 +386,24 @@ class NoticeAjaxControllerInterviewsTest extends AbstractControllerTestCase { } + + +/** @see http://forge.afi-sa.fr/issues/16741 */ +class NoticeAjaxControllerResumeGamWidgetTest extends AbstractControllerTestCase { + /** @test */ + public function shouldDisplayGamWidget() { + $this->fixture('Class_Notice', + ['id' => 3800226, + 'unimarc' => file_get_contents(dirname(__FILE__) + . '/sous_la_peau.uni')]); + $this->dispatch('noticeajax/resume/id/3800226', true); + $this->assertXPath('//iframe[contains(@src, "gamannecy.com")]', + $this->_response->getBody()); + } +} + + + class NoticeAjaxControllerResumeAlbumTest extends AbstractControllerTestCase { protected $_notice; -- GitLab