Subversion Repositories eFlore/Applications.coel

Rev

Rev 1856 | Rev 1862 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1856 Rev 1857
Line 7... Line 7...
7
	private $bdd = null;
7
	private $bdd = null;
8
	private $auteurs = array();
8
	private $auteurs = array();
9
	protected $parametres_autorises = array(
9
	protected $parametres_autorises = array(
10
			'-n' => array(true, false, 'Nom du fichier à importer.'));
10
			'-n' => array(true, false, 'Nom du fichier à importer.'));
Line -... Line 11...
-
 
11
	
-
 
12
	protected $table_publication = null;
-
 
13
	protected $table_auteur = null;
11
	
14
	
12
	protected $colonnes_obligatoires = array();
15
	protected $colonnes_obligatoires = array();
Line 13... Line 16...
13
	protected $colonnes_acceptees = array();
16
	protected $colonnes_acceptees = array();
Line 24... Line 27...
24
			$this->initialiserScript();
27
			$this->initialiserScript();
25
			$cmd = $this->getParametre('a');
28
			$cmd = $this->getParametre('a');
26
			$fichier = $this->getParametre('n');
29
			$fichier = $this->getParametre('n');
27
			switch ($cmd) {
30
			switch ($cmd) {
28
				case "import" :
31
				case "import" :
29
					//testerauteur
-
 
30
					$this->charger($fichier); break;
32
					$resultat = $this->charger($fichier); break;
31
				default :
33
				default :
32
					$this->traiterErreur('Erreur : la commande "%s" n\'existe pas!', array($cmd));
34
					$this->traiterErreur('Erreur : la commande "%s" n\'existe pas!', array($cmd));
33
			}
35
			}
34
		} catch (Exception $erreur) {
36
		} catch (Exception $erreur) {
35
			$this->traiterErreur($erreur->getMessage());
37
			$this->traiterErreur($erreur->getMessage());
36
		}
38
		}
-
 
39
		
-
 
40
		// renvoi du résultat vers la sortie php
-
 
41
		echo $resultat;
37
	}
42
	}
Line 38... Line 43...
38
	
43
	
39
	private function initialiserScript() {
44
	private function initialiserScript() {
40
		$fichierIni = $this->getScriptChemin().'import.ini';
45
		$fichierIni = $this->getScriptChemin().'import.ini';
Line 46... Line 51...
46
			throw new Exception($erreur);
51
			throw new Exception($erreur);
47
		}
52
		}
Line 48... Line 53...
48
		
53
		
49
		$this->colonnes_obligatoires= Config::get('champs_obligatoires');
54
		$this->colonnes_obligatoires= Config::get('champs_obligatoires');
-
 
55
		$this->colonnes_acceptees = Config::get('champs');
-
 
56
		
-
 
57
		$tables = Config::get('tables');
-
 
58
		$this->table_publication = $tables['publication'];
50
		$this->colonnes_acceptees = Config::get('champs');
59
		$this->table_auteur = $tables['auteur'];
Line 51... Line 60...
51
	}
60
	}
Line 52... Line 61...
52
 
61
 
Line 90... Line 99...
90
				if(!in_array($index, $index_colonnes_refusees)) {
99
				if(!in_array($index, $index_colonnes_refusees)) {
91
					$ligne_inseree[] = $this->traiterChamp($valeur, $index_colonnes_importees[$index]);
100
					$ligne_inseree[] = $this->traiterChamp($valeur, $index_colonnes_importees[$index]);
92
				}
101
				}
93
			}
102
			}
94
			// Ajout du nom complet formaté de la publication
103
			// Ajout du nom complet formaté de la publication
95
			$ligne_inseree[] = $this->formaterNomComplet($ligne, $index_colonnes_importees);
104
			$ligne_inseree[] = $this->bdd->proteger($this->formaterNomComplet($ligne, $index_colonnes_importees));
96
			$lignes[] = "(".implode(",", $ligne_inseree).")";
105
			$lignes[] = "(".implode(",", $ligne_inseree).")";
97
		}
106
		}
Line 98... Line 107...
98
		
107
		
99
		// Ajout de la colonne nom complet aux champs de la requête
108
		// Ajout de la colonne nom complet aux champs de la requête
-
 
109
		$colonnes_importees[] = 'cpu_fmt_nom_complet';
-
 
110
		
100
		$colonnes_importees[] = 'cpu_fmt_nom_complet';
111
		// le script renvoie le nombre de publications importées
101
		$this->insererPublications($colonnes_importees, $lignes);
112
		return $this->insererPublications($colonnes_importees, $lignes);
Line 102... Line 113...
102
	}
113
	}
-
 
114
	
-
 
115
	protected function formaterNomComplet($ligne, $roles) {
-
 
116
		
-
 
117
		$roles = array_flip($roles);
103
	
118
		
-
 
119
		// Intitulé de la publication complet : fmt_auteur, date_parution(année). titre. Editeur (nom), collection, fascicule, indication_nvt. pages.
-
 
120
		// indication_nvt = serie_tome 
-
 
121
		$champs_nom_complet = array('auteur', 'annee', 'titre', 'editeur', 'intitule_revue', 'fascicule', 'serie_tome', 'pages');
-
 
122
		$champs_fmt = array();
-
 
123
		
-
 
124
		$fmt_nom_complet = "";
-
 
125
		
-
 
126
		foreach($champs_nom_complet as $champ) {
-
 
127
			$index = $roles[$champ];
-
 
128
			if(!isset($ligne[$index])) {				
-
 
129
				$champs_fmt[$champ] = "";
-
 
130
			} else {
-
 
131
				$champs_fmt[$champ] = $ligne[$index];
-
 
132
			}
-
 
133
		}
-
 
134
		
-
 
135
		$indication_nvt_pages = array($champs_fmt['serie_tome'], $champs_fmt['pages']);
-
 
136
		$indication_nvt_pages = array_filter($indication_nvt_pages, 'strlen');
-
 
137
		$indication_nvt_pages = trim(implode(". ", $indication_nvt_pages));
-
 
138
		$indication_nvt_pages .= !empty($indication_nvt_pages) ? "." : "";
-
 
139
		
-
 
140
		$annee_titre_editeur = array($champs_fmt['annee'], $champs_fmt['titre'], $champs_fmt['editeur']);
-
 
141
		$annee_titre_editeur = array_filter($annee_titre_editeur, 'strlen');
-
 
142
		$annee_titre_editeur = trim(implode(". ", $annee_titre_editeur));
-
 
143
		
-
 
144
		$fmt_nom_complet =  array($champs_fmt['auteur'], 
-
 
145
							$annee_titre_editeur, 
-
 
146
							$champs_fmt['intitule_revue'],
-
 
147
							$champs_fmt['fascicule'],
-
 
148
							$indication_nvt_pages);
-
 
149
		
-
 
150
		$fmt_nom_complet = array_filter($fmt_nom_complet, 'strlen');
104
	protected function formaterNomComplet($ligne, $roles) {
151
		$fmt_nom_complet = implode(", ", $fmt_nom_complet);
105
		// TODO: écrire la fonction
152
		
Line 106... Line 153...
106
		return 'aaaaa';
153
		return $fmt_nom_complet;
107
	}
154
	}
108
	
155
	
109
	private function insererPublications(&$colonnes, &$publications) {
156
	private function insererPublications(&$colonnes, &$publications) {
Line 110... Line 157...
110
		$requete = "INSERT INTO $table ".
157
		$requete = "INSERT INTO ".$this->table_publication." ".
111
				   	"(".implode(',', $colonnes).") ".
158
				   	"(".implode(',', $colonnes).") ".
Line 112... Line 159...
112
				   "VALUES ".implode(","."\n", $publications)."\n";
159
				   "VALUES ".implode(","."\n", $publications)."\n";
113
		
160
		
114
		echo $requete;exit;
161
		return $this->bdd->executer($requete);
Line 125... Line 172...
125
		}
172
		}
Line 126... Line 173...
126
		
173
		
127
		return $this->bdd->proteger($valeur);
174
		return $this->bdd->proteger($valeur);
Line 128... Line 175...
128
	}
175
	}
129
	
176
	
130
	private function obtenirInfosAuteur($auteur) {
177
	private function obtenirInfosAuteur($auteur_intitule) {
-
 
178
		$retour = $auteur_intitule;
-
 
179
		if(isset($this->cache_auteur[$auteur_intitule])) {
131
		$retour = $auteur;
180
			$retour = !empty($this->cache_auteur[$auteur_intitule]['cp_id_personne']) ?
132
		if(isset($cache_auteur[$auteur])) {
181
				$this->cache_auteur[$auteur_intitule]['cp_id_personne'] :
133
			$retour = $cache_auteur[$auteur];
182
				$this->cache_auteur[$auteur_intitule];
134
		} else {
183
		} else {
Line 135... Line 184...
135
			$auteur = $this->fabriquerCombinaisonsAuteur($auteur);
184
			$auteur = $this->fabriquerCombinaisonsAuteur($auteur_intitule);
136
			$auteur_req = "(".implode(', ', $auteur).")";
185
			$auteur_req = "(".implode(', ', $auteur).")";
Line 137... Line 186...
137
			
186
			
138
			$requete = "SELECT cp_id_personne FROM coel_personne WHERE cp_fmt_nom_complet IN ".$auteur_req;
187
			$requete = "SELECT cp_id_personne, cp_fmt_nom_complet FROM ".$this->table_auteur." WHERE cp_fmt_nom_complet IN ".$auteur_req;
139
			$infos_auteur = $this->bdd->recupererTous($requete);
188
			$infos_auteur = $this->bdd->recupererTous($requete);
140
			
189
			
-
 
190
			if(!empty($infos_auteur)) {
141
			if(!empty($infos_auteur)) {
191
				$retour = $infos_auteur[0]['cp_id_personne'];
142
				$retour = $infos_auteur[0]['cp_id_personne'];
192
				$this->cache_auteur[$auteur_intitule] = $infos_auteur[0];
143
				$cache_auteur[$auteur] = $infos_auteur[0]['cp_id_personne'];
193
			} else {
Line 144... Line 194...
144
			} else {
194
				$retour = $auteur_intitule;
145
				$cache_auteur[$auteur] = $auteur;
195
				$this->cache_auteur[$auteur_intitule] = $auteur_intitule;
Line 190... Line 240...
190
		} else {
240
		} else {
191
			// Cas du nom à trois parties (genre "Carl Linné")
241
			// Cas du nom à trois parties (genre "Carl Linné")
192
			$possibilites_auteurs = $this->cartesian(array($combinaisons[0], $combinaisons[1]));
242
			$possibilites_auteurs = $this->cartesian(array($combinaisons[0], $combinaisons[1]));
193
			$possibilites_auteurs = array_merge($possibilites_auteurs, $this->cartesian(array($combinaisons[1], $combinaisons[0])));
243
			$possibilites_auteurs = array_merge($possibilites_auteurs, $this->cartesian(array($combinaisons[1], $combinaisons[0])));
194
		}
244
		}
195
		// Elimination d'éventuels doublons	
-
 
196
		array_unique($possibilites_auteurs);	
-
 
Line 197... Line 245...
197
		
245
		
198
		$auteurs_formates = array();
246
		$auteurs_formates = array();
199
		foreach($possibilites_auteurs as &$possibilite) {
247
		foreach($possibilites_auteurs as &$possibilite) {
200
			$initiales = true;
248
			$initiales = true;