diff --git a/application/modules/opac/views/scripts/recherche/resultatRecherche.phtml b/application/modules/opac/views/scripts/recherche/resultatRecherche.phtml index 9f2b4d67c0f8af33ce68013fcfa879075867ce20..156cc6455295dcd49a7f29a9161d52319c3a95d9 100644 --- a/application/modules/opac/views/scripts/recherche/resultatRecherche.phtml +++ b/application/modules/opac/views/scripts/recherche/resultatRecherche.phtml @@ -16,8 +16,16 @@ if ($this->is_pertinence) { $this->titre .= $this->_(" (recherche élargie triée par pertinence)"); } ?> -<div class="print"><a href="<?php echo $this->url(['action' => 'print', - 'modele_fusion' => Class_ModeleFusion::findAll()[0]->getId()]); ?>">imprimer</a></div> +<div class="print"> +<?php +if ($fusion=Class_ModeleFusion::findFirstBy(['nom' => 'recherche'])) { +?> +<a href="<?php echo $this->url(['action' => 'print', + 'modele_fusion' => $fusion->getId()]); ?>">imprimer</a> + + +<?php } ?> +</div> <div class="resultats_page"> <?php echo $this->tagTriRecherche($this->criteres_recherche); diff --git a/library/Class/Article.php b/library/Class/Article.php index 7282dc8c7ef77f15e52032da85e0bc624d28773b..7f89f542a43e74fdd8878d161489fb0e0e30df37 100644 --- a/library/Class/Article.php +++ b/library/Class/Article.php @@ -854,6 +854,7 @@ class Class_Article extends Storm_Model_Abstract { * @return string */ public function getContenu() { + xdebug_break(); $contenu = parent::_get('contenu'); $quote = '[\"\']'; diff --git a/library/Class/ModeleFusion.php b/library/Class/ModeleFusion.php index 74cab77c5907cdae41925dde453d4cf274273885..3452710ea2a476da3b99d9ea8a26db6fbe900775 100644 --- a/library/Class/ModeleFusion.php +++ b/library/Class/ModeleFusion.php @@ -42,7 +42,11 @@ class Class_ModeleFusion extends Storm_Model_Abstract { public function getDataSourceNamed($name) { - return array_at($name, $this->getDataSource()); + $this->dataSource=array_at($name, $this->getDataSource()); + return $this->dataSource; + if (!$this->dataSource) + return $this->dataSource=array_at($name, $this->getDataSource()); + return $this->dataSource->callGetterByAttributeName($name); } @@ -87,6 +91,11 @@ class Class_ModeleFusion extends Storm_Model_Abstract { public function getTagValueForInstance($match,$instance) { if (strpos($match,'.') === false) return $instance->callGetterByAttributeName($match); + else { + return $this->getTagValueForCollectionInstance($match,$instance); + $match = explode('.',$match); + array_shift($match); + } if (!$instance->callGetterByAttributeName($match)) return ''; $matches = substr($match,0,strpos($match,'.')); @@ -97,11 +106,43 @@ class Class_ModeleFusion extends Storm_Model_Abstract { } + public function getTagValueForCollectionInstance($match,$instance) { + $attributes=$match; + xdebug_break(); + if (is_array($match)) + $attributes = array_filter(explode('.',array_shift($match))); + else + if (strpos($match,'.')) { + $attributes = array_filter(explode('.',$match)); + } + + else $attributes =[ $match]; + xdebug_break(); + $model = $instance->callGetterByAttributeName(array_shift($attributes)); + if (!$model) + return ''; + if (is_array($value = $this->getValue($model, $attributes))) + return $this->buildSection($value,array_shift($match)); +// return $this->buildTable($value, array_shift($match)); + + return $this->htmlize($value); + } + + public function getTagValueForString($match) { - $attributes = explode('.',array_shift($match)); + $attributes=$match; + xdebug_break(); + if (is_array($match)) + $attributes = array_filter(explode('.',array_shift($match))); + else + if (strpos($match,'.')) { + $attributes = array_filter(explode('.',$match)); + } - $model = $this->getDataSourceNamed(array_shift($attributes)); + else $attributes =[ $match]; xdebug_break(); + $model = $this->getDataSourceNamed(array_shift($attributes)); + if (is_array($value = $this->getValue($model, $attributes))) return $this->buildSection($value,array_shift($match)); // return $this->buildTable($value, array_shift($match)); @@ -111,6 +152,7 @@ class Class_ModeleFusion extends Storm_Model_Abstract { public function htmlize($value) { + return $value; //php 5.4 - 5.2 compat if (!$in_utf8 = htmlentities($value, ENT_QUOTES, 'UTF-8')) return htmlentities($value, ENT_QUOTES); diff --git a/library/Class/Notice.php b/library/Class/Notice.php index 6b67599f60ed29df0d29e154785fd92ed91db19f..f08728f2008c0eca512f07f3f7a25716532ee857 100644 --- a/library/Class/Notice.php +++ b/library/Class/Notice.php @@ -362,7 +362,9 @@ class Class_Notice extends Storm_Model_Abstract { return parent::setUnimarc($unimarc); } - + public function getFetchUrlVignette() { + return $this->fetchUrlVignette(); + } public function fetchUrlVignette() { if ($this->hasVignette()) return $this->_attributes['url_vignette']; @@ -1659,6 +1661,11 @@ class Class_Notice extends Storm_Model_Abstract { ->setFacettes(implode(' ', array_unique($facettes))) ->setDateCreation($date_nouveaute); } + + public function getArticle() { + xdebug_break(); + return Class_Article::findFirstBy(['id_notice' => $this->getId()]); + } } ?> \ No newline at end of file diff --git a/library/ZendAfi/Form/ModeleFusion.php b/library/ZendAfi/Form/ModeleFusion.php index d280db7bfcbc53f3fc7888d3524d3edc0391cc28..45a6aa92bf0ef527752327150ecd161f83b03d79 100644 --- a/library/ZendAfi/Form/ModeleFusion.php +++ b/library/ZendAfi/Form/ModeleFusion.php @@ -24,8 +24,7 @@ class ZendAfi_Form_ModeleFusion extends ZendAfi_Form { public static function newWith($datas=[], $custom_form=null) { $form_name='MODELE_FUSION'; -// $modele_fusion = Class_ModeleFusion::get($form_name); -// if (!$modele_fusion) + if (!$datas) $datas= (new Class_ModeleFusion())->toArray(); @@ -33,17 +32,20 @@ class ZendAfi_Form_ModeleFusion extends ZendAfi_Form { $form->setMethod('post') ->addElement('text', 'nom', - ['label' => 'Nom']) + ['label' => 'Nom', + 'required' => true, + 'allowEmpty' => false]) ->addElement('ckeditor', 'contenu', + [ + 'label' => '', + 'value' => $datas['contenu'], + 'required' => true, + 'allowEmpty' => false]); - array( - 'label' => $datas['nom'], - 'value' => $datas['contenu'], - 'required' => true, - 'allowEmpty' => false)); - + $form->populate($datas); return $form; + } } diff --git a/tests/application/modules/opac/controllers/RechercheControllerTest.php b/tests/application/modules/opac/controllers/RechercheControllerTest.php index 4714be909cf4717ab1806bb5ef8fe24a5cf9d0ea..807e2b4058319f92329a3eaa3cf81d767f1a62c3 100644 --- a/tests/application/modules/opac/controllers/RechercheControllerTest.php +++ b/tests/application/modules/opac/controllers/RechercheControllerTest.php @@ -2326,29 +2326,57 @@ class RechercheControllerPrintActionTest extends AbstractControllerTestCase { public function setUp() { parent::setUp(); + Class_Article::beVolatile(); + Class_Notice::beVolatile(); +/* $record = $this->fixture('Class_Notice',['id'=> 10, + 'titre_principal' => 'Le photographe', + 'url_vignette' => 'photographe.jpg', + 'auteur_principal' => 'Guibert']); + + + $record2 = $this->fixture('Class_Notice',['id'=> 12, + 'titre_principal' => 'Transmetropolitan', + 'auteur_principal' => 'Ellis']); + +*/ $this->fixture('Class_ModeleFusion', ['id' => 1, 'nom' => 'pomme', - 'contenu' => '<p> {moteurRecherche_resultat.notices[<img src="{url_vignette}"/> {titre_principal} {article_cms.contenu} + 'contenu' => '<p> {moteurRecherche_resultat.notices[<img src="{url_vignette}"/> {titre_principal} <div>{article.contenu}</div> ]}</p>']); Class_Indexation_PseudoNotice::index( $this->fixture('Class_Article' , ['id' => 10, 'titre' => 'pomme', - 'contenu' => 'blabla', + 'contenu' => '<p>blabla</p>', + //'notice' => $record, + 'notice' => new Class_Notice(), + 'type_doc_id' => Class_TypeDoc::ARTICLE])); + + + Class_Indexation_PseudoNotice::index( $this->fixture('Class_Article' , ['id' => 12, + 'titre' => 'transmetropolitan', + 'contenu' => '<p>bd</p>', 'notice' => new Class_Notice(), 'type_doc_id' => Class_TypeDoc::ARTICLE])); + + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Notice') + ->whenCalled('findAllByRequeteRecherche') + ->with("Select id_notice, MATCH(alpha_titre) AGAINST(' POMME') as rel1, MATCH(alpha_auteur) AGAINST(' POMME') as rel2 from notices Where MATCH(titres, auteurs, editeur, collection, matieres, dewey) AGAINST('+(POMME POMMES POM)' IN BOOLEAN MODE) order by (rel1 * 1.5) + (rel2) desc", + 10,1) + ->answers(Class_Notice::findAll()) + ->beStrict(); + $this->dispatch("/recherche/print/expressionRecherche/pomme/modele_fusion/1",true); } /** @test */ - public function displayShouldprintTitle() { - - $this->assertXPathContentContains("//p", "pomme",$this->_response->getBody()); + public function displayShouldprintContent() { + $this->assertXPathContentContains("//div//p", "bd",$this->_response->getBody()); } -/** @test */ - public function contenuShouldContains() { - $this->assertXPathContentContains("//p", "blabla",$this->_response->getBody()); + /** @test */ + public function contenuShouldContainsTransmetropolitan() { + $this->assertXPathContentContains("//div", "transmetropolitan",$this->_response->getBody()); } }