From 7765dcded9cb8970a64189ab19d5b7528d662dac Mon Sep 17 00:00:00 2001
From: efalcy <stl@gresille.org>
Date: Thu, 6 Mar 2014 17:49:07 +0100
Subject: [PATCH] rel #12091 : add zendform to switch between list and wall

---
 .../admin/controllers/ModulesController.php   | 15 +++-
 .../admin/views/scripts/modules/domains.phtml |  9 +--
 library/Class/Profil.php                      |  1 -
 library/Class/Systeme/ModulesAccueil.php      |  2 +-
 .../Systeme/ModulesAccueil/DomainBrowser.php  |  7 +-
 library/Class/Systeme/ModulesAppli.php        | 12 ++-
 .../Form/Configuration/DomainModule.php       | 74 +++++++++++++++++++
 .../View/Helper/RenderDomainBrowser.php       |  4 +-
 .../View/Helper/Accueil/DomainBrowserTest.php |  5 ++
 9 files changed, 111 insertions(+), 18 deletions(-)
 create mode 100644 library/ZendAfi/Form/Configuration/DomainModule.php

diff --git a/application/modules/admin/controllers/ModulesController.php b/application/modules/admin/controllers/ModulesController.php
index a2588c113fe..44058068579 100644
--- a/application/modules/admin/controllers/ModulesController.php
+++ b/application/modules/admin/controllers/ModulesController.php
@@ -122,10 +122,19 @@ class Admin_ModulesController extends ZendAfi_Controller_Action {
 		return $this->_simpleAction('blog_all');
 	}
 
-
+	
 	public function domainsAction() {
-		$this->view->display_mode = Class_Profil::getCurrentProfil()->getModulePreference('domains', 'browse' , 'display_mode');
-		return $this->_simpleAction('domains');
+		$post_values = $this->_request->getPost();
+		$form = 
+			ZendAfi_Form_Configuration_DomainModule::newConfigurationWith(
+				array_merge(Class_Profil::getCurrentProfil()
+										->getConfigurationOf('domains', 'browse', ''),
+										$post_values));
+
+		if ($this->_request->isPost() && $form->isValid($post_values))
+			return $this->updateEtRetour($post_values);
+
+		$this->view->form = $form;
 	}
 
 
diff --git a/application/modules/admin/views/scripts/modules/domains.phtml b/application/modules/admin/views/scripts/modules/domains.phtml
index 592ea00c2a4..f5a2baab1ab 100644
--- a/application/modules/admin/views/scripts/modules/domains.phtml
+++ b/application/modules/admin/views/scripts/modules/domains.phtml
@@ -1,8 +1 @@
-<?php 
-echo $this->render('modules/_debut.phtml');
-echo $this->tag('input', 
-								'', 
-								['name'=>'display_mode',
-								 'value' => $this->display_mode]);
-echo $this->render('modules/_fin.phtml');
-?>
+<?php 		echo $this->renderForm($this->form); ?>
diff --git a/library/Class/Profil.php b/library/Class/Profil.php
index b0d2fdc51cc..617c870627b 100644
--- a/library/Class/Profil.php
+++ b/library/Class/Profil.php
@@ -752,7 +752,6 @@ class Class_Profil extends Storm_Model_Abstract {
 	
 	public function setModulePreference($controller,$action,$pref,$value) {
 			$cfg_modules = $this->getCfgModulesAsArray();
-			xdebug_break();
 			$cfg_modules[$controller][$action][$pref]=$value;
 			$this->setCfgModules($cfg_modules)->save();
 	}
diff --git a/library/Class/Systeme/ModulesAccueil.php b/library/Class/Systeme/ModulesAccueil.php
index 9c0e22a9dbe..e622591820c 100644
--- a/library/Class/Systeme/ModulesAccueil.php
+++ b/library/Class/Systeme/ModulesAccueil.php
@@ -126,7 +126,7 @@ class Class_Systeme_ModulesAccueil extends Class_Systeme_ModulesAbstract {
 												 'MULTIMEDIA' => new Class_Systeme_ModulesAccueil_Multimedia,
 												 'HISTORIQUE_RECHERCHES' => new Class_Systeme_ModulesAccueil_HistoriqueRecherches,
 												 'PANIER' => new Class_Systeme_ModulesAccueil_Panier,
-												 'DOMAIN_BROWSER' => new Class_Systeme_ModulesAccueil_DomainBrowser,
+												 'DOMAIN_BROWSER' => new Class_Systeme_ModulesAccueil_DomainBrowser
 				];
 			}
 
diff --git a/library/Class/Systeme/ModulesAccueil/DomainBrowser.php b/library/Class/Systeme/ModulesAccueil/DomainBrowser.php
index 6408cd76574..cf272a21c73 100644
--- a/library/Class/Systeme/ModulesAccueil/DomainBrowser.php
+++ b/library/Class/Systeme/ModulesAccueil/DomainBrowser.php
@@ -30,11 +30,14 @@ class Class_Systeme_ModulesAccueil_DomainBrowser extends Class_Systeme_ModulesAc
 
 	protected $_popupWidth = 600;
 
-	protected $_popupHeight = 600;
+	protected $_popupHeight = 700;
 
 	protected $_defaultValues = ['titre' => 'Domaines',
 															 'root_domain_id' => 0,
 															 'allow_breadcrumb' => 1,
-															 'display_mode' => 'wall'];
+															 'display_mode' => Class_Systeme_ModulesAppli::LISTE_FORMAT_MUR];
+
+
+
 }
 ?>
\ No newline at end of file
diff --git a/library/Class/Systeme/ModulesAppli.php b/library/Class/Systeme/ModulesAppli.php
index 0691c869992..f44e70f88fe 100644
--- a/library/Class/Systeme/ModulesAppli.php
+++ b/library/Class/Systeme/ModulesAppli.php
@@ -140,7 +140,7 @@ class Class_Systeme_ModulesAppli extends Class_Systeme_ModulesAbstract {
 		
 		'domains' => ['*' => ['libelle' => 'Domaines', 
 													'popup_width' => 710, 
-													'popup_height' => 620]]
+													'popup_height' => 200]]
 		];
 
 
@@ -158,6 +158,16 @@ class Class_Systeme_ModulesAppli extends Class_Systeme_ModulesAbstract {
 	}
 
 
+	public static function getAvailableListeDomainsFormat() {
+		return 
+			[
+				Class_Systeme_ModulesAppli::LISTE_FORMAT_ACCORDEON => 'Liste',
+				Class_Systeme_ModulesAppli::LISTE_FORMAT_MUR => 'Mur'
+				];
+			 
+	}
+
+
 	/**
 	 * @param string $type_module
 	 * @param string $action
diff --git a/library/ZendAfi/Form/Configuration/DomainModule.php b/library/ZendAfi/Form/Configuration/DomainModule.php
new file mode 100644
index 00000000000..354b8a2ca5a
--- /dev/null
+++ b/library/ZendAfi/Form/Configuration/DomainModule.php
@@ -0,0 +1,74 @@
+<?php
+/**
+ * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
+ *
+ * AFI-OPAC 2.0 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).
+ *
+ * AFI-OPAC 2.0 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 AFI-OPAC 2.0; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA 
+ */
+
+
+
+class ZendAfi_Form_Configuration_DomainModule extends ZendAfi_Form {
+
+	protected $_text_size = 40;
+	protected $_num_size = 4;
+
+	
+	public static function newConfigurationWith($conf) {
+		$form = new self();
+		$form
+			->populate($conf)
+			->addDisplayGroup([
+												 'boite', 
+												 'display_mode'
+													],
+												'Module', 
+												['legend' => $form->_('Module')])
+			->addDisplayGroup(['submit'],
+												'submit',
+												['legend' => '']);
+;
+		
+		return $form;
+	}
+
+	
+	public function init() {
+		parent::init();
+		$this
+			->setAttrib('id', 
+									'configuration_domainModule')
+			->addElement('select',
+									 'boite', 
+									 ['label' => $this->_('Style de boite'),
+										'multiOptions' => (new Class_Profil_Templates(
+																				 Class_Profil::getCurrentProfil()))->toArray()])
+		
+			->addElement('select', 
+									 'display_mode', 
+									 ['label' => $this->_('Format'),
+										'multiOptions' => Class_Systeme_ModulesAppli::getAvailableListeDomainsFormat()])
+			->addElement('submit', 
+									 'submit', 
+									 ['label' => $this->_('Valider')]);
+;
+			
+	}
+
+
+
+} 
+?>
\ No newline at end of file
diff --git a/library/ZendAfi/View/Helper/RenderDomainBrowser.php b/library/ZendAfi/View/Helper/RenderDomainBrowser.php
index a045e874ec3..6c0fbed1680 100644
--- a/library/ZendAfi/View/Helper/RenderDomainBrowser.php
+++ b/library/ZendAfi/View/Helper/RenderDomainBrowser.php
@@ -30,10 +30,10 @@ class ZendAfi_View_Helper_RenderDomainBrowser extends ZendAfi_View_Helper_BaseHe
 		$this->_root = $root;
 		$this->_breadcrumb_str = (string)$breadcrumb_str;
 		$this->_allow_breadcrumb = $allow_breadcrumb;
-		xdebug_break();
+
 		$profil = Class_Profil::getCurrentProfil();
 		$display_mode = $profil->getModulePreference('domains','browse','display_mode');
-		$this->render = $display_mode == 'wall'
+		$this->render = $display_mode == 	Class_Systeme_ModulesAppli::LISTE_FORMAT_MUR
 			? new ZendAfi_View_Helper_RenderDomainBrowser_Wall($this->view)
 			: new ZendAfi_View_Helper_RenderDomainBrowser_List($this->view);
 
diff --git a/tests/library/ZendAfi/View/Helper/Accueil/DomainBrowserTest.php b/tests/library/ZendAfi/View/Helper/Accueil/DomainBrowserTest.php
index f5446bfdb2b..25555b32239 100644
--- a/tests/library/ZendAfi/View/Helper/Accueil/DomainBrowserTest.php
+++ b/tests/library/ZendAfi/View/Helper/Accueil/DomainBrowserTest.php
@@ -29,6 +29,11 @@ abstract class ZendAfi_View_Helper_Accueil_DomainBrowserTestCase extends ViewHel
 	public function setUp() {
 		parent::setUp();
 		Class_CodifThesaurus::beVolatile();
+		Class_Profil::getCurrentProfil()->setModulePreference('domains', 
+																													'browse', 
+																													'display_mode', 
+																													'list');
+
 		$this->fixture('Class_Catalogue',
 									 ['id' => 1,
 										'libelle' => 'Metal']);
-- 
GitLab