From 7b97d18d1fc697bd2b959e188d9034a7da233706 Mon Sep 17 00:00:00 2001 From: efalcy <efalcy@afi-sa.fr> Date: Tue, 26 Feb 2019 11:27:52 +0100 Subject: [PATCH] hotline#87609 : display custom_fields in article_info DL --- cosmogramme/VERSIONS_HOTLINE/87609 | 1 + library/Class/CustomField/Value.php | 5 +++ .../ZendAfi/View/Helper/TagArticleInfo.php | 32 +++++++++++++------ .../CmsControllerCalendarActionTest.php | 4 +-- .../opac/controllers/CmsControllerTest.php | 32 +++++++++++++++++++ 5 files changed, 63 insertions(+), 11 deletions(-) create mode 100644 cosmogramme/VERSIONS_HOTLINE/87609 diff --git a/cosmogramme/VERSIONS_HOTLINE/87609 b/cosmogramme/VERSIONS_HOTLINE/87609 new file mode 100644 index 00000000000..36c41e0c9d5 --- /dev/null +++ b/cosmogramme/VERSIONS_HOTLINE/87609 @@ -0,0 +1 @@ + - ticket #87609 : Possibilité d'afficher des champs personnalisés dans les articles CMS (en display:none par défaut) \ No newline at end of file diff --git a/library/Class/CustomField/Value.php b/library/Class/CustomField/Value.php index 7a2a77c0226..e4a740744ea 100644 --- a/library/Class/CustomField/Value.php +++ b/library/Class/CustomField/Value.php @@ -63,6 +63,11 @@ class Class_CustomField_Value extends Storm_Model_Abstract { } + public function getFieldId() { + return $this->getField()->getId(); + } + + public function getOptionsListAsArray() { return $this->getField()->getOptionsListAsArray(); } diff --git a/library/ZendAfi/View/Helper/TagArticleInfo.php b/library/ZendAfi/View/Helper/TagArticleInfo.php index 8e14fdbbf8f..654b99e2811 100644 --- a/library/ZendAfi/View/Helper/TagArticleInfo.php +++ b/library/ZendAfi/View/Helper/TagArticleInfo.php @@ -32,6 +32,7 @@ class ZendAfi_View_Helper_TagArticleInfo extends ZendAfi_View_Helper_BaseHelper $this->renderCat($article). $this->renderLocalisation($article). $this->renderTags($article). + $this->renderCustomFields($article). '</dl>'; } @@ -49,14 +50,14 @@ class ZendAfi_View_Helper_TagArticleInfo extends ZendAfi_View_Helper_BaseHelper $this->renderItem( $this->view->getHumanDate($article->getEventsDebut(), 'EEE d MMM'), - 'event_start_date', $this->view->_('Commence le')); + 'event_start_date', $this->_('Commence le')); } public function renderHeureDebut($article) { return $this->renderItem($this->view->getHumanDate($article->getEventsDebut(),"HH'h'mm"), - 'event_start_hour',$this->view->_('à ')); + 'event_start_hour',$this->_('à ')); } @@ -66,7 +67,7 @@ class ZendAfi_View_Helper_TagArticleInfo extends ZendAfi_View_Helper_BaseHelper $this->renderItem( $this->view->getHumanDate($article->getEventsFin(), 'EEE d MMM'), - 'event_end_date',$this->view->_('finit le')); + 'event_end_date',$this->_('finit le')); } @@ -74,7 +75,7 @@ class ZendAfi_View_Helper_TagArticleInfo extends ZendAfi_View_Helper_BaseHelper return $this->renderItem($this->view->getHumanDate($article->getEventsFin(),"HH'h'mm"), 'event_end_hour', - $this->view->_('à ')); + $this->_('à ')); } @@ -86,12 +87,12 @@ class ZendAfi_View_Helper_TagArticleInfo extends ZendAfi_View_Helper_BaseHelper return $this->renderItem($bib->getLibelle(), 'event_bib', - $this->view->_('Bibliothèque')) + $this->_('Bibliothèque')) . $this->renderItem($this->view->tagAnchor($bib->getUrl(), $bib->getLibelle()), 'event_bib_link', - $this->view->_('Bibliothèque')); + $this->_('Bibliothèque')); } @@ -99,14 +100,14 @@ class ZendAfi_View_Helper_TagArticleInfo extends ZendAfi_View_Helper_BaseHelper return $this->renderItem($article->getCategorieLibelle(), 'event_cat', - $this->view->_('Catégorie')); + $this->_('Catégorie')); } public function renderLocalisation($article) { return $this->renderItem($article->getLieuLibelle(), 'event_localisation', - $this->view->_('Lieu')); + $this->_('Lieu')); } @@ -116,11 +117,24 @@ class ZendAfi_View_Helper_TagArticleInfo extends ZendAfi_View_Helper_BaseHelper foreach($tags as $tag) { $html.= $this->renderItem($tag, 'event_tag', - $this->view->_('Tag')); + $this->_('Tag')); } return $html; } + + public function renderCustomFields($article) { + if (!($model_value = Class_CustomField_Model::getModel('Article')->find($article->getId()))) + return ''; + + $html = ''; + foreach ($model_value->getFieldValues() as $custom_field_value) { + $html .= $this->renderItem($custom_field_value->getValue(), + 'custom_field_'.$custom_field_value->getFieldId(), + $custom_field_value->getLabel()); + } + return $html; + } } ?> \ No newline at end of file diff --git a/tests/application/modules/opac/controllers/CmsControllerCalendarActionTest.php b/tests/application/modules/opac/controllers/CmsControllerCalendarActionTest.php index 4f842401bed..a9a17a86089 100644 --- a/tests/application/modules/opac/controllers/CmsControllerCalendarActionTest.php +++ b/tests/application/modules/opac/controllers/CmsControllerCalendarActionTest.php @@ -558,8 +558,8 @@ class CmsControllerCalendarActionWithDayTest extends AbstractControllerTestCase 'id_lieu' => '', 'custom_fields' => [], 'published' => true]) - ->answers([Class_Article::find(2)]) - ->beStrict(); + ->answers([Class_Article::find(2)]); + $this->dispatch('cms/calendar/date/2014-09-30/id_profil/3/id_module/1/opac/render/ajax', true); } diff --git a/tests/application/modules/opac/controllers/CmsControllerTest.php b/tests/application/modules/opac/controllers/CmsControllerTest.php index 266aca12224..473843de0f7 100644 --- a/tests/application/modules/opac/controllers/CmsControllerTest.php +++ b/tests/application/modules/opac/controllers/CmsControllerTest.php @@ -974,6 +974,31 @@ class CmsControllerArticleViewTest extends CmsControllerWithFeteDeLaFriteTestCas public function setUp() { parent::setUp(); + $theme = $this->fixture('Class_CustomField', + ['id' => 1, + 'priority' => 3, + 'label' => 'Theme', + 'field_type' => Class_CustomField_Meta::SELECT, + 'options_list' => 'sigb;opac', + 'model' => 'Article']); + $multi_options = $this->fixture('Class_CustomField', + ['id' => 20, + 'priority' => 3, + 'label' => 'Options "classieuses"', + 'field_type' => Class_CustomField_Meta::MULTI_CHECKBOX, + 'options_list' => 'wifi;restauration;projection', + 'model' => 'Article']); + $this->fixture('Class_CustomField_Value', + ['id' => 59, + 'custom_field_id' => $theme->getId(), + 'model_id' => 224, + 'value' => 'sigb']); + + $this->fixture('Class_CustomField_Value', + ['id' => 5, + 'custom_field_id' => $multi_options->getId(), + 'model_id' => 224, + 'value' => 'wifi;restauration']); Class_AdminVar::newInstanceWithId('ID_READ_SPEAKER', ['valeur' => '1234']); @@ -999,6 +1024,12 @@ class CmsControllerArticleViewTest extends CmsControllerWithFeteDeLaFriteTestCas } + /** @test */ + public function wifiAndRestaurantionShouldBeDisplayed() { + $this->assertXPathContentContains('//dl[@class="article_info"]/dd[@class="custom_field_20"]', 'wifi;restauration',$this->_response->getBody()); + } + + /** @test */ public function titleShouldBeFeteDeLaFrite() { $this->assertXpathContentContains('//h1', 'La fête de la frite'); @@ -1296,6 +1327,7 @@ class CmsControllerArticleViewAsAdminTest extends CmsControllerWithFeteDeLaFrite + class CmsControllerArticleViewWithModoTest extends CmsControllerWithFeteDeLaFriteTestCase { public function setUp() { parent::setUp(); -- GitLab