Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 1689 Rev 1694
Line 79... Line 79...
79
			   'images'				=> self::GenColInfo('images', 'Image(s)', 1, NULL, NULL /* cas particulier 'getImages' */, TRUE),
79
			   'images'				=> self::GenColInfo('images', 'Image(s)', 1, NULL, NULL /* cas particulier 'getImages' */, TRUE),
Line 80... Line 80...
80
 
80
 
81
			   /* 'nom_commun'			=> self::GenColInfo('nom_commun', 'Nom Commun', 1, NULL, 'getNomCommun', FALSE),
81
			   /* 'nom_commun'			=> self::GenColInfo('nom_commun', 'Nom Commun', 1, NULL, 'getNomCommun', FALSE),
82
				  'nom-commun'			=> self::GenColInfo('nom-commun', 'Nom Commun', 1, NULL, 'getNomCommun_v2'),
82
				  'nom-commun'			=> self::GenColInfo('nom-commun', 'Nom Commun', 1, NULL, 'getNomCommun_v2'),
83
				  'nom-commun'			=> self::GenColInfo('nom-commun', 'Nom Commun', 1, NULL, 'getNomCommun_v3'), */
83
				  'nom-commun'			=> self::GenColInfo('nom-commun', 'Nom Commun', 1, NULL, 'getNomCommun_v3'), */
Line 84... Line 84...
84
			   'nom-commun'			=> self::GenColInfo('nom-commun', 'Nom Commun', 1, NULL, NULL /* cas particu 'getNomCommun_v4' */),
84
			   'nom-commun'			=> self::GenColInfo('nom-commun', 'Nom Commun', 1, NULL, NULL /* cas particu 'getNomCommun_v4' */, TRUE, 'getNomCommun_preload'),
85
 
85
 
Line 86... Line 86...
86
			);
86
			);
87
		}	
87
		}	
-
 
88
 
-
 
89
		return $colonnes;
-
 
90
	}
-
 
91
 
-
 
92
	static function preload($colonnes, $cel, $ids) {
-
 
93
		$result = array();
-
 
94
		foreach($colonnes as $abbrev => $colonne) {
-
 
95
			if(!$colonne['preload']) continue;
-
 
96
			$result[$abbrev] = call_user_func(array(__CLASS__, $colonne['preload']), $cel, $ids);
Line 88... Line 97...
88
 
97
		}
89
		return $colonnes;
98
		return $result;
90
	}
99
	}
Line 91... Line 100...
91
	
100
	
92
	public static function getIntitulesColonnes($colonnes) {
101
	public static function getIntitulesColonnes($colonnes) {
93
		return array_map(array('FormateurGroupeColonne', 'retournerNomItem'), $colonnes);
102
		return array_map(array('FormateurGroupeColonne', 'retournerNomItem'), $colonnes);
94
	}
103
	}
95
	
104
	
Line 96... Line 105...
96
	public static function retournerNomItem(&$item) {
105
	public static function retournerNomItem(&$item) {
97
		return $item['nom'];
106
		return $item['nom'];
98
	}
107
	}
Line 141... Line 150...
141
			}
150
			}
Line 142... Line 151...
142
				
151
				
143
			// // fin de section "cas particuliers"
152
			// // fin de section "cas particuliers"
144
			$ligne_formatee[] = $valeur;
153
			$ligne_formatee[] = $valeur;
-
 
154
		}
-
 
155
 
-
 
156
		// TODO:
-
 
157
		// taxon => (code_catminat) => syntaxon => données baseveg
145
		}
158
 
146
		return $ligne_formatee;
159
		return $ligne_formatee;
Line 147... Line 160...
147
	}
160
	}
148
	
161
	
-
 
162
	/*
Line 149... Line 163...
149
	/*
163
	* Wrapper générant un tableau associatif:
150
	* Wrapper générant un tableau associatif:
164
	* Ne pas changer les valeurs par défaut du prototype sans réflexion sur l'implication pour nomEnsembleVersListeColonnes()
151
	
165
	
152
	* @param $abbrev (obligatoire): nom court de colonne, largement utilisé lors de l'import.
166
	* @param $abbrev (obligatoire): nom court de colonne, largement utilisé lors de l'import.
Line 170... Line 184...
170
	* 		  $fonction_data doit prendre comme premier argument le tableau des champs de l'enregistrement existant
184
	* 		  $fonction_data doit prendre comme premier argument le tableau des champs de l'enregistrement existant
171
	*		  $fonction_data doit retourner une valeur
185
	*		  $fonction_data doit retourner une valeur
Line 172... Line 186...
172
	
186
	
173
	* @param $importable (optionnel): défini si la colonne est traitée (ou absolument ignorée par PHPExcel) lors de
187
	* @param $importable (optionnel): défini si la colonne est traitée (ou absolument ignorée par PHPExcel) lors de
-
 
188
	*		  l'import.
-
 
189
 
-
 
190
	* @param $preload (optionnel): défini une fonction de préchargement massif de donnée potentiellement utilisable par $fonction_data.
Line 174... Line 191...
174
	*		  l'import.
191
	*		  Utile, notamment, dans le cadre de l'export
175
	
192
	
176
	*/
193
	*/
177
	static function GenColInfo($abbrev, $nom, $is_extra = 0, $fonction = NULL, $fonction_data = NULL, $importable = TRUE) {
194
	static function GenColInfo($abbrev, $nom, $is_extra = 0, $fonction = NULL, $fonction_data = NULL, $importable = TRUE, $preload = NULL) {
178
		return Array('abbrev' => $abbrev,
195
		return Array('abbrev' => $abbrev,
179
					 'nom' => $nom,
196
					 'nom' => $nom,
180
					 'extra' => $is_extra ? 1 : 0,
197
					 'extra' => $is_extra ? 1 : 0,
181
					 'fonction' => $fonction,
198
					 'fonction' => $fonction,
-
 
199
					 'fonction_data' => $fonction_data,
182
					 'fonction_data' => $fonction_data,
200
					 'importable' => $importable,
183
					 'importable' => $importable
201
					 'preload' => $preload,
Line 184... Line 202...
184
		);
202
		);
185
	}
203
	}
Line 346... Line 364...
346
		// cache
364
		// cache
347
		self::$cache['getNomCommun'][$cache_id] = $nom;
365
		self::$cache['getNomCommun'][$cache_id] = $nom;
348
		return $nom;
366
		return $nom;
349
	}
367
	}
Line -... Line 368...
-
 
368
 
-
 
369
	/* Cette fonction initialise le cache des noms communs en 1 fois, sur la liste des observations à exporter.
-
 
370
	   Ainsi, les appels successifs à getNomCommun_v4() ne sont pas couteux (pas de requête SQL)
-
 
371
	 */
-
 
372
	static function getNomCommun_preload($cel, $obsids) {
-
 
373
		if(!$obsids) return;
-
 
374
		if(!$cel->executerRequete("SHOW TABLES LIKE 'cel_references'", Cel::SQL_RETOUR_LIGNE)) return NULL;
-
 
375
 
-
 
376
		// CREATE INDEX i_nom_referentiel ON cel_obs (nom_referentiel(5));
-
 
377
		$req = sprintf("SELECT r.referentiel, r.num_taxon, r.nom_commun FROM cel_references r" .
-
 
378
					   " INNER JOIN cel_obs c ON (r.referentiel = substring_index(c.nom_referentiel, ':', 1) and r.num_taxon = c.nt)" .
-
 
379
					   " WHERE c.id_observation IN (%s)",
-
 
380
					   implode(',', $obsids));
-
 
381
		$res = $cel->requeter($req);
-
 
382
		foreach($res as $v) {
-
 
383
			self::$cache['getNomCommun'][$v['referentiel'] . '-' . $v['num_taxon'] . '-' . 'fra'] = $v['nom_commun'];
-
 
384
		}
-
 
385
		return NULL;
-
 
386
	}
350
 
387
					   
351
	static function getNomCommun_v4($obs, $cel) {
388
	static function getNomCommun_v4($obs, $cel) {
352
		static $is_table = false;
389
		static $is_table = false;
Line 353... Line 390...
353
		if(! $obs['nt']) return NULL;
390
		if(! $obs['nt']) return NULL;
Line 362... Line 399...
362
		$cache_id = $referentiel . '-' . $obs['nt'] . '-' . $langue;
399
		$cache_id = $referentiel . '-' . $obs['nt'] . '-' . $langue;
Line 363... Line 400...
363
 
400
 
Line 364... Line 401...
364
		if(isset(self::$cache['getNomCommun'][$cache_id])) return self::$cache['getNomCommun'][$cache_id];
401
		if(isset(self::$cache['getNomCommun'][$cache_id])) return self::$cache['getNomCommun'][$cache_id];
365
 
-
 
366
		// pas de cache:
-
 
367
		$donnees = Array('masque.nt' => $obs['nt'],
-
 
368
						 'masque.lg' => $langue,
-
 
369
						 'retour.champs' => 'conseil_emploi');
402
 
370
 
403
		// pas de cache:
371
		$nom = $cel->executerRequete(sprintf("SELECT nom_commun FROM cel_references " .
404
		$nom = $cel->executerRequete(sprintf("SELECT nom_commun FROM cel_references " .
372
											 "WHERE referentiel = '%s' AND num_taxon = %d LIMIT 1",
405
											 "WHERE referentiel = '%s' AND num_taxon = %d LIMIT 1",
373
											 $referentiel,
406
											 $referentiel,