From 1739e571b691669a1a1f1a6455718d7ff269b292 Mon Sep 17 00:00:00 2001
From: gloas <gloas@afi-sa.fr>
Date: Tue, 10 Jul 2018 10:43:36 +0200
Subject: [PATCH] dev #30038 upgrade domain browser widget

---
 VERSIONS_WIP/30038                            |  2 +
 .../Systeme/ModulesAccueil/DomainBrowser.php  |  1 +
 .../Form/Configuration/Widget/Domains.php     |  8 ++-
 .../View/Helper/RenderDomainBrowser.php       | 53 +++++++++----------
 .../controllers/WidgetControllerTest.php      | 12 ++++-
 .../View/Helper/Accueil/DomainBrowserTest.php |  2 +-
 6 files changed, 47 insertions(+), 31 deletions(-)
 create mode 100644 VERSIONS_WIP/30038

diff --git a/VERSIONS_WIP/30038 b/VERSIONS_WIP/30038
new file mode 100644
index 00000000000..ca9bb85d08e
--- /dev/null
+++ b/VERSIONS_WIP/30038
@@ -0,0 +1,2 @@
+ - ticket #30038 : Boite domaine : ajout du paramètre "tri du résultat de recherche" dans la configuration de la boite.
+ 
\ No newline at end of file
diff --git a/library/Class/Systeme/ModulesAccueil/DomainBrowser.php b/library/Class/Systeme/ModulesAccueil/DomainBrowser.php
index de574c668c5..fd1f64e2fc5 100644
--- a/library/Class/Systeme/ModulesAccueil/DomainBrowser.php
+++ b/library/Class/Systeme/ModulesAccueil/DomainBrowser.php
@@ -35,6 +35,7 @@ class Class_Systeme_ModulesAccueil_DomainBrowser extends Class_Systeme_ModulesAc
     $this->_defaultValues = ['titre' => $this->_libelle,
                              'allow_breadcrumb' => 0,
                              'root_domain_id' => 0,
+                             'tri' => Class_CriteresRecherche::SORT_PUBLICATION,
                              'display_mode' => Class_Systeme_ModulesAppli::LISTE_FORMAT_MUR];
   }
 }
\ No newline at end of file
diff --git a/library/ZendAfi/Form/Configuration/Widget/Domains.php b/library/ZendAfi/Form/Configuration/Widget/Domains.php
index 15cca0e2584..41102880d45 100644
--- a/library/ZendAfi/Form/Configuration/Widget/Domains.php
+++ b/library/ZendAfi/Form/Configuration/Widget/Domains.php
@@ -37,8 +37,14 @@ class ZendAfi_Form_Configuration_Widget_Domains extends ZendAfi_Form_Configurati
                    ['label' => $this->_('Format'),
                     'multiOptions' => Class_Systeme_ModulesAppli::getAvailableListeDomainsFormat()])
 
+      ->addElement('select',
+                   'tri',
+                   ['label' => $this->_('Tri du résultat de recherche'),
+                    'multiOptions' => (new Class_CriteresRecherche())->getListeTris()])
+
       ->addToSelectionGroup(['root_domain_id'])
 
-      ->addToDisplaySettingsGroup(['display_mode']);
+      ->addToDisplaySettingsGroup(['display_mode',
+                                   'tri']);
   }
 }
\ No newline at end of file
diff --git a/library/ZendAfi/View/Helper/RenderDomainBrowser.php b/library/ZendAfi/View/Helper/RenderDomainBrowser.php
index ee4e7172fc5..ec5d66b4127 100644
--- a/library/ZendAfi/View/Helper/RenderDomainBrowser.php
+++ b/library/ZendAfi/View/Helper/RenderDomainBrowser.php
@@ -1,4 +1,4 @@
-<?php 
+<?php
 /**
  * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
  *
@@ -16,11 +16,11 @@
  *
  * 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 
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
  */
 
 class ZendAfi_View_Helper_RenderDomainBrowser extends ZendAfi_View_Helper_BaseHelper {
-  
+
   protected $_current, $_pref, $_id_module,$renderer;
 
   public function renderDomainBrowser($current, $id_module, $preferences) {
@@ -45,12 +45,12 @@ class ZendAfi_View_Helper_RenderDomainBrowser extends ZendAfi_View_Helper_BaseHe
 
     foreach($this->_current->getChildren() as $child)
       $html .= $this->display($child);
-    
+
     return $html;
   }
 
 
-  public function breadcrumb() {    
+  public function breadcrumb() {
     if ($this->_current->getId()==$this->_pref['root_domain_id'])
       return '';
     $parents_html = '';
@@ -73,8 +73,8 @@ class ZendAfi_View_Helper_RenderDomainBrowser extends ZendAfi_View_Helper_BaseHe
   protected function display($domain) {
     $view = $this->view;
     $url_img = $domain->getUrlImg();
-    $img = $view->tagImg($url_img ? $url_img : $view->skinImageUrl('filetypes.png'),  
-                         ['alt' => $domain->getLibelle(), 
+    $img = $view->tagImg($url_img ? $url_img : $view->skinImageUrl('filetypes.png'),
+                         ['alt' => $domain->getLibelle(),
                           'title' => $domain->getLibelle()]);
     $url = $this->getBrowsingUrl($domain);
 
@@ -86,17 +86,16 @@ class ZendAfi_View_Helper_RenderDomainBrowser extends ZendAfi_View_Helper_BaseHe
     if (($domain->getId()==$this->_pref['root_domain_id']) ||  !$domain->hasDomaineParent())
       return $this->view->url([], null, true);
 
-    $params = $domain->hasSousDomaines() 
+    $params = $domain->hasSousDomaines()
       ? ['controller' =>'domains',
-                      'action' => 'browse',
-                      'id'=> $domain->getId(),
-                      'id_module' => $this->_id_module
-        ]
+         'action' => 'browse',
+         'id'=> $domain->getId(),
+         'id_module' => $this->_id_module]
       : ['controller' =>'recherche',
-                      'action' => 'simple',
-                      'id_catalogue'=> $domain->getId(),
-                      'id_module' => $this->_id_module
-        ];
+         'action' => 'simple',
+         'id_catalogue'=> $domain->getId(),
+         'id_module' => $this->_id_module,
+         'tri' => (isset($this->_pref['tri']) ? $this->_pref['tri'] : null)];
 
     return $this->view->url($params, null, true);
   }
@@ -106,7 +105,7 @@ class ZendAfi_View_Helper_RenderDomainBrowser extends ZendAfi_View_Helper_BaseHe
 
 
 abstract class ZendAfi_View_Helper_RenderDomainBrowser_Abstract {
-  protected 
+  protected
     $_view,
     $_helper,
     $_container_tag = '',
@@ -129,32 +128,32 @@ abstract class ZendAfi_View_Helper_RenderDomainBrowser_Abstract {
   public function children($html) {
     if (!$html)
       return '';
-    return $this->_view->tag($this->_container_tag, 
+    return $this->_view->tag($this->_container_tag,
                              $html,
                              ['class' => 'children']);
   }
 
-  
+
   public function breadcrumb($html) {
     if (!$html)
       return '';
-    return $this->_view->tag($this->_container_tag, 
+    return $this->_view->tag($this->_container_tag,
                              $html,
-                             ['class' => 'breadcrumb']); 
+                             ['class' => 'breadcrumb']);
   }
 }
 
 
 
 class ZendAfi_View_Helper_RenderDomainBrowser_Wall extends ZendAfi_View_Helper_RenderDomainBrowser_Abstract {
-  protected 
+  protected
     $_container_tag = 'div',
     $_helper_class = 'liste_mur';
-  
+
   public function display($url, $img, $title){
     return $this->_view->tag('div',
-                            $this->_view->tagAnchor($url, 
-                                                    $img . $this->_view->tag('div', 
+                            $this->_view->tagAnchor($url,
+                                                    $img . $this->_view->tag('div',
                                                                              $title,
                                                                              ['class' => 'titre_auteur'])));
   }
@@ -167,12 +166,12 @@ class ZendAfi_View_Helper_RenderDomainBrowser_Wall extends ZendAfi_View_Helper_R
 
 
 class ZendAfi_View_Helper_RenderDomainBrowser_List extends ZendAfi_View_Helper_RenderDomainBrowser_Abstract  {
-  protected 
+  protected
     $_container_tag = 'ul';
 
   public function display($url, $img, $title){
     $view = $this->_view;
-    return $view->tag('li',$view->tagAnchor($url, 
+    return $view->tag('li',$view->tagAnchor($url,
                                             $img . $view->tag('span', $title)));
   }
 
diff --git a/tests/application/modules/admin/controllers/WidgetControllerTest.php b/tests/application/modules/admin/controllers/WidgetControllerTest.php
index 9538948d90e..828c86fd56a 100644
--- a/tests/application/modules/admin/controllers/WidgetControllerTest.php
+++ b/tests/application/modules/admin/controllers/WidgetControllerTest.php
@@ -1822,6 +1822,12 @@ class WidgetControllerDomainBrowserDispatchTest extends WidgetControllerDispatch
   }
 
 
+  /** @test **/
+  public function inputTriShouldBeDisplay() {
+    $this->assertXpath('//select[@name="tri"]/option[@selected="selected"][@value="annee desc"]');
+  }
+
+
   /** @test */
   public function submitButtonShouldBeDisplayed() {
     $this->assertXPath('//button[@type="submit"]');
@@ -1868,8 +1874,10 @@ class WidgetControllerDomainBrowserPostDispatchTest extends WidgetControllerPost
                                                        'boite' => '',
                                                        'division' => '3',
                                                        'id_module' => '6',
-                                                       'type_module' => 'DOMAIN_BROWSER'],
-                                     'profile_id' => '5']),
+                                                       'type_module' => 'DOMAIN_BROWSER',
+                                                       'tri' => 'annee desc'],
+                                     'profile_id' => '5',
+                                     'tri' => 'annee desc']),
                         $this->_saved_settings);
   }
 }
diff --git a/tests/library/ZendAfi/View/Helper/Accueil/DomainBrowserTest.php b/tests/library/ZendAfi/View/Helper/Accueil/DomainBrowserTest.php
index 794e2059abb..8188ca48a24 100644
--- a/tests/library/ZendAfi/View/Helper/Accueil/DomainBrowserTest.php
+++ b/tests/library/ZendAfi/View/Helper/Accueil/DomainBrowserTest.php
@@ -129,7 +129,7 @@ abstract class ZendAfi_View_Helper_Accueil_DomainBrowserViewAccordionTestCase ex
 class ZendAfi_View_Helper_Accueil_DomainBrowserViewAccordionTest extends ZendAfi_View_Helper_Accueil_DomainBrowserViewAccordionTestCase {
   /** @test */
   public function linkForDomainMetalShouldBePresent() {
-    $this->assertXPath($this->_html, '//div[contains(@class,"domains")]//ul[@class="children"]//li//a[contains(@href, "/recherche/simple/id_catalogue/1/id_module/9")]', $this->_html);
+    $this->assertXPath($this->_html, '//div[contains(@class,"domains")]//ul[@class="children"]//li//a[contains(@href, "/recherche/simple/id_catalogue/1/id_module/9/tri/annee+desc")]', $this->_html);
   }
 
 
-- 
GitLab