From d3bf2b9392c45f4e1c18e954ef88de673e5f57f0 Mon Sep 17 00:00:00 2001
From: gloas <gloas@afi-sa.fr>
Date: Mon, 14 Dec 2020 12:23:43 +0100
Subject: [PATCH] hotline#122399 : adding opening hours to OSM information

---
 VERSIONS_HOTLINE/122399                       |   1 +
 library/ZendAfi/View/Helper/RenderLibrary.php |  11 +-
 .../View/Helper/RenderLibraryOpeningHours.php |  32 +++++
 library/templates/Chili/Library/Settings.php  |   2 +
 .../Chili/Library/Wrapper/Library.php         |  34 ++++++
 library/templates/Chili/Template.php          |   3 +-
 .../Library/View/Wrapper/ItemForOsm.php       |   4 +-
 library/templates/Intonation/Template.php     |   3 +-
 library/templates/Intonation/View/Grid.php    |   3 +
 .../Templates/ChiliLibraryOSMTest.php         | 109 ++++++++++++++++++
 10 files changed, 187 insertions(+), 15 deletions(-)
 create mode 100644 VERSIONS_HOTLINE/122399
 create mode 100644 library/ZendAfi/View/Helper/RenderLibraryOpeningHours.php
 create mode 100644 library/templates/Chili/Library/Wrapper/Library.php
 create mode 100644 tests/scenarios/Templates/ChiliLibraryOSMTest.php

diff --git a/VERSIONS_HOTLINE/122399 b/VERSIONS_HOTLINE/122399
new file mode 100644
index 00000000000..bcc65e610bd
--- /dev/null
+++ b/VERSIONS_HOTLINE/122399
@@ -0,0 +1 @@
+ - ticket #122399 : Magasin de thèmes : Ajout des horaires dans la carte open street map des exemplaires dans le thème Chili.
\ No newline at end of file
diff --git a/library/ZendAfi/View/Helper/RenderLibrary.php b/library/ZendAfi/View/Helper/RenderLibrary.php
index 520d67961de..a879561f0ce 100644
--- a/library/ZendAfi/View/Helper/RenderLibrary.php
+++ b/library/ZendAfi/View/Helper/RenderLibrary.php
@@ -122,11 +122,7 @@ class ZendAfi_View_Helper_RenderLibrary extends ZendAfi_View_Helper_BaseHelper {
 
 
   protected function renderOpeningHours() {
-    $openings = $this->library->getHoraire()
-      ? $this->library->getHoraire()
-      : $this->view->libraryOpenings($this->library);
-
-    return $this->_renderField($this->_escapeInfo($openings),
+    return $this->_renderField($this->view->renderLibraryOpeningHours($this->library),
                                'field-opening-hours');
   }
 
@@ -182,9 +178,4 @@ class ZendAfi_View_Helper_RenderLibrary extends ZendAfi_View_Helper_BaseHelper {
 
     return $this->_tag('div', $content, $attributes);
   }
-
-
-  protected function _escapeInfo($info) {
-    return str_replace('BR', '<br>', urldecode(str_replace('%0D%0A','BR', $info)));
-  }
 }
\ No newline at end of file
diff --git a/library/ZendAfi/View/Helper/RenderLibraryOpeningHours.php b/library/ZendAfi/View/Helper/RenderLibraryOpeningHours.php
new file mode 100644
index 00000000000..0fb0597b96b
--- /dev/null
+++ b/library/ZendAfi/View/Helper/RenderLibraryOpeningHours.php
@@ -0,0 +1,32 @@
+<?php
+/**
+ * Copyright (c) 2012-2020, 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 ZendAfi_View_Helper_RenderLibraryOpeningHours extends ZendAfi_View_Helper_BaseHelper {
+
+  public function renderLibraryOpeningHours($library) {
+    $openings = ($horaire = $library->getHoraire())
+      ? $horaire
+      : $this->view->libraryOpenings($library);
+
+    return str_replace('BR', '<br>', urldecode(str_replace('%0D%0A','BR', $openings)));
+  }
+}
diff --git a/library/templates/Chili/Library/Settings.php b/library/templates/Chili/Library/Settings.php
index 76360860b01..4875de46624 100644
--- a/library/templates/Chili/Library/Settings.php
+++ b/library/templates/Chili/Library/Settings.php
@@ -103,6 +103,8 @@ class Chili_Library_Settings extends Intonation_Library_Settings {
     $hydrating_mapping['div class user_informations_fields'] = 'card-body pl-0 pt-2';
     $hydrating_mapping['dt class user_info'] = 'col-12';
     $hydrating_mapping['dd class user_info'] = 'col-12';
+    $hydrating_mapping['div class description_library_openings'] = 'col-12';
+    $hydrating_mapping['div class description_library_opened'] = 'col-12';
 
     $settings[$this->_template->withNameSpace('hydrating_mapping')] = $hydrating_mapping;
     return $settings;
diff --git a/library/templates/Chili/Library/Wrapper/Library.php b/library/templates/Chili/Library/Wrapper/Library.php
new file mode 100644
index 00000000000..2fa6df530d7
--- /dev/null
+++ b/library/templates/Chili/Library/Wrapper/Library.php
@@ -0,0 +1,34 @@
+<?php
+/**
+ * Copyright (c) 2012-2020, 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 Chili_Library_Wrapper_Library extends Intonation_Library_View_Wrapper_Library {
+  protected function _renderOpening(){
+    $html = [$this->_view->div(['class'=>'description_library_openings'],
+                                $this->_view->renderLibraryOpeningHours($this->_model)),
+
+             $this->_view->div(['class'=>'description_library_opened'],
+                                parent::_renderOpening())
+    ];
+
+    return $this->_view->grid($html, ['class' => 'description_library_opening_hours']);
+  }
+}
diff --git a/library/templates/Chili/Template.php b/library/templates/Chili/Template.php
index bae693708b6..3ec68b9403b 100644
--- a/library/templates/Chili/Template.php
+++ b/library/templates/Chili/Template.php
@@ -118,6 +118,7 @@ class Chili_Template extends Intonation_Template {
   protected function _getMapWrapper() {
     return
       array_merge(parent::_getMapWrapper(),
-                  ['Class_Notice' => 'Chili_Library_Wrapper_Record']);
+                  ['Class_Notice' => 'Chili_Library_Wrapper_Record',
+                   'Class_Bib' => 'Chili_Library_Wrapper_Library']);
   }
 }
\ No newline at end of file
diff --git a/library/templates/Intonation/Library/View/Wrapper/ItemForOsm.php b/library/templates/Intonation/Library/View/Wrapper/ItemForOsm.php
index 52f9a06ca79..16a0ff71f85 100644
--- a/library/templates/Intonation/Library/View/Wrapper/ItemForOsm.php
+++ b/library/templates/Intonation/Library/View/Wrapper/ItemForOsm.php
@@ -27,9 +27,7 @@ class Intonation_Library_View_Wrapper_ItemForOsm extends Intonation_Library_View
     if (!$library = $this->_model->getBib())
       return $description;
 
-    $wrapper = (new Intonation_Library_View_Wrapper_Library)
-      ->setModel($library)
-      ->setView($this->_view);
+    $wrapper = Class_Template::current()->newWrapper($library, $this->_view);
 
     return
       $description
diff --git a/library/templates/Intonation/Template.php b/library/templates/Intonation/Template.php
index 70e84abab3f..508d16fd26c 100644
--- a/library/templates/Intonation/Template.php
+++ b/library/templates/Intonation/Template.php
@@ -408,6 +408,7 @@ class Intonation_Template extends Class_Template {
 
 
   protected function _getMapWrapper() {
-    return ['Class_Notice' => 'Intonation_Library_View_Wrapper_Record'];
+    return ['Class_Notice' => 'Intonation_Library_View_Wrapper_Record',
+            'Class_Bib' => 'Intonation_Library_View_Wrapper_Library'];
   }
 }
diff --git a/library/templates/Intonation/View/Grid.php b/library/templates/Intonation/View/Grid.php
index 9fd7684525c..bb50c9dc8cb 100644
--- a/library/templates/Intonation/View/Grid.php
+++ b/library/templates/Intonation/View/Grid.php
@@ -26,6 +26,9 @@ class Intonation_View_Grid extends ZendAfi_View_Helper_BaseHelper {
     if (!$html)
       return '';
 
+    if (is_array($html))
+      $html = implode($html);
+
     if (!isset($container_attribs['class']))
       $container_attribs ['class'] = '';
 
diff --git a/tests/scenarios/Templates/ChiliLibraryOSMTest.php b/tests/scenarios/Templates/ChiliLibraryOSMTest.php
new file mode 100644
index 00000000000..955a16ebc27
--- /dev/null
+++ b/tests/scenarios/Templates/ChiliLibraryOSMTest.php
@@ -0,0 +1,109 @@
+<?php
+/**
+ * Copyright (c) 2012-2020, 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 ChiliLibraryOSMInRecordItemsTest extends AbstractControllerTestCase {
+
+  protected $_storm_default_to_volatile = true;
+
+
+  public function setUp() {
+    parent::setUp();
+
+    $this->_buildTemplateProfil(['id' => 25,
+                                 'template' => 'CHILI']);
+    $this->fixture('Class_Notice',
+                   ['id' => 153,
+                    'exemplaires' => [
+                                      $this->fixture('Class_Exemplaire',
+                                                     ['id' => 352,
+                                                      'id_bib' => 2
+                                                     ]),
+                                      $this->fixture('Class_Exemplaire',
+                                                     ['id' => 353,
+                                                      'id_bib' => 3
+                                                     ])
+                    ]
+                   ]);
+
+    $this->fixture('Class_Bib',
+                   ['id' => 2,
+                    'libelle' => "Annecy",
+                    'id_lieu' => 3,
+                    'horaire' => 'Lundi : 9h00'
+                   ]);
+
+    $this->fixture('Class_Lieu',
+                   ['id' => 3,
+                    'libelle' => "Bonlieu",
+                    'latitude' => '45.5',
+                    'longitude' => '5'
+                   ]);
+
+
+    $this->fixture('Class_Bib',
+                   ['id' => 3,
+                    'libelle' => "Dombes",
+                    'id_lieu' => 4
+                   ]);
+
+    $this->fixture('Class_Lieu',
+                   ['id' => 4,
+                    'libelle' => "Autrelieu",
+                    'latitude' => '49.5',
+                    'longitude' => '7'
+                   ]);
+
+    $this->fixture('Class_Ouverture',
+                   ['id' => 10,
+                    'label' => 'Normal',
+                    'debut_matin' => '09:00',
+                    'jour_semaine' => Class_Ouverture::MARDI,
+                    'id_site' => 3
+                   ]);
+
+    $this->dispatch('noticeajax/items-resources/id/153/id_profil/25');
+  }
+
+
+  /** @test */
+  public function dataOSMShouldContainsAnnecyOuvertLundiA9h00() {
+    $this->assertXPath('//div[contains(@id,"osm_map")][contains(@data-osm,"Lundi : 9h00")]');
+  }
+
+
+  /** @test */
+  public function dataOSMShouldContainsDombesOuvertMardiA15h00() {
+    $this->assertXPath('//div[contains(@id,"osm_map")][contains(@data-osm,"Mardi : 09h")]');
+  }
+
+
+  /** @test */
+  public function dataOSMShouldContainsClassLibraryOpeningsCol12() {
+    $this->assertXPath('//div[contains(@id,"osm_map")][contains(@data-osm,"description_library_openings col-12")]');
+  }
+
+
+  /** @test */
+  public function dataOSMShouldContainsClassLibraryOpenedCol12() {
+    $this->assertXPath('//div[contains(@id,"osm_map")][contains(@data-osm,"description_library_opened col-12")]');
+  }
+}
-- 
GitLab