From 0860a4695f4e90508134707de12be29c06c351f6 Mon Sep 17 00:00:00 2001
From: gloas <gloas@afi-sa.fr>
Date: Mon, 25 Feb 2019 10:32:47 +0100
Subject: [PATCH] dev #64573 wip on record view and search result

---
 .../scripts/recherche/resultatRecherche.phtml |   7 +-
 library/ZendAfi/Form/BiographieNotice.php     |   2 +-
 library/ZendAfi/View/Helper/Search/Header.php |  13 +-
 .../Intonation/Assets/css/intonation.css      |   4 +
 .../View/RenderAuthorDescription.php          |  16 ++-
 .../Intonation/View/RenderRecordBadges.php    |   2 -
 .../Intonation/View/Search/Header.php         |  27 +++++
 .../Intonation/View/Search/Result.php         | 113 ++++++++++++++++++
 tests/scenarios/Templates/TemplatesTest.php   |  22 ++++
 9 files changed, 185 insertions(+), 21 deletions(-)
 create mode 100644 library/templates/Intonation/View/Search/Header.php
 create mode 100644 library/templates/Intonation/View/Search/Result.php

diff --git a/application/modules/opac/views/scripts/recherche/resultatRecherche.phtml b/application/modules/opac/views/scripts/recherche/resultatRecherche.phtml
index b667b57311e..32dc16889c8 100644
--- a/application/modules/opac/views/scripts/recherche/resultatRecherche.phtml
+++ b/application/modules/opac/views/scripts/recherche/resultatRecherche.phtml
@@ -1,5 +1,4 @@
 <?php
-$this->openBoite($this->titre);
-echo $this->Search_Header($this->search_result);
-$this->closeBoite();
-echo $this->Search_Result($this->search_result);
+echo
+  $this->Search_Header($this->search_result)
+  . $this->Search_Result($this->search_result);
diff --git a/library/ZendAfi/Form/BiographieNotice.php b/library/ZendAfi/Form/BiographieNotice.php
index b237ed8d4c1..8c5eb26302c 100644
--- a/library/ZendAfi/Form/BiographieNotice.php
+++ b/library/ZendAfi/Form/BiographieNotice.php
@@ -23,7 +23,7 @@ class ZendAfi_Form_BiographieNotice extends ZendAfi_Form {
   public function init() {
     parent::init();
     $this
-      ->addElement('url',
+      ->addElement('text',
                    'url_auteur',
                    ['label' => $this->_('URL Wikipedia de l\'auteur'),
                     'size' => 80,
diff --git a/library/ZendAfi/View/Helper/Search/Header.php b/library/ZendAfi/View/Helper/Search/Header.php
index 43f4bed600b..9f9a2c166e4 100644
--- a/library/ZendAfi/View/Helper/Search/Header.php
+++ b/library/ZendAfi/View/Helper/Search/Header.php
@@ -43,11 +43,14 @@ class ZendAfi_View_Helper_Search_Header extends ZendAfi_View_Helper_BaseHelper {
              $this->view->tagSearchExtension($this->_criteria),
              $this->_tagRecordSelectionCount()];
 
-    return $this->_tag('div',
-                       implode(
-                               array_merge($composition,
-                                           $html)),
-                       ['class' => 'resultats_page']);
+    return
+      $this->view->openBoite($this->view->titre)
+      . $this->_tag('div',
+                    implode(
+                            array_merge($composition,
+                                        $html)),
+                    ['class' => 'resultats_page'])
+      . $this->view->closeBoite();
   }
 
 
diff --git a/library/templates/Intonation/Assets/css/intonation.css b/library/templates/Intonation/Assets/css/intonation.css
index a94f431e867..2d6e521499a 100644
--- a/library/templates/Intonation/Assets/css/intonation.css
+++ b/library/templates/Intonation/Assets/css/intonation.css
@@ -415,4 +415,8 @@ healer.col {
     overflow: hidden;
     min-height: 1px;
     min-width: 1px;
+}
+
+.selector_widget label {
+    white-space: nowrap;
 }
\ No newline at end of file
diff --git a/library/templates/Intonation/View/RenderAuthorDescription.php b/library/templates/Intonation/View/RenderAuthorDescription.php
index 3a7f65fa76a..4e800557d84 100644
--- a/library/templates/Intonation/View/RenderAuthorDescription.php
+++ b/library/templates/Intonation/View/RenderAuthorDescription.php
@@ -22,30 +22,28 @@
 class Intonation_View_RenderAuthorDescription extends ZendAfi_View_Helper_BaseHelper {
 
   public function renderAuthorDescription($description) {
-    $html = [$this->_div(['class' => 'col-3 col-xl-2'],
+    $html = [$this->_div(['class' => 'col-3'],
                          $this->view->Author_RenderThumbnail($description)),
 
-             $this->_div(['class' => 'col-9 col-xl-4 pl-3 pl-xl-0'],
+             $this->_div(['class' => 'col-9 pl-3'],
                          $this->view->Author_RenderFacets($description)),
 
-             $this->_div(['class' => 'col-12 col-xl-5 mt-3'],
+             $this->_div(['class' => 'col-12 mt-3'],
                          $this->view->Author_RenderWikipedia($description)),
 
              $this->_div(['class' => 'col-12 mt-3 text-right'],
                          $this->view->Author_EditBiographyUrl($description)),
 
-             $this->_div(['class' => 'col-12 col-xl-6 mt-3'],
+             $this->_div(['class' => 'col-12 mt-3'],
                          $this->view->Author_RenderRecords($description)),
 
-             $this->_div(['class' => 'col-12 col-xl-5 mt-3'],
+             $this->_div(['class' => 'col-12 mt-3'],
                          $this->view->Author_RenderCollaborations($description)),
 
-             $this->_div(['class' => 'col-12'], ''),
-
-             $this->_div(['class' => 'col-12 col-xl-6 mt-3'],
+             $this->_div(['class' => 'col-12 mt-3'],
                          $this->view->Author_RenderInterviews($description)),
 
-             $this->_div(['class' => 'col-12 col-xl-5 mt-3'],
+             $this->_div(['class' => 'col-12 mt-3'],
                          $this->view->Author_RenderYoutubeChan($description)),
     ];
 
diff --git a/library/templates/Intonation/View/RenderRecordBadges.php b/library/templates/Intonation/View/RenderRecordBadges.php
index c924d60d4ee..ef055e30a67 100644
--- a/library/templates/Intonation/View/RenderRecordBadges.php
+++ b/library/templates/Intonation/View/RenderRecordBadges.php
@@ -117,8 +117,6 @@ class Intonation_View_RenderRecordBadges extends ZendAfi_View_Helper_BaseHelper
 
   protected function _getFacets($record) {
     $codes = [Class_CodifTags::CODE_FACETTE,
-              Class_CodifDewey::CODE_FACETTE,
-              Class_CodifPcdm4::CODE_FACETTE,
               Class_CodifMatiere::CODE_FACETTE,
               Class_CodifGenre::CODE_FACETTE,
               Class_CodifCentreInteret::CODE_FACETTE];
diff --git a/library/templates/Intonation/View/Search/Header.php b/library/templates/Intonation/View/Search/Header.php
new file mode 100644
index 00000000000..c22939854e6
--- /dev/null
+++ b/library/templates/Intonation/View/Search/Header.php
@@ -0,0 +1,27 @@
+<?php
+/**
+ * Copyright (c) 2012-2019, Agence Française Informatique (AFI). All rights reserved.
+ *
+ * BOKEH is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
+ * the Free Software Foundation.
+ *
+ * There are special exceptions to the terms and conditions of the AGPL as it
+ * is applied to this software (see README file).
+ *
+ * BOKEH is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * along with BOKEH; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
+ */
+
+
+class Intonation_View_Search_Header extends ZendAfi_View_Helper_BaseHelper {
+  public function Search_Header($search) {
+    return '';
+  }
+}
diff --git a/library/templates/Intonation/View/Search/Result.php b/library/templates/Intonation/View/Search/Result.php
new file mode 100644
index 00000000000..70a0ed2d83f
--- /dev/null
+++ b/library/templates/Intonation/View/Search/Result.php
@@ -0,0 +1,113 @@
+<?php
+/**
+ * Copyright (c) 2012-2019, Agence Française Informatique (AFI). All rights reserved.
+ *
+ * BOKEH is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
+ * the Free Software Foundation.
+ *
+ * There are special exceptions to the terms and conditions of the AGPL as it
+ * is applied to this software (see README file).
+ *
+ * BOKEH is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * along with BOKEH; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
+ */
+
+
+class Intonation_View_Search_Result extends ZendAfi_View_Helper_BaseHelper {
+  public function Search_Result($search) {
+
+    $records = $search->fetchRecords();
+
+    $records = array_map(function($record)
+                         {
+                           return (new Intonation_Library_View_Wrapper_Record)
+                             ->setModel($record)
+                             ->setView($this->view);
+                         }, $records);
+
+    $records = $this->view->renderList(new Storm_Collection($records),
+                                       function($wrapped)
+                                       {
+                                         return $this->view->cardifyOnlyDescription($wrapped);
+                                       });
+
+    $facets = $this->view->facettes($search->fetchFacetsAndTags($search->getSettings())['facettes'],
+                                    $search->getSettings(),
+                                    $search->getCriteresRecherche());
+
+    $criteria = $search->getCriteresRecherche();
+
+    $this->view->titre = $this->_('Résultats pour %s',
+                                  $criteria->getExpressionRecherche());
+
+    $html = [$this->_div(['class' => 'col-12'],
+                          $this->_tag('h1',
+                                      $this->view->titre)),
+
+             $this->_div(['class' => 'col-12'],
+                         $this->_renderTools($search,$criteria)),
+
+             $this->_div(['class' => 'col-3'],
+                         $facets),
+
+             $this->_div(['class' => 'offset-1 col-8'],
+                         $records)];
+
+    return $this->view->grid(implode($html));
+  }
+
+
+  protected function _renderTools($search,$criteria) {
+   $instance = (new Class_Profil_Preferences_SearchResult())
+      ->getHeaderCompositionOf(Class_Profil::getCurrentProfil());
+
+   $tools = $instance->getSelected();
+
+   $tools = array_map(function ($item) use ($criteria)
+                      {
+                        return $item->renderOn($this->view, $criteria);
+                      },
+                      $tools);
+
+   $tools = array_merge($tools,
+                        $this->_pager($search, $criteria));
+
+   $tools = array_map(function ($html)
+                      {
+                        return $this->_tag('li',
+                                           $html,
+                                           ['class' => 'nav-item']);
+                      },
+                      $tools);
+
+   return $this->_tag('ul',
+                      implode($tools),
+                      ['class' => 'nav nav-fill nav-pills']);
+  }
+
+
+  protected function _pager($search,$criteria) {
+    $count_result = $search->getRecordsCount();
+    $current_page = $criteria->getPage();
+    $page_size = $criteria->getPageSize();
+
+    $count_pages = ceil( $count_result / $page_size );
+
+    return [$this->_tag( 'span' ,
+                        $this->_( '%d résultats' , $count_result )),
+
+            $this->view->tagAnchor('', $this->_tag('i','',['class' => 'fas fa-chevron-left'])),
+
+            $this->_tag( 'span' ,
+                        $this->_('Page %d / %d' , $current_page, $count_pages)),
+
+            $this->view->tagAnchor('', $this->_tag('i','',['class' => 'fas fa-chevron-right']))];
+  }
+}
diff --git a/tests/scenarios/Templates/TemplatesTest.php b/tests/scenarios/Templates/TemplatesTest.php
index f31b9acb1d9..1d16e095f2e 100644
--- a/tests/scenarios/Templates/TemplatesTest.php
+++ b/tests/scenarios/Templates/TemplatesTest.php
@@ -2339,3 +2339,25 @@ class TemplatesDispatchNoticeajaxAuthorActionTest extends TemplatesIntonationTes
     $this->assertXPath('//div');
   }
 }
+
+
+
+class TemplatesSearchRecordsTest extends TemplatesIntonationTestCase {
+  public function setUp() {
+    parent::setUp();
+    $this->fixture('Class_Notice',
+                   ['id' => 456,
+                    'titre_principal' => 'Psycho',
+                    'clef_oeuvre' => 'PSYKO',
+                    'facettes' => 'G13 M12']);
+
+    $this->dispatch('/opac/recherche/psyko/id_profil/72');
+  }
+
+
+  /** @test */
+  public function dispatchViewRecordShouldDisplayPsycho() {
+    $this->assertXPathContentContains('//h1',
+                                      'Psycho');
+  }
+}
\ No newline at end of file
-- 
GitLab