Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 1632 Rev 1633
Line 30... Line 30...
30
 *
30
 *
31
 * Si <Utilisateur> est fourni, le observations seront le résultat de l'intersection des 2 contraintes
31
 * Si <Utilisateur> est fourni, le observations seront le résultat de l'intersection des 2 contraintes
32
 *
32
 *
33
 */
33
 */
34
set_include_path(get_include_path() . PATH_SEPARATOR . dirname(dirname(realpath(__FILE__))) . '/lib');
34
set_include_path(get_include_path() . PATH_SEPARATOR . dirname(dirname(realpath(__FILE__))) . '/lib');
-
 
35
 
-
 
36
// si getNomCommun_v2 ou getNomCommun_v3 sont utilisés
35
require_once('lib/PHPExcel/Classes/PHPExcel.php');
37
/*require_once('/home/raphael/eflore/framework/framework/Framework.php');
-
 
38
Framework::setCheminAppli("/home/raphael/eflore/projets/services/index.php");
-
 
39
Framework::setInfoAppli(Config::get('info'));
-
 
40
require_once('/home/raphael/eflore/projets/services/modules/0.1/Projets.php');*/
Line 36... Line 41...
36
 
41
 
Line -... Line 42...
-
 
42
class ExportXLS extends Cel  {
-
 
43
 
37
class ExportXLS extends Cel  {
44
	private $cache = Array();
38
 
45
 
39
	function ExportXLS($config) {
46
	function ExportXLS($config) {
Line 40... Line 47...
40
		parent::__construct($config);
47
		parent::__construct($config);
Line 241... Line 248...
241
			   'date_transmission'	=> self::GenColInfo('date_transmission', 'Date Transmission', 1),
248
			   'date_transmission'	=> self::GenColInfo('date_transmission', 'Date Transmission', 1),
242
			   'abondance'			=> self::GenColInfo('abondance', 'Abondance', 1),
249
			   'abondance'			=> self::GenColInfo('abondance', 'Abondance', 1),
243
			   'certitude'			=> self::GenColInfo('certitude', 'Certitude', 1),
250
			   'certitude'			=> self::GenColInfo('certitude', 'Certitude', 1),
244
			   'phenologie'			=> self::GenColInfo('phenologie', 'Phénologie', 1),
251
			   'phenologie'			=> self::GenColInfo('phenologie', 'Phénologie', 1),
Line 245... Line 252...
245
 
252
 
246
			   //'nom-commun'			=> self::GenColInfo('nom-commun', 'Nom Commun', 1, NULL, 'getNomCommun')
253
			   'nom-commun'			=> self::GenColInfo('nom-commun', 'Nom Commun', 1, NULL, 'getNomCommun')
247
			   //'nom-commun'			=> self::GenColInfo('nom-commun', 'Nom Commun', 1, NULL, 'getNomCommun_v2')
254
			   //'nom-commun'			=> self::GenColInfo('nom-commun', 'Nom Commun', 1, NULL, 'getNomCommun_v2')
248
			   //'nom-commun'			=> self::GenColInfo('nom-commun', 'Nom Commun', 1, NULL, 'getNomCommun_v3')
255
			   //'nom-commun'			=> self::GenColInfo('nom-commun', 'Nom Commun', 1, NULL, 'getNomCommun_v3')
249
		   );
256
		   );
Line 278... Line 285...
278
		// TODO: les widget ne font malheureusement pas usage de l'heure dans le CEL
285
		// TODO: les widget ne font malheureusement pas usage de l'heure dans le CEL
279
		$date_formatee = strftime('%A %d %B %Y', $timestamp);
286
		$date_formatee = strftime('%A %d %B %Y', $timestamp);
280
		if(!$date_formatee) return "00/00/0000";
287
		if(!$date_formatee) return "00/00/0000";
281
		return $date_formatee;
288
		return $date_formatee;
282
	}
289
	}
283
}
-
 
284
290
 
-
 
291
 
-
 
292
	// TODO: référentiel ne devrait pas être généré au moment d'un Config::get,
-
 
293
	// comme dans Config::get('nomsVernaRechercheLimiteeTpl')
-
 
294
	// Par exemple, la variable pour "nva" ?
-
 
295
	function getNomCommun($obs) {
-
 
296
		$langue = 'fra';
-
 
297
		list($referentiel) = explode(':', strtolower($obs['nom_referentiel']));
-
 
298
		if($referentiel == 'bdtfx') $referentiel = 'nvjfl';
-
 
299
		else return '';
-
 
300
 
-
 
301
		$cache_id = $referentiel . '-' . $obs['nt'] . '-' . $langue;
-
 
302
		if(isset($this->cache['getNomCommun'][$cache_id])) {
-
 
303
			//debug: error_log("require url_service_nom_attribution: OK ! (pour \"{$obs['nom_ret']}\")");
-
 
304
			return $this->cache['getNomCommun'][$cache_id];
-
 
305
		}
-
 
306
		// pas de cache:
-
 
307
		//debug: error_log("require url_service_nom_attribution pour \"{$obs['nom_ret']}\"");
-
 
308
 
-
 
309
		// pour bdtfx:
-
 
310
		// /service:eflore:0.1/nvjfl/noms-vernaculaires/attributions?masque.nt=X&masque.lg=fra&retour.champs=num_statut
-
 
311
		// /projet/services/modules/0.1/nvjfl/NomsVernaculaires.php
-
 
312
		$url = str_replace(Array('{referentiel}', '{valeur}', '{langue}'),
-
 
313
						   Array($referentiel, $obs['nt'], $langue),
-
 
314
						   $this->config['eflore']['url_service_nom_attribution']) .
-
 
315
			"&retour.champs=num_statut";
-
 
316
		$noms = @json_decode(file_get_contents($url));
-
 
317
		if(! $noms) return '';
-
 
318
		$noms = array_filter((array)($noms->resultat), function($item) { return ($item->num_statut == 1); });
-
 
319
		$nom = array_pop($noms)->nom_vernaculaire;
-
 
320
 
-
 
321
		// cache
-
 
322
		$this->cache['getNomCommun'][$cache_id] = $nom;
-
 
323
		return $nom;
-
 
324
	}
-
 
325
 
-
 
326
 
-
 
327
	/* Tente de bootstraper le framework au plus court et d'initialiser une instance de
-
 
328
	   NomsVernaculaires pour obtenir le nom commun */
-
 
329
	function getNomCommun_v2($obs) {
-
 
330
		static $service;
-
 
331
		$service = new Projets();
-
 
332
 
-
 
333
		$langue = 'fra';
-
 
334
		list($referentiel) = explode(':', strtolower($obs['nom_referentiel']));
-
 
335
		if($referentiel == 'bdtfx') $referentiel = 'nvjfl';
-
 
336
		else return '';
-
 
337
 
-
 
338
		$cache_id = $referentiel . '-' . $obs['nt'] . '-' . $langue;
-
 
339
		if(isset($this->cache['getNomCommun'][$cache_id])) {
-
 
340
			error_log("require NomsVernaculaires.php: OK ! (pour \"{$obs['nom_ret']}\")");
-
 
341
			return $this->cache['getNomCommun'][$cache_id];
-
 
342
		}
-
 
343
		// pas de cache:
-
 
344
		error_log("require NomsVernaculaires.php pour \"{$obs['nom_ret']}\"");
-
 
345
 
-
 
346
		$data = Array('masque.nt' => $obs['nt'],
-
 
347
							 'masque.lg' => $langue,
-
 
348
							 'retour.champs' => 'num_statut');
-
 
349
		$noms = $service->consulter(Array('nvjfl', 'noms-vernaculaires'), $data);
-
 
350
 
-
 
351
		if(! $noms) return '';
-
 
352
		$noms = array_filter((array)($noms->resultat), function($item) { return ($item->num_statut == 1); });
-
 
353
		$nom = array_pop($noms)->nom_vernaculaire;
-
 
354
 
-
 
355
		// cache
-
 
356
		$this->cache['getNomCommun'][$cache_id] = $nom;
-
 
357
		return $nom;
-
 
358
	}
-
 
359
 
-
 
360
 
-
 
361
	/* Effectue un bootstraping plus sage que ci-dessus, mais le gain d'efficacité
-
 
362
	   n'est pas aussi retentissant qu'espéré */
-
 
363
	static $service;
-
 
364
	function getNomCommun_v3($obs) {
-
 
365
		if(! $this->service) $this->service = new Projets();
-
 
366
 
-
 
367
		$langue = 'fra';
-
 
368
		list($referentiel) = explode(':', strtolower($obs['nom_referentiel']));
-
 
369
		if($referentiel == 'bdtfx') $referentiel = 'nvjfl';
-
 
370
		else return '';
-
 
371
 
-
 
372
		$cache_id = $referentiel . '-' . $obs['nt'] . '-' . $langue;
-
 
373
		if(isset($this->cache['getNomCommun'][$cache_id])) {
-
 
374
			error_log("require NomsVernaculaires.php: OK ! (pour \"{$obs['nom_ret']}\")");
-
 
375
			return $this->cache['getNomCommun'][$cache_id];
-
 
376
		}
-
 
377
		// pas de cache:
-
 
378
		error_log("require NomsVernaculaires.php pour \"{$obs['nom_ret']}\"");
-
 
379
 
-
 
380
		$data = Array('masque.nt' => $obs['nt'],
-
 
381
					  'masque.lg' => $langue,
-
 
382
					  'retour.champs' => 'conseil_emploi');
-
 
383
		$this->service->initialiserRessourcesEtParametres(Array('nvjfl', 'noms-vernaculaires', 'attributions'), $data);
-
 
384
		try {
-
 
385
			$noms = $this->service->traiterRessources();
-
 
386
		} catch(Exception $e) { return ''; }
-
 
387
		if(! $noms) return '';
-
 
388
		$noms = array_filter($noms['resultat'], function($item) { return ($item['num_statut'] == 1); });
-
 
389
		$nom = array_pop($noms)['nom_vernaculaire'];
-
 
390
 
-
 
391
		// cache
-
 
392
		$this->cache['getNomCommun'][$cache_id] = $nom;
-
 
393
		return $nom;
-
 
394
	}
-
 
395
 
-
 
396
}
-
 
397