diff --git a/application/modules/opac/controllers/RechercheController.php b/application/modules/opac/controllers/RechercheController.php index e26503fa16b4ed2a37343a5e2a811af5e0a1c9cd..8623affc2e0148fc71e2ca170aee7b2f6b5c7fc0 100644 --- a/application/modules/opac/controllers/RechercheController.php +++ b/application/modules/opac/controllers/RechercheController.php @@ -114,7 +114,8 @@ class RechercheController extends ZendAfi_Controller_Action { protected function _renderAtomResult($criteres_recherche) { $this->getHelper('ViewRenderer')->setNoRender(); - $builder = new ZendAfi_Feed_SearchResult($this->moteur->search($criteres_recherche)); + $result = $this->moteur->lancerRecherche($criteres_recherche); + $builder = new ZendAfi_Feed_SearchResult($result); $feed = Zend_Feed::importBuilder($builder, 'atom'); $this->_response->setHeader('Content-Type', 'application/atom+xml;charset=utf-8'); diff --git a/library/Class/MoteurRecherche/Result.php b/library/Class/MoteurRecherche/Result.php index 1e0fd6934c61c1aa128a539e7b8afcc122b33205..18b284fc6b6e9eda8631e5d61ce12f04996a3096 100644 --- a/library/Class/MoteurRecherche/Result.php +++ b/library/Class/MoteurRecherche/Result.php @@ -41,6 +41,16 @@ class Class_MoteurRecherche_Result { } + public function getSearchTerms() { + return $this->_criteres_recherche->getExpressionRecherche(); + } + + + public function getUrl() { + return $this->_criteres_recherche->getUrlCriteresWithFacettes(); + } + + public function fetchFacetsAndTags($preferences) { return $this->_search_engine->getFacettes($this->_facets_query, $preferences); diff --git a/library/Class/Notice.php b/library/Class/Notice.php index c56c6a17cd8083f9a6a1cb6a32fd357fb5d4ff49..6911d951a3e2130d4c51435e47af420dc8e2fad3 100644 --- a/library/Class/Notice.php +++ b/library/Class/Notice.php @@ -551,7 +551,7 @@ class Class_Notice extends Storm_Model_Abstract { if ($champs) { for ($i = 0; $i < strlen($champs); $i++) { switch ($champs[$i]) { - case "J": $notice["J"] = $this->getTitrePrincipal($notice["type_doc"], $notice["tome_alpha"]); break; + case "J": $notice["J"] = $this->getTitrePrincipal(); break; case "A": $notice["A"] = $this->getAuteurPrincipal(); break; case "E": $notice["E"] = $this->getEditeur(); break; case "F": $notice["F"] = $this->getCentreInteret(); break; @@ -814,7 +814,7 @@ class Class_Notice extends Storm_Model_Abstract { } - public function getTitrePrincipal($type_doc = false, $tome = false) { + public function getTitrePrincipal($separator = BR) { // 200$a $titre = ''; if ($titres = $this->get_subfield('200', 'a')) @@ -829,7 +829,7 @@ class Class_Notice extends Storm_Model_Abstract { $data=$this->get_subfield('461','v'); $tome = isset($data[0]) ? $data[0] : null; if ($tome) $chapeau .= " n° " . $tome; - if ($titre) $titre = $chapeau . BR . $titre; + if ($titre) $titre = $chapeau . $separator . $titre; else $titre = $chapeau; } } diff --git a/library/ZendAfi/Feed/SearchResult.php b/library/ZendAfi/Feed/SearchResult.php index a8c912c7803c4e02aefc578e1afad8df07264813..9624c5674bc0373b52871e592c3499e5283108fa 100644 --- a/library/ZendAfi/Feed/SearchResult.php +++ b/library/ZendAfi/Feed/SearchResult.php @@ -19,13 +19,36 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class ZendAfi_Feed_SearchResult implements Zend_Feed_Builder_Interface { + use Trait_Translator; + + public function __construct($search_result) { + $this->_search_result = $search_result; + } + + public function getHeader() { - return new Zend_Feed_Builder_Header('', ''); + return new Zend_Feed_Builder_Header( + $this->_('Recherche') . ': ' .$this->_search_result->getSearchTerms(), + Class_Url::absolute($this->_search_result->getUrl())); } public function getEntries() { - return []; + $entries = []; + $this + ->_search_result + ->recordsDo( + function($record) use (&$entries){ + $entries []= $this->newEntry($record); + }); + return $entries; + } + + + public function newEntry($record) { + return new Zend_Feed_Builder_Entry($record->getTitrePrincipal(' - '), '', ''); } } + +?> \ No newline at end of file diff --git a/tests/application/modules/opac/controllers/RechercheControllerAtomTest.php b/tests/application/modules/opac/controllers/RechercheControllerAtomTest.php index b0dfd568164f214dca07aa45002ba299dc9e26df..1116f9b0c5efdcb3b1a0a292b32452e5115c98fa 100644 --- a/tests/application/modules/opac/controllers/RechercheControllerAtomTest.php +++ b/tests/application/modules/opac/controllers/RechercheControllerAtomTest.php @@ -80,15 +80,13 @@ class RechercheControllerAtomWithTwoNoticesTestCase extends RechercheControllerA $loader->whenCalled('findAllByRequeteRecherche') - ->with('Select id_notice from notices', 5, 1) - ->answers([$potter, $rdv]) - ->beStrict(); + ->answers([$potter, $rdv]); } protected function _prepareSql($sql) { $sql->whenCalled('fetchOne') - ->with('Select count(*) from notices') + ->with('Select count(*) from notices Where MATCH(titres, auteurs, editeur, collection, matieres, dewey) AGAINST(\'+(HARRY HARRYS ARI) +(POTTER POTTERS POT)\' IN BOOLEAN MODE)') ->answers(2) ->whenCalled('execute') @@ -99,7 +97,7 @@ class RechercheControllerAtomWithTwoNoticesTestCase extends RechercheControllerA protected function _searchUrl() { - return 'recherche/simple/expressionRecherche//tri/*/format/atom/page_size/5'; + return 'recherche/simple/expressionRecherche/Harry+Potter/tri/*/format/atom/page_size/5'; } @@ -109,5 +107,35 @@ class RechercheControllerAtomWithTwoNoticesTestCase extends RechercheControllerA '//atom:feed'); } + + /** @test */ + public function feedTitleShouldBeRechercheHarryPotter() { + $this->_xpath->assertXPathContentContains($this->_response->getBody(), + '//atom:feed/atom:title', + 'Recherche: Harry Potter'); + } + + + /** @test */ + public function feedSelfLinkShouldBeAbsoluteSearchUrl() { + $this->_xpath->assertXPath($this->_response->getBody(), + '//atom:feed/atom:link[@rel="self"][@href="http://localhost/afi-opac3/recherche/simple/expressionRecherche/Harry+Potter/tri/%2A/format/atom/page_size/5"]'); + } + + + /** @test */ + public function feedFirstEntryTitleShouldBeHarryPotter() { + $this->_xpath->assertXPathContentContains($this->_response->getBody(), + '//atom:entry/atom:title', + 'Harry Potter n° 1 - A l\'école des sorciers'); + } + + + /** @test */ + public function feedSecondEntryShouldBeRendezVous() { + $this->_xpath->assertXPathContentContains($this->_response->getBody(), + '//atom:entry/atom:title', + 'Rendez-vous à Kiruna'); + } } ?> \ No newline at end of file