From f42fb91cab17777695de1dcf760a12ee89a796eb Mon Sep 17 00:00:00 2001
From: vinot <g.vinot@ville-montrouge.fr>
Date: Sat, 27 Jun 2015 14:55:29 +0200
Subject: [PATCH] =?UTF-8?q?Premier=20chapitre=20version=201.2=20avec=20mai?=
 =?UTF-8?q?ntenant=20un=20bloc=20param=C3=A9trable?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../admin/controllers/AccueilController.php   |  5 ++
 .../scripts/accueil/premier-chapitre.phtml    | 74 +++++++++++++++++++
 library/Class/Systeme/ModulesAccueil.php      |  1 +
 .../ModulesAccueil/PremierChapitre.php        | 43 +++++++++++
 .../View/Helper/Accueil/PremierChapitre.php   | 33 +++++++++
 .../View/Helper/PremierChapitre/Abstract.php  |  2 +-
 .../View/Helper/RenderPremierChapitre.php     | 72 ++++++++++++++++++
 7 files changed, 229 insertions(+), 1 deletion(-)
 create mode 100644 application/modules/admin/views/scripts/accueil/premier-chapitre.phtml
 create mode 100644 library/Class/Systeme/ModulesAccueil/PremierChapitre.php
 create mode 100644 library/ZendAfi/View/Helper/Accueil/PremierChapitre.php
 create mode 100644 library/ZendAfi/View/Helper/RenderPremierChapitre.php

diff --git a/application/modules/admin/controllers/AccueilController.php b/application/modules/admin/controllers/AccueilController.php
index b4b8830e12b..f460775b000 100644
--- a/application/modules/admin/controllers/AccueilController.php
+++ b/application/modules/admin/controllers/AccueilController.php
@@ -283,6 +283,11 @@ class Admin_AccueilController extends Zend_Controller_Action {
 		$this->view->catalogues = Class_Catalogue::getCataloguesForCombo();
 		$this->view->paniers = Class_PanierNotice::getPaniersForCombo();
 	}
+	
+	public function premierChapitreAction() {
+		$this->view->paniers = Class_PanierNotice::getPaniersForCombo();
+		$this->_simpleAction('PREMIER-CHAPITRE');
+	}
 
 
 	protected function isAFlashStyleSelected() {
diff --git a/application/modules/admin/views/scripts/accueil/premier-chapitre.phtml b/application/modules/admin/views/scripts/accueil/premier-chapitre.phtml
new file mode 100644
index 00000000000..a0164cae423
--- /dev/null
+++ b/application/modules/admin/views/scripts/accueil/premier-chapitre.phtml
@@ -0,0 +1,74 @@
+<center>
+	<h1>Propriétés du module Premier-Chapitre</h1><br>
+	<div class="formTable">
+		<form class="news" method="post" action="<?php echo $this->url ?>">
+
+			<fieldset>
+				<legend>Affichage</legend>
+				<table cellspacing="2">
+
+					<tr>
+						<td class="droite">Style de boite&nbsp;</td>
+						<td class="gauche"><?php echo $this->combo_templates ?></td>
+					</tr>
+
+				</table>
+			</fieldset>
+			<br />
+
+			<fieldset>
+				<legend>Généralités</legend>
+				<table cellspacing="2">
+					<tr>
+						<td class="droite">Titre&nbsp;</td>
+						<td class="gauche">
+							<input type="text" name="titre" size="55" value='<?php print htmlspecialchars($this->preferences["titre"], ENT_QUOTES) ?>' >
+						</td>
+					</tr>
+					<tr>
+						<td class="droite">Texte d'introduction&nbsp;</td>
+						<td class="gauche">
+							<input type="text" name="intro" size="55" value='<?php print htmlspecialchars($this->preferences["intro"], ENT_QUOTES) ?>' >
+						</td>
+					</tr>
+				</table>
+			</fieldset>
+
+			<fieldset>
+				<legend>Mode d'affichage</legend>
+			<table cellspacing="2">
+    		<tr>
+    			<td class="droite">Type de selection&nbsp;</td>
+    			<td class="gauche">
+    				<select name="type" id="type">
+    					<option value="0" <?php if($this->preferences["type"]==0) print(" selected"); ?>>Aléatoire</option>
+    					<option value="1" <?php if($this->preferences["type"]==1) print(" selected"); ?>>Panier</option>
+    					<option value="2" <?php if($this->preferences["type"]==2) print(" selected"); ?>>Toutes les notice</option>
+    				</select>
+    			</td>
+    		</tr>
+			<tr>
+    			<td class="droite">Nombre à afficher<br/>(en mode aléatoire)&nbsp;</td>
+    			<td class="gauche"><input type="text" name="nb_aff" size="4" value="<?php print($this->preferences["nb_aff"]); ?>"></td>
+    		</tr>
+    		<tr>
+    			<td class="droite" valign="top">Format d'affichage</td>
+    			<td class="gauche">
+    				<select name="format" id="format">
+    					<option value="0" <?php if($this->preferences["format"]==0) print(" selected"); ?>>Vignettes seules</option>
+    					<option value="1" <?php if($this->preferences["format"]==1) print(" selected"); ?>>Vignettes + Frame</option>
+    					<option value="2" <?php if($this->preferences["format"]==2) print(" selected"); ?>>Vignettes + Frame + lien Notice</option>
+    				</select>
+    			</td>
+  			</tr>
+			<tr>
+				<td class="droite">Panier&nbsp;</td>
+				<td class="gauche"><?php echo $this->formSelect("id_panier", $this->preferences["id_panier"],null,$this->paniers) ?></td>
+			</tr>	
+  		</table>
+			</fieldset>
+
+		<?php echo $this->formSubmit("Valider","Valider",array("class" => "bouton")) ?>
+ 	</form>
+ </div>
+
diff --git a/library/Class/Systeme/ModulesAccueil.php b/library/Class/Systeme/ModulesAccueil.php
index 7d7a5ad8ad7..80bee972494 100644
--- a/library/Class/Systeme/ModulesAccueil.php
+++ b/library/Class/Systeme/ModulesAccueil.php
@@ -127,6 +127,7 @@ class Class_Systeme_ModulesAccueil extends Class_Systeme_ModulesAbstract {
 												 'HISTORIQUE_RECHERCHES' => new Class_Systeme_ModulesAccueil_HistoriqueRecherches,
 												 'PANIER' => new Class_Systeme_ModulesAccueil_Panier,
 												 'DOMAIN_BROWSER' => new Class_Systeme_ModulesAccueil_DomainBrowser,
+												 'PREMIER_CHAPITRE' => new Class_Systeme_ModulesAccueil_PremierChapitre,
 				];
 			}
 
diff --git a/library/Class/Systeme/ModulesAccueil/PremierChapitre.php b/library/Class/Systeme/ModulesAccueil/PremierChapitre.php
new file mode 100644
index 00000000000..ab359fc494c
--- /dev/null
+++ b/library/Class/Systeme/ModulesAccueil/PremierChapitre.php
@@ -0,0 +1,43 @@
+<?php
+/**
+ * Copyright (c) 2015, Gaël VINOT (Ville de Montrouge). 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_Systeme_ModulesAccueil_PremierChapitre extends Class_Systeme_ModulesAccueil_Null{
+
+	protected $_group = Class_Systeme_ModulesAccueil::GROUP_INFO;
+
+	protected $_libelle = 'Premier Chapitre';
+
+	protected $_action = 'premier-chapitre';
+
+	protected $_popupWidth = 600;
+
+
+	protected $_popupHeight = 700;
+
+	protected $_defaultValues = ['titre' => 'Premier Chapitre',
+												'intro' => '',
+												'type' => 0,
+												'nb_aff' => 8,
+												'id_panier' => 0,
+												'format' => 0];
+}
+?>
\ No newline at end of file
diff --git a/library/ZendAfi/View/Helper/Accueil/PremierChapitre.php b/library/ZendAfi/View/Helper/Accueil/PremierChapitre.php
new file mode 100644
index 00000000000..7f187ef1c0f
--- /dev/null
+++ b/library/ZendAfi/View/Helper/Accueil/PremierChapitre.php
@@ -0,0 +1,33 @@
+<?php
+/**
+ * Copyright (c) 2015, Gaël VINOT (Ville de Montrouge). 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_Accueil_PremierChapitre extends ZendAfi_View_Helper_Accueil_Base {
+	/** @return array */
+	public function getHTML() {
+		$this->titre = $this->preferences['titre'];
+		$this->contenu = '';
+		if (!empty($this->preferences['intro']))
+			$this->contenu = '<p>'.$this->preferences['intro'].'</p>';
+		$this->contenu .= $this->view->renderPremierChapitre($this->id_module, $this->preferences);
+
+		return $this->getHtmlArray();
+	}
+}
+?>
\ No newline at end of file
diff --git a/library/ZendAfi/View/Helper/PremierChapitre/Abstract.php b/library/ZendAfi/View/Helper/PremierChapitre/Abstract.php
index cf264031769..037708ab64d 100644
--- a/library/ZendAfi/View/Helper/PremierChapitre/Abstract.php
+++ b/library/ZendAfi/View/Helper/PremierChapitre/Abstract.php
@@ -1,6 +1,6 @@
 <?php
 /**
- * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
+ * Copyright (c) 2015, Gaël VINOT (Ville de Montrouge). 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
diff --git a/library/ZendAfi/View/Helper/RenderPremierChapitre.php b/library/ZendAfi/View/Helper/RenderPremierChapitre.php
new file mode 100644
index 00000000000..c49bf4b185c
--- /dev/null
+++ b/library/ZendAfi/View/Helper/RenderPremierChapitre.php
@@ -0,0 +1,72 @@
+<?php 
+/**
+ * Copyright (c) 2015, Gaël VINOT (Ville de Montrouge). 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_RenderPremierChapitre extends ZendAfi_View_Helper_BaseHelper {
+	
+	protected $_pref, $_id_module,$renderer;
+
+	public function renderPremierChapitre($id_module, $preferences) {
+		$this->_id_module=$id_module;
+		$this->_pref = $preferences;
+
+		$type = $this->_pref["type"];
+		$format = $this->_pref["format"];
+		
+		if ($type == 1)
+			$data = $this->_selection();
+		else if ($type == 2) {
+			$data = $this->_complete();
+			$format = 0;
+		}
+		else
+			$data = $this->_aleatoire();
+		
+		if ($format == 1 || $format == 2) $preferences['target'] = 'frame';
+		if ($format == 2) $preferences['linkNotice'] = true;
+		return $this->view->premierChapitre_Vignettes($data,$preferences);
+	}
+	protected function _aleatoire() {
+		$nb_aff = $this->_pref["nb_aff"];
+		if (!preg_match('@^\d+$@',$nb_aff))
+			$pcs =  Class_PremierChapitre::getAleatoire();
+		else 
+			$pcs =  Class_PremierChapitre::getAleatoire($nb_aff);
+		return $pcs;
+	}
+	
+	protected function _complete() {
+		return Class_PremierChapitre::getAll();;
+	}
+	
+	protected function _selection() {
+		$id_panier = $this->_pref['id_panier'];
+		$pan = Class_PanierNotice::find($id_panier);
+		$pcs = [];
+		if ($pan) {
+			foreach ($pan->getNoticesAsArray() as $notice)
+				if ($pc = Class_PremierChapitre::getByNotice($notice))
+					$pcs[] = $pc;
+		}
+		return $pcs;
+	}
+
+}
+?>
\ No newline at end of file
-- 
GitLab