From b8ec576335529251b3cfa0f71d71cf03162a15a7 Mon Sep 17 00:00:00 2001 From: efalcy <efalcy@afi-sa.fr> Date: Fri, 9 Jan 2015 18:23:24 +0100 Subject: [PATCH] sandbox fusion search result : recursive instance(wip) --- library/Class/ModeleFusion.php | 27 ++++++++++++++----- .../controllers/RechercheControllerTest.php | 1 + 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/library/Class/ModeleFusion.php b/library/Class/ModeleFusion.php index c0cbaaed54a..74cab77c590 100644 --- a/library/Class/ModeleFusion.php +++ b/library/Class/ModeleFusion.php @@ -85,7 +85,14 @@ class Class_ModeleFusion extends Storm_Model_Abstract { public function getTagValueForInstance($match,$instance) { - return $instance->callGetterByAttributeName($match); + if (strpos($match,'.') === false) + return $instance->callGetterByAttributeName($match); + if (!$instance->callGetterByAttributeName($match)) + return ''; + $matches = substr($match,0,strpos($match,'.')); + return $this->getTagValueForInstance(substr($match,strpos($match,'.')+1),$instance->callGetterByAttributeName($matches)); + + } @@ -124,12 +131,8 @@ class Class_ModeleFusion extends Storm_Model_Abstract { return $this->getValue($value_or_model, $attributes); } - public function buildSection($items,$html) { - $contenu_decode=preg_replace_callback('/\{[^\}]+\}/', - create_function('$matches', - 'return html_entity_decode($matches[0],ENT_QUOTES);'), - $html); + public function decode($contenu_decode) { $matches = []; preg_match_all('/'. //ex: @session_formation.stagiaires[nom, prenom]@ '\{'. //delimiteur @@ -142,7 +145,17 @@ class Class_ModeleFusion extends Storm_Model_Abstract { $contenu_decode, $matches, PREG_SET_ORDER); + return $matches; + } + public function buildSection($items,$html) { + + $contenu_decode=preg_replace_callback('/\{[^\}]+\}/', + create_function('$matches', + 'return html_entity_decode($matches[0],ENT_QUOTES);'), + $html); + + $matches = $this->decode($contenu_decode); $result=''; foreach($items as $item) { $decode=$contenu_decode; @@ -153,7 +166,7 @@ class Class_ModeleFusion extends Storm_Model_Abstract { try { $tag= str_replace('{','',$tag); $tag= str_replace('}','',$tag); - + xdebug_break(); $tag_value = $this->getTagValueForInstance($tag,$item); } catch (Storm_Model_Exception $e) { continue; diff --git a/tests/application/modules/opac/controllers/RechercheControllerTest.php b/tests/application/modules/opac/controllers/RechercheControllerTest.php index dded174a815..f764ffc56be 100644 --- a/tests/application/modules/opac/controllers/RechercheControllerTest.php +++ b/tests/application/modules/opac/controllers/RechercheControllerTest.php @@ -2757,6 +2757,7 @@ class RechercheControllerPrintActionTest extends AbstractControllerTestCase { /** @test */ public function displayShouldprintTitle() { + $this->assertXPathContentContains("//p", "pomme",$this->_response->getBody()); } -- GitLab