From 23f5aa55ec8d48424a0195be3688bbe2f2a8cbdd Mon Sep 17 00:00:00 2001
From: llaffont <laurent.laffont@gmail.com>
Date: Fri, 21 Mar 2014 10:42:57 +0100
Subject: [PATCH] Cosmogramme: new sites => change from low level sql to storm

---
 .../php/integre_generation_pergame.php        | 20 +++++++-------
 library/Class/IntMajAuto.php                  | 27 +++++++++++++++++++
 2 files changed, 38 insertions(+), 9 deletions(-)
 create mode 100644 library/Class/IntMajAuto.php

diff --git a/cosmogramme/php/integre_generation_pergame.php b/cosmogramme/php/integre_generation_pergame.php
index ac873ca2cf5..003328ee020 100644
--- a/cosmogramme/php/integre_generation_pergame.php
+++ b/cosmogramme/php/integre_generation_pergame.php
@@ -143,8 +143,8 @@ if($_REQUEST["action"]=="CONTROLE")
 
 		sqlExecute("delete from int_bib where id_bib=".$enreg["ID_SITE"]);
 		$enreg1["id_bib"]=$enreg["ID_SITE"];
-		$enreg1["nom"]=$enreg["LIBELLE"];
-		$enreg1["nom_court"]=$enreg["LIBELLE"];
+		$enreg1["nom"]=trim($enreg["LIBELLE"]);
+		$enreg1["nom_court"]=trim($enreg["LIBELLE"]);
 		$enreg1["qualite"]=5;
 		$enreg1["sigb"]=$type_sigb;
 		$enreg1["planif_mode"]="r";
@@ -160,7 +160,8 @@ if($_REQUEST["action"]=="CONTROLE")
 			$enreg1["comm_sigb"]=1;
 			$enreg1["comm_params"]=serialize(array("Autoriser_docs_disponibles"=>"0","Max_par_carte"=>"3","Max_par_document"=>"3"));
 		}
-		sqlInsert("int_bib", $enreg1);
+
+		(new Class_IntBib)->updateAttributes($enreg1)->save();
 		$nb_bibs++;
 	}
 	print('</table></div>');
@@ -216,7 +217,7 @@ if($_REQUEST["action"]=="CONTROLE")
 			$enreg["type_operation"]=1;
 			$enreg["nom_fichier"]=$path_fichier."site".$id_bib."/suppressions.txt";
 			$enreg["rang"]=$id_prog;
-			sqlInsert("int_maj_auto", $enreg);
+			(new Class_IntMajAuto)->updateAttributes($enreg)->save();
 		}
 
 		// notices total
@@ -229,7 +230,8 @@ if($_REQUEST["action"]=="CONTROLE")
 		$enreg["type_operation"]=2;
 		$enreg["nom_fichier"]=$path_fichier."site".$id_bib."/notices_total.txt";
 		$enreg["rang"]=$id_prog;
-		sqlInsert("int_maj_auto", $enreg);
+		(new Class_IntMajAuto)->updateAttributes($enreg)->save();
+
 
 		// notices incrémentiel
 		echo '<tr><td class="blank">&nbsp;</td><td class="blank">Import incrémentiel des notices</td></tr>';
@@ -241,7 +243,7 @@ if($_REQUEST["action"]=="CONTROLE")
 		$enreg["type_operation"]=0;
 		$enreg["nom_fichier"]=$path_fichier."site".$id_bib."/notices.txt";
 		$enreg["rang"]=$id_prog;
-		sqlInsert("int_maj_auto", $enreg);
+		(new Class_IntMajAuto)->updateAttributes($enreg)->save();
 
 		// abonnés
 		echo '<tr><td class="blank">&nbsp;</td><td class="blank">Import des abonnés</td></tr>';
@@ -253,7 +255,7 @@ if($_REQUEST["action"]=="CONTROLE")
 		$enreg["type_operation"]=2;
 		$enreg["nom_fichier"]=$path_fichier."site".$id_bib."/abonnes.txt";
 		$enreg["rang"]=$id_prog;
-		sqlInsert("int_maj_auto", $enreg);
+		(new Class_IntMajAuto)->updateAttributes($enreg)->save();
 
 		// prêts
 		echo '<tr><td class="blank">&nbsp;</td><td class="blank">Import des prêts</td></tr>';
@@ -264,7 +266,7 @@ if($_REQUEST["action"]=="CONTROLE")
 		$enreg["type_operation"]=2;
 		$enreg["nom_fichier"]=$path_fichier."site".$id_bib."/prets.txt";
 		$enreg["rang"]=$id_prog;
-		sqlInsert("int_maj_auto", $enreg);
+		(new Class_IntMajAuto)->updateAttributes($enreg)->save();
 
 		// réservations (pergame uniquement)
 		if($type_sigb==1)
@@ -277,7 +279,7 @@ if($_REQUEST["action"]=="CONTROLE")
 			$enreg["type_operation"]=2;
 			$enreg["nom_fichier"]=$path_fichier."site".$id_bib."/reservations.txt";
 			$enreg["rang"]=$id_prog;
-			sqlInsert("int_maj_auto", $enreg);
+			(new Class_IntMajAuto)->updateAttributes($enreg)->save();
 		}
 	}
 	print('</table></div>');
diff --git a/library/Class/IntMajAuto.php b/library/Class/IntMajAuto.php
new file mode 100644
index 00000000000..2b6da0f462e
--- /dev/null
+++ b/library/Class/IntMajAuto.php
@@ -0,0 +1,27 @@
+<?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 Class_IntMajAuto extends Storm_Model_Abstract {
+  protected $_table_name = 'int_maj_auto';
+  protected $_table_primary = 'id_prog';
+}
+
+?>
\ No newline at end of file
-- 
GitLab