From 7c0cec4c26fb70d62b8dd41817094b349145d854 Mon Sep 17 00:00:00 2001
From: gloas <gloas@afi-sa.fr>
Date: Fri, 15 Sep 2017 16:48:47 +0200
Subject: [PATCH] dev #64573 plug try template feature

---
 .gitignore                                    |   1 +
 .../admin/controllers/SkinController.php      |  13 +-
 .../admin/views/scripts/skin/index.phtml      |  19 +-
 library/Class/Template.php                    | 151 +++++++++
 public/opac/skins/intonation/css/global.css   | 291 ++++++++++++++++++
 .../boites/boite_banniere_droite.html         |   8 +
 .../boites/boite_banniere_gauche.html         |   8 +
 .../boites/boite_de_la_division_droite.html   |  17 +
 .../boite_de_la_division_du_milieu.html       |  20 ++
 .../boites/boite_de_la_division_gauche.html   |  15 +
 .../templates/boites/boite_telephone.html     |  10 +
 .../templates/boites/boite_vide.html          |   7 +
 .../admin/controllers/SkinControllerTest.php  |   9 +-
 13 files changed, 560 insertions(+), 9 deletions(-)
 create mode 100644 library/Class/Template.php
 create mode 100644 public/opac/skins/intonation/css/global.css
 create mode 100644 public/opac/skins/intonation/templates/boites/boite_banniere_droite.html
 create mode 100644 public/opac/skins/intonation/templates/boites/boite_banniere_gauche.html
 create mode 100644 public/opac/skins/intonation/templates/boites/boite_de_la_division_droite.html
 create mode 100644 public/opac/skins/intonation/templates/boites/boite_de_la_division_du_milieu.html
 create mode 100644 public/opac/skins/intonation/templates/boites/boite_de_la_division_gauche.html
 create mode 100644 public/opac/skins/intonation/templates/boites/boite_telephone.html
 create mode 100644 public/opac/skins/intonation/templates/boites/boite_vide.html

diff --git a/.gitignore b/.gitignore
index e33f9836fd7..3d9665087b2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,6 +10,7 @@
 # Ignore all but the base skins
 /skins/*
 /public/opac/skins/*
+!/public/opac/skins/intonation
 !/public/opac/skins/modele
 !/public/opac/skins/original
 !/public/opac/skins/responsive
diff --git a/application/modules/admin/controllers/SkinController.php b/application/modules/admin/controllers/SkinController.php
index 6b525a3e195..736d60e4ae9 100644
--- a/application/modules/admin/controllers/SkinController.php
+++ b/application/modules/admin/controllers/SkinController.php
@@ -22,12 +22,19 @@
 
 class Admin_SkinController extends ZendAfi_Controller_Action {
   public function indexAction() {
-    $this->view->titre = $this->_('Essayer une autre charte graphique');
+    $this->view->titre = $this->_('Changer la charte graphique');
+    $this->view->templates = (new Class_Template)->getTemplates();
   }
 
 
   public function tryAction() {
-    Class_Profil::setCurrentProfil(Class_Profil::find($this->_getParam('on')));
-    $this->_forward('index', 'index', 'opac');
+    if(!$this->view->id_profile = (new Class_Template)
+      ->tryTemplateOn($this->_getParam('template'),
+                      $this->_getParam('on'))) {
+      $this->_helper->notify($this->_('Une erreur c\'est produite. Vous ne pouvez pas tester le template'));
+      return $this->_redirectToIndex();
+    }
+
+    $this->_forward('index', 'index', 'opac', ['id_profil' => $this->view->id_profile]);
   }
 }
\ No newline at end of file
diff --git a/application/modules/admin/views/scripts/skin/index.phtml b/application/modules/admin/views/scripts/skin/index.phtml
index 48725676f2c..fdb038306f0 100644
--- a/application/modules/admin/views/scripts/skin/index.phtml
+++ b/application/modules/admin/views/scripts/skin/index.phtml
@@ -1,5 +1,16 @@
 <?php
-//(new Class_Profil())->getAvailableSkins();
-echo $this->tagPreview(Class_Url::relative('/admin/skin/try/skin/evolution/on/1'),
-                      $this->_('Essayer la charte Evolution'));
-?>
\ No newline at end of file
+$description = (new Class_TableDescription('templates'))
+  ->addColumn($this->_('Titre'), function($template)
+              {
+                return $template->getTitle();
+              })
+
+  ->addRowAction(function($template)
+                 {
+                   return $this->tagPreview($template->getTryUrl(),
+                                            $this->_('Essayer "%s"', $template->getTitle()));
+                 });
+
+echo $this->renderTable($description,
+                        $this->templates,
+                        ['sorter' => true]);
\ No newline at end of file
diff --git a/library/Class/Template.php b/library/Class/Template.php
new file mode 100644
index 00000000000..4bb5b9bb8c3
--- /dev/null
+++ b/library/Class/Template.php
@@ -0,0 +1,151 @@
+<?php
+/**
+ * Copyright (c) 2012-2017, 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 Class_Template {
+  public function getTemplates() {
+    return [
+            new Template_Evo(),
+            new Template_Responsive()
+    ];
+  }
+
+
+  public function find($id) {
+    $template =  (new Storm_Collection($this->getTemplates()))
+      ->select(function($template) use ($id)
+               {
+                 return $id == $template->getId();
+               });
+
+    if($template->isEmpty())
+      return null;
+
+    return $template->first();
+  }
+
+
+  public function tryTemplateOn($id, $id_profile) {
+    if(!$template = $this->find($id))
+      return null;
+
+    if(!$profile = Class_Profil::find($id_profile))
+      return null;
+
+    $temp_profile = $profile->copy();
+
+    return $template->upgrade($temp_profile)
+      ? $temp_profile->getId()
+      : null;
+  }
+}
+
+
+
+class Template_Base extends Class_Entity {
+  use Trait_Translator;
+
+  public function getTryUrl() {
+    return Class_Url::relative(sprintf('/admin/skin/try/template
+/%s/on/1', $this->getId()));
+  }
+}
+
+
+
+
+class Template_Responsive extends Template_Base {
+  public function __construct() {
+    $this->_attribs = ['Id' => 'RES',
+                       'Title' => $this->_('Responsive')];
+    $this
+      ->setId('RES')
+      ->setTitle($this->_('Template responsive'))
+      ->setSkin('intonation');
+  }
+
+
+  public function upgrade($profile) {
+    $profile
+      ->setSkin($this->getSkin());
+
+    $profile
+      ->setCfgSiteParam('barre_nav_on', '1')
+      ->setCfgSiteParam('accessibilite_on', '')
+      ->setCfgSiteParam('hauteur_banniere', '')
+      ->setCfgSiteParam('responsive', '1')
+      ->setCfgSiteParam('couleur_lien_bandeau', '')
+      ->setCfgSiteParam('couleur_texte_bandeau', '')
+
+      ->setCfgSiteParam('largeur_site', '90')
+      ->setCfgSiteParam('size_site_scale', 'percent')
+
+      ->setCfgSiteParam('width_division1_scale', 'percent')
+      ->setCfgSiteParam('width_division2_scale', 'percent')
+      ->setCfgSiteParam('width_division3_scale', 'percent')
+
+      ->setCfgSiteParam('marge_division1', '')
+      ->setCfgSiteParam('marge_division2', '')
+      ->setCfgSiteParam('marge_division3', '');
+
+    $this->_setWidths($profile);
+
+    (new Class_Profil_Preferences())
+      ->setModulePref($profile,
+                      (new Class_Entity())
+                      ->setController('recherche')
+                      ->setAction('resultat')
+                      ->setSubAction('simple'),
+                      ['header_composition' => 'Advanced;History;Order;PageSize;']);
+
+    $profile->save();
+    return $profile;
+  }
+
+
+  protected function _setWidths($profile) {
+    if(1 == $profile->getCfgSiteParam('nb_divisions'))
+      return $profile
+        ->setCfgSiteParam('largeur_division1', '100');
+
+    if(2 == $profile->getCfgSiteParam('nb_divisions'))
+      return $profile
+        ->setCfgSiteParam('largeur_division1', '20')
+        ->setCfgSiteParam('largeur_division2', '80')
+        ->setCfgSiteParam('largeur_division3', '20');
+
+    return $profile
+      ->setCfgSiteParam('largeur_division1', '20')
+      ->setCfgSiteParam('largeur_division2', '60')
+      ->setCfgSiteParam('largeur_division3', '20');
+  }
+}
+
+
+
+class Template_Evo extends Template_Responsive {
+  public function __construct() {
+    parent::__construct();
+    $this
+      ->setId('EVO')
+      ->setTitle($this->_('Template evolutif'));
+  }
+}
diff --git a/public/opac/skins/intonation/css/global.css b/public/opac/skins/intonation/css/global.css
new file mode 100644
index 00000000000..463c12ea90e
--- /dev/null
+++ b/public/opac/skins/intonation/css/global.css
@@ -0,0 +1,291 @@
+/* Global */
+:root {
+    --front-text: #3B3B3B;
+    --front-title: #333333;
+    --front-anchor: #1B1B1B;
+    --front-anchor-highlight: #000;
+    --front-error-text: #F00;
+
+    --front-shadow: rgba(0, 0 , 0 ,0.3);
+    --front-separator: rgba(0 ,0 ,0 , 0.15);
+
+    --front-background: #F0F0F0;
+    --front-widget-background: #FFF;
+    --front-navbar-background: #CCC;
+}
+
+body.opac {
+    font-family: open sans;
+    color: var(--front-text);
+    font-size: 14px;
+    margin: 0;
+    padding: 0;
+}
+
+#site_web_wrapper * {
+    font-family: open sans;
+    font-size: 1em;
+}
+
+#site_web_wrapper h1,
+#site_web_wrapper h2,
+#site_web_wrapper h3,
+#site_web_wrapper h4 {
+    color: var(--front-title);
+    white-space: normal;
+    margin: 0;
+    padding: 0.5ex 0.5em;
+    font-weight: normal;
+    cursor: default;
+}
+
+#site_web_wrapper h1,
+#site_web_wrapper h2 {
+    font-size: 18px;
+}
+
+#site_web_wrapper #menu_horizontal a,
+#site_web_wrapper h3 {
+    font-size: 16px;
+}
+
+#site_web_wrapper h4 {
+    font-size: 15px;
+}
+
+#site_web_wrapper #menu_horizontal a,
+#site_web_wrapper #menu_horizontal a:visited,
+a,
+a:visited {
+    font-weight: normal;
+    text-decoration: none;
+    color: var(--front-anchor);
+    transition: all 0s;
+}
+
+#site_web_wrapper #menu_horizontal a:focus,
+#site_web_wrapper #menu_horizontal a:hover,
+#site_web_wrapper a:focus,
+#site_web_wrapper a:hover {
+    color: var(--front-anchor-highlight);
+    text-decoration: underline;
+}
+
+#site_web_wrapper #header .boite,
+#site_web_wrapper #colContenuInner > *:not(.configuration_module):not(.boite),
+#site_web_wrapper #menu_horizontal,
+#site_web_wrapper #menu_horizontal > ul > li > ul,
+#site_web_wrapper #col_wrapper .boite:not(.conteneur_deux_colonnes),
+#site_web_wrapper #col_wrapper .barre_nav {
+    box-shadow: 1px 1px 5px var(--front-shadow);
+}
+
+#site_web_wrapper #menu_horizontal > ul > li > ul > li:not(:first-child) {
+    border-top: 1px solid var(--front-separator);
+}
+
+#site_web_wrapper #menu_horizontal > ul > li > ul > li,
+#site_web_wrapper #header .boite,
+#site_web_wrapper #colContenuInner > *:not(.configuration_module):not(.boite),
+#site_web_wrapper #col_wrapper .boite:not(.conteneur_deux_colonnes),
+#site_web_wrapper #col_wrapper .barre_nav {
+    background-color: var(--front-widget-background);
+}
+
+
+/* Conteneur site */
+#site_web_wrapper #right_col_color {
+    display: inline-block;
+    vertical-align: top;
+}
+
+/* Eléments qui sont redimensionnés en fonction de leur conteneur  */
+.auto_resize img,
+.auto_resize object,
+.auto_resize embed {
+    display:none;
+}
+
+/* Footer */
+
+/* Menu horizontal */
+#site_web_wrapper #menu_horizontal {
+    background: var(--front-navbar-background);
+    white-space: nowrap;
+    height: inherit;
+    margin: inherit;
+    padding: inherit;
+    text-align: center;
+}
+
+#site_web_wrapper #site_web_wrapper #menu_horizontal {
+    height: auto;
+}
+
+#site_web_wrapper #menu_horizontal img {
+    vertical-align: middle;
+    margin-right: 5px;
+}
+
+#site_web_wrapper #menu_horizontal ul,
+#site_web_wrapper #menu_horizontal li {
+    padding: 0;
+    margin: 0;
+}
+
+#site_web_wrapper #menu_horizontal ul li a {
+    margin: 0.5ex 0.5em;
+    padding: 0.5ex 0.5em;
+    display: inline-block;
+}
+
+
+#site_web_wrapper #menu_horizontal li {
+    vertical-align: middle;
+    list-style: none;
+    display: inline-block;
+    text-align: left;
+}
+
+#menu_horizontal ul li ul
+{
+	border: 1px solid #B0BEC7;
+	background-color: #FFFFFF;
+	display: none;
+	position: absolute;
+	top: 1.5em;
+	left: 2.5em;
+	padding: 2px;
+	z-index: 101;
+}
+
+#site_web_wrapper #menu_horizontal ul li {
+    position: relative;
+}
+
+#site_web_wrapper #menu_horizontal ul li ul {
+    display: none;
+    position: absolute;
+    z-index: 101;
+    top: auto;
+}
+
+#site_web_wrapper #menu_horizontal ul li ul li {
+    display: block;
+    height: auto;
+}
+
+#site_web_wrapper #menu_horizontal ul li.over ul {
+    display: block;
+}
+
+/* Menu Gauche */
+#site_web_wrapper .facette ul,
+#site_web_wrapper #menu_horizontal ul,
+#site_web_wrapper .menuGauche ul {
+    list-style: none;
+    margin: 0;
+    padding: 0;
+}
+
+#site_web_wrapper .menuGauche img{
+    margin-right:5px;
+}
+
+/* Boites */
+#site_web_wrapper #header .boite,
+#site_web_wrapper #colContenuInner > div .contenu,
+#site_web_wrapper .boite:not(.conteneur_deux_colonnes) .contenu,
+#site_web_wrapper #col_wrapper .barre_nav {
+    padding: 1ex 1em;
+}
+
+#site_web_wrapper #colContenuInner > *:not(.configuration_module):not(.boite),
+#site_web_wrapper #col_wrapper .boite:not(.conteneur_deux_colonnes),
+#site_web_wrapper #col_wrapper .barre_nav {
+    margin: 2ex 1em;
+}
+
+#site_web_wrapper .boite .rss{
+    position: absolute;
+    top: 1ex;
+    right: 0.5em;
+}
+
+.form td.masque{
+    text-align:right;
+}
+
+.form td.saisie{
+    text-align:left;
+}
+
+.submit {
+    background:transparent url(../images/bouton/btn_ok.gif) no-repeat scroll 0 0;
+    border:0 none;
+    cursor:pointer;
+    height:18px;
+    width:18px;
+}
+
+#site_web_wrapper .panier_index .submit {
+    font-size: 0px;
+}
+
+#site_web_wrapper .bibview_find .submit {
+    font-size: 0px;
+}
+
+.calendar_title td {
+    text-align:center;
+}
+
+.calendar_table {
+    border: none;
+}
+
+.calendar_table td,
+.calendar_table th {
+    text-align: center;
+}
+
+/* Error */
+.error {
+    color: var(--front-error-text);
+    font-weight:bold;
+}
+
+
+/* Boites bannière*/
+#site_web_wrapper > div.siteWeb,
+#site_web_wrapper > div.siteWeb > div#site_web_content,
+#site_web_wrapper > div.siteWeb > div#site_web_content > div#col_wrapper {
+    width: auto;
+    float: none;
+    height: auto;
+}
+
+#site_web_wrapper #banniere > a.home > img {
+    width: auto !important;
+}
+
+#site_web_wrapper #header > div {
+    display: inline-block;
+    vertical-align: top;
+}
+
+#site_web_wrapper #header .boite {
+    margin: 1ex 1em;
+}
+
+#site_web_wrapper [class*="menu"] a[href="#"] {
+    pointer-events: none;
+}
+
+#site_web_wrapper [class*="menu"] li {
+    cursor: default;
+}
+
+#site_web_wrapper #col_wrapper {
+    background: var(--front-background);
+}
diff --git a/public/opac/skins/intonation/templates/boites/boite_banniere_droite.html b/public/opac/skins/intonation/templates/boites/boite_banniere_droite.html
new file mode 100644
index 00000000000..9a272b840a4
--- /dev/null
+++ b/public/opac/skins/intonation/templates/boites/boite_banniere_droite.html
@@ -0,0 +1,8 @@
+<div class="boiteBanniereDroite">
+	<div class="boiteBanniereDroiteInner">
+			{IF-TITRE}			
+			<h1>{TITRE}</h1>
+			{ENDIF}
+			{CONTENU}
+	</div>
+</div>
diff --git a/public/opac/skins/intonation/templates/boites/boite_banniere_gauche.html b/public/opac/skins/intonation/templates/boites/boite_banniere_gauche.html
new file mode 100644
index 00000000000..000278038a8
--- /dev/null
+++ b/public/opac/skins/intonation/templates/boites/boite_banniere_gauche.html
@@ -0,0 +1,8 @@
+<div class="boiteBanniereGauche">
+	<div class="boiteBanniereGaucheInner">
+			{IF-TITRE}			
+			<h1>{TITRE}</h1>
+			{ENDIF}
+			{CONTENU}
+	</div>
+</div>
diff --git a/public/opac/skins/intonation/templates/boites/boite_de_la_division_droite.html b/public/opac/skins/intonation/templates/boites/boite_de_la_division_droite.html
new file mode 100644
index 00000000000..092c5890db4
--- /dev/null
+++ b/public/opac/skins/intonation/templates/boites/boite_de_la_division_droite.html
@@ -0,0 +1,17 @@
+<div class="boiteDroite">
+	<div class="boiteDroiteInner">
+		{IF-TITRE}
+
+	
+	<div class="titre">
+		<div><h1>{TITRE}</h1></div>
+		<div class="rss">{RSS}</div>
+	</div>
+
+		{ENDIF}
+	
+	<div class="contenu">
+		{CONTENU}
+	</div>
+	</div>
+</div>
diff --git a/public/opac/skins/intonation/templates/boites/boite_de_la_division_du_milieu.html b/public/opac/skins/intonation/templates/boites/boite_de_la_division_du_milieu.html
new file mode 100644
index 00000000000..ed17d4ab2ab
--- /dev/null
+++ b/public/opac/skins/intonation/templates/boites/boite_de_la_division_du_milieu.html
@@ -0,0 +1,20 @@
+<div class="boiteMilieu">
+	<div class="boiteMilieuInner">
+		{IF-TITRE}
+
+	<div class="titre">
+			<div class="titreInner">
+				<h1>{TITRE}</h1>
+				<div class="rss">{RSS}</div>
+			</div>
+	</div>
+
+		{ENDIF}
+	
+	<div class="contenu">
+  	<div class="contenuInner">
+		{CONTENU}
+		</div>
+	</div>
+	</div>
+</div>
diff --git a/public/opac/skins/intonation/templates/boites/boite_de_la_division_gauche.html b/public/opac/skins/intonation/templates/boites/boite_de_la_division_gauche.html
new file mode 100644
index 00000000000..e92210e9cea
--- /dev/null
+++ b/public/opac/skins/intonation/templates/boites/boite_de_la_division_gauche.html
@@ -0,0 +1,15 @@
+<div class="boiteGauche">
+	<div class="boiteGaucheInner">
+
+		{IF-TITRE}
+		<div class="titre">
+			<div><h1>{TITRE}</h1></div>
+			<div class="rss">{RSS}</div>
+		</div>
+		{ENDIF}
+	
+		<div class="contenu">
+			{CONTENU}
+		</div>
+	</div>
+</div>
diff --git a/public/opac/skins/intonation/templates/boites/boite_telephone.html b/public/opac/skins/intonation/templates/boites/boite_telephone.html
new file mode 100644
index 00000000000..1992b70726b
--- /dev/null
+++ b/public/opac/skins/intonation/templates/boites/boite_telephone.html
@@ -0,0 +1,10 @@
+<div class="{TYPE_MODULE} boite_accueil">
+  <a href="#" class="app-icon"></a>
+  <a href="#" class="icon-retour"></a>
+		{IF-TITRE}
+                    <div class="img-titre"><div class="titre"><h2>{TITRE}</h2></div></div>
+
+		{ENDIF}
+			<div class="contenu">{CONTENU}</div>
+			
+</div>
diff --git a/public/opac/skins/intonation/templates/boites/boite_vide.html b/public/opac/skins/intonation/templates/boites/boite_vide.html
new file mode 100644
index 00000000000..2ec9111d862
--- /dev/null
+++ b/public/opac/skins/intonation/templates/boites/boite_vide.html
@@ -0,0 +1,7 @@
+<div class="boiteVide">
+	<div class="boiteVideInner">
+		<div class="titre"><h1>{TITRE}</h1></div>
+		<div class="rss">{RSS}</div>
+		<div class="contenu">{CONTENU}</div>
+	</div>
+</div>
diff --git a/tests/application/modules/admin/controllers/SkinControllerTest.php b/tests/application/modules/admin/controllers/SkinControllerTest.php
index 7da1ac31837..52d087a80d9 100644
--- a/tests/application/modules/admin/controllers/SkinControllerTest.php
+++ b/tests/application/modules/admin/controllers/SkinControllerTest.php
@@ -40,12 +40,17 @@ class SkinControllerIndexDispatchTest extends Admin_AbstractControllerTestCase {
 class SkinControllerTryDispatchTest extends Admin_AbstractControllerTestCase {
   public function setUp() {
     parent::setUp();
-    $this->dispatch('/admin/skin/try/skin/evolution/on/1?iframe=true&width=95%25&height=95%25', true);
+
+    $this->fixture('Class_Profil',
+                   ['id' => 1,
+                   ]);
+
+    $this->dispatch('/admin/skin/try/template/EVO/on/1?iframe=true&width=95%25&height=95%25', true);
   }
 
 
   /** @test */
   public function shouldForwardToBokehIndex() {
-    $this->assertXPath('//body[contains(@class, "opac")]');
+    $this->assertXPath('//body[contains(@class, "opac")][contains(@class, "profil_2")]');
   }
 }
\ No newline at end of file
-- 
GitLab