Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

Rev 1108 Rev 1109
Line 6... Line 6...
6
 * un identifiant (numérique ou alphanumérique sous forme de ChatMot si possible), un nom, une langue et
6
 * un identifiant (numérique ou alphanumérique sous forme de ChatMot si possible), un nom, une langue et
7
 * une relation avec un taxon de la bdtfx.
7
 * une relation avec un taxon de la bdtfx.
8
 * Si l'url finit par /noms-vernaculaires on retourne une liste de noms (seulement les 100 premières par défaut).
8
 * Si l'url finit par /noms-vernaculaires on retourne une liste de noms (seulement les 100 premières par défaut).
9
 * L'url peut contenir des paramètres optionnels passés après le ? : /observations?param1=val1&param2=val2&...
9
 * L'url peut contenir des paramètres optionnels passés après le ? : /observations?param1=val1&param2=val2&...
10
 *
10
 *
-
 
11
 * ATTENTION : /attributions groupe par taxon, le nombre de résultats est donc
-
 
12
  * inférieur ou égal au nombre demandé par navigation.limite
-
 
13
 * 
11
 * Les paramètres de requête disponibles sont : masque, masque.code, masque.nom, masque.region , recherche,
14
 * Les paramètres de requête disponibles sont : masque, masque.code, masque.nom, masque.region , recherche,
12
 * distinct, retour.format, navigation.depart et navigation.limite.
15
 * distinct, retour.format, navigation.depart et navigation.limite.
13
 *
16
 *
14
 * Encodage en entrée : utf8
17
 * Encodage en entrée : utf8
15
 * Encodage en sortie : utf8
18
 * Encodage en sortie : utf8
Line 49... Line 52...
49
      * Est utilisée principalement pr déterminer le format du tableau à retourner.	 */
52
      * Est utilisée principalement pr déterminer le format du tableau à retourner.	 */
50
     protected $format_reponse = 'noms-vernaculaires';
53
     protected $format_reponse = 'noms-vernaculaires';
Line 51... Line 54...
51
 
54
 
52
     /** Variables constituant les parametres de la requete SQL (champ, condition, limit) remplie
55
     /** Variables constituant les parametres de la requete SQL (champ, condition, limit) remplie
53
      * selon ressources et paramètres */
56
      * selon ressources et paramètres */
54
     protected $requete_champ = array(' * ');
57
     protected $requete_champ = array('*');
55
     protected $requete_condition = '';
58
     protected $requete_condition = '';
56
     protected $limite_requete = array(
59
     protected $limite_requete = array(
57
         'depart' => 0,
60
         'depart' => 0,
58
         'limite' => 100
61
         'limite' => 100
Line 208... Line 211...
208
     public function traiterRessourceChamp() {
211
     public function traiterRessourceChamp() {
209
         $this->format_reponse .= '/champ';
212
         $this->format_reponse .= '/champ';
210
         $this->analyserChamp();
213
         $this->analyserChamp();
211
     }
214
     }
Line 212... Line 215...
212
 
215
 
213
     public function analyserChamp() {
-
 
214
         $this->requete_champ = array();
216
    public function analyserChamp() {
215
         $this->recupererTableConfig('champs_possibles');// s'il y a plusieurs champs correspondant au champ demandé ils sont séparé par des |
217
        $this->recupererTableConfig('champs_possibles');// s'il y a plusieurs champs correspondant au champ demandé ils sont séparé par des |
-
 
218
        $champs = explode(' ', $this->ressources[1]);
216
         $champs = explode(' ', $this->ressources[1]);
219
		//$this->requete_champ = array(); // * car absence de mappings
217
         foreach ($champs as $champ) {
220
        foreach ($champs as $champ) {
218
             preg_match('/^([^.]+)(\.([^.]+))?$/', $champ, $match);
221
            preg_match('/^([^.]+)(\.([^.]+))?$/', $champ, $match);
-
 
222
            if (isset($this->champs_possibles[$match[1]])) {
219
             if (isset($this->champs_possibles[$match[1]])) {
223
				// wtf?
-
 
224
                //$this->requete_champ[] = str_replace('|', ', ', $this->champs_possibles[$match[1]]);
-
 
225
				// marche pas, pour chaque champ il faut en retourner un qui a un
-
 
226
				// autre nom etc. , pas le temps de faire des mappings
220
                 $this->requete_champ[] = str_replace('|', ', ', $this->champs_possibles[$match[1]]);
227
				$this->requete_champ[] = $match[1];
-
 
228
            } elseif (isset($this->champs_possibles[$match[0]])) {
221
             } elseif (isset($this->champs_possibles[$match[0]])) {
229
				// wtf ?
222
                 $this->requete_champ[] = str_replace('|', ', ', $this->champs_possibles[$match[0]]);
230
                $this->requete_champ[] = str_replace('|', ', ', $this->champs_possibles[$match[0]]);
223
             } else {
231
            } else {
224
                 $champs_possibles = implode('</li><li>', array_keys($this->champs_possibles));
232
                $champs_possibles = implode('</li><li>', array_keys($this->champs_possibles));
225
                 $c = 'Erreur dans votre requête : </br> Le champ "'.$champ_possibles.'" n\'existe pas. '.
233
                $c = 'Erreur dans votre requête : </br> Le champ "'.$champ_possibles.'" n\'existe pas. '.
226
                     'Les champs disponibles sont : <li>'.$champs_possibles.'</li> et leurs déclinaisons (ex. ".code").';
234
                     'Les champs disponibles sont : <li>'.$champs_possibles.'</li> et leurs déclinaisons (ex. ".code").';
227
                 $this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $c);
235
                $this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $c);
228
             }
236
            }
229
         }
237
        }
Line 230... Line 238...
230
     }
238
    }
231
 
239
 
232
	 // fait du neuf avec du vieux
240
	 // fait du neuf avec du vieux
233
	public function assemblerLaRequete() {
241
	public function assemblerLaRequete() {
Line 250... Line 258...
250
		$limiteClause = self::formerRequeteLimite( // LIMIT
258
		$limiteClause = self::formerRequeteLimite( // LIMIT
251
			$this->limite_requete['depart'],
259
			$this->limite_requete['depart'],
252
			$count,
260
			$count,
253
			$this->limite_requete['limite']
261
			$this->limite_requete['limite']
254
		);
262
		);
255
 
-
 
256
        $req = sprintf(
263
        $req = sprintf(
257
            'SELECT %s, group_concat(num_taxon) as num_taxon, IF(num_statut="",1,0) AS is_null' .
264
            'SELECT %s, group_concat(num_taxon) as num_taxon, IF(num_statut="",1,0) AS is_null' .
258
            ' FROM %s WHERE %s GROUP BY id ORDER BY %s is_null ASC, num_statut ASC %s -- %s:%d',
265
            ' FROM %s WHERE %s GROUP BY id ORDER BY %s is_null ASC, num_statut ASC %s -- %s:%d',
Line 259... Line 266...
259
 
266
 
260
            in_array('*', $this->requete_champ) ? ' * ' : implode(', ', $this->requete_champ),
267
            in_array('*', $this->requete_champ) ? ' * ' : implode(', ', $this->requete_champ),
261
            $this->table,
268
            $this->table,
262
            $this->requete_condition ? implode(' AND ', $this->requete_condition) : 'TRUE',
269
            $this->requete_condition ? implode(' AND ', $this->requete_condition) : 'TRUE',
263
			$this->tri ? ($this->tri . ' ' . $this->tri_ordre . ', ') : '',
270
			$this->tri ? ($this->tri . ' ' . $this->tri_ordre . ', ') : '',
264
            $limiteClause,
271
            $limiteClause,
265
            __FILE__, __LINE__);
-
 
266
		//echo "REQ: $req\n";
272
            __FILE__, __LINE__);
267
		return $req;
273
		return $req;
Line 268... Line 274...
268
	}
274
	}
269
 
275
 
Line 279... Line 285...
279
            $limiteClause = self::formerRequeteLimite( // LIMIT
285
            $limiteClause = self::formerRequeteLimite( // LIMIT
280
                $this->limite_requete['depart'],
286
                $this->limite_requete['depart'],
281
                $count,
287
                $count,
282
                $this->limite_requete['limite']);
288
                $this->limite_requete['limite']);
283
        }
289
        }
284
 
-
 
285
        $req = sprintf(
290
        $req = sprintf(
286
            'SELECT %s, IF(num_statut="",1,0) AS is_null' .
291
            'SELECT %s, IF(num_statut="",1,0) AS is_null' .
287
            ' FROM %s WHERE %s ORDER BY %s is_null ASC, num_statut ASC %s -- %s:%d',
292
            ' FROM %s WHERE %s ORDER BY %s is_null ASC, num_statut ASC %s -- %s:%d',
Line 288... Line 293...
288
 
293
 
289
            in_array('*', $this->requete_champ) ? ' * ' : implode(', ', $this->requete_champ),
294
            in_array('*', $this->requete_champ) ? ' * ' : implode(', ', $this->requete_champ),
290
            $this->table,
295
            $this->table,
291
            $this->requete_condition ? implode(' AND ', $this->requete_condition) : 'TRUE',
296
            $this->requete_condition ? implode(' AND ', $this->requete_condition) : 'TRUE',
292
			$this->tri ? ($this->tri . ' ' . $this->tri_ordre . ', ') : '',
297
			$this->tri ? ($this->tri . ' ' . $this->tri_ordre . ', ') : '',
293
            $nolimit ? '' : $limiteClause,
298
            $nolimit ? '' : $limiteClause,
294
            __FILE__, __LINE__);
-
 
295
		//echo "REQ 2: $req\n";
299
            __FILE__, __LINE__);
296
		return $req;
300
		return $req;
Line 297... Line 301...
297
	}
301
	}
298
 
302
 
Line 347... Line 351...
347
			case 'noms-vernaculaires/attributions'	: $reponse = $this->formaterNomsVernaculairesAttributions($resultat);	break;
351
			case 'noms-vernaculaires/attributions'	: $reponse = $this->formaterNomsVernaculairesAttributions($resultat);	break;
348
			case 'noms-vernaculaires/id'			: $reponse = $this->formaterNomsVernaculairesId($resultat);			break;
352
			case 'noms-vernaculaires/id'			: $reponse = $this->formaterNomsVernaculairesId($resultat);			break;
349
			case 'noms-vernaculaires/id/champ'		: $reponse = $this->formaterNomsVernaculairesIdChamp($resultat);	break;
353
			case 'noms-vernaculaires/id/champ'		: $reponse = $this->formaterNomsVernaculairesIdChamp($resultat);	break;
350
			default									:																	break;
354
			default									:																	break;
351
		}
355
		}
352
		//echo "\nCOMPTE: " . count($reponse['resultat']) . "\n\n";
-
 
353
		return $reponse;
356
		return $reponse;
354
	}
357
	}
Line 355... Line 358...
355
	
358
	
356
	public function ajouterJsonEnTeteNV() {
359
	public function ajouterJsonEnTeteNV() {
Line 371... Line 374...
371
	/**
374
	/**
372
	 * @TODO Ne devrait pas retourner un oblet mais un Array (conserve l'ordre,
375
	 * @TODO Ne devrait pas retourner un oblet mais un Array (conserve l'ordre,
373
	 * évite d'écraser des clefs etc.)
376
	 * évite d'écraser des clefs etc.)
374
	 */
377
	 */
375
	public function ajouterJsonResultatNV($resultat) {
378
	public function ajouterJsonResultatNV($resultat) {
376
		//echo "CPT RES: " . count($resultat) . "\n\n";
-
 
377
		$resultat_json = array();
379
		$resultat_json = array();
378
		foreach ($resultat as $tab) {
380
		foreach ($resultat as $tab) {
379
			$this->table_retour = array();
381
			$this->table_retour = array();
380
			foreach ($tab as $key => $valeur) {
382
			foreach ($tab as $key => $valeur) {
381
				if ($valeur != '') {
383
				if ($valeur != '') {
Line 452... Line 454...
452
			$table_retour_json['entete']['href.precedent'] = $url['precedent'];
454
			$table_retour_json['entete']['href.precedent'] = $url['precedent'];
453
		}
455
		}
454
		if (!empty($url['suivant'])) {
456
		if (!empty($url['suivant'])) {
455
			$table_retour_json['entete']['href.suivant']   = $url['suivant'];
457
			$table_retour_json['entete']['href.suivant']   = $url['suivant'];
456
		}
458
		}
-
 
459
		$resultat_json = array();
457
		foreach ($resultat as &$tab) {		
460
		foreach ($resultat as &$tab) {		
458
			$nnv = $tab['num_nom_vernaculaire'];
461
			$nnv = $tab['num_nom_vernaculaire'];
459
			$resultat_json[$nnv]['id'] = $tab['id'];
462
			$resultat_json[$nnv]['id'] = $tab['id'];
460
			$resultat_json[$nnv]['nom_vernaculaire'] = $tab['nom_vernaculaire'];
463
			$resultat_json[$nnv]['nom_vernaculaire'] = $tab['nom_vernaculaire'];
461
			$resultat_json[$nnv]['langue.code'] = $resultat_json[$nnv]['code_langue'] = $tab['code_langue'];
464
			$resultat_json[$nnv]['langue.code'] = $resultat_json[$nnv]['code_langue'] = $tab['code_langue'];
Line 464... Line 467...
464
				$this->taxons[] = $tab['num_taxon']; // utilisé pour chercher les noms latins plus bas
467
				$this->taxons[] = $tab['num_taxon']; // utilisé pour chercher les noms latins plus bas
465
				if($this->champs_supp) {
468
				if($this->champs_supp) {
466
					//$resultat_json[$nnv] = $this->ajouterChampsOntologieLigneResultat($tab);
469
					//$resultat_json[$nnv] = $this->ajouterChampsOntologieLigneResultat($tab);
467
					// simple initialisation par copie de la référence de l'original
470
					// simple initialisation par copie de la référence de l'original
468
					$resultat_json[$nnv] = &$tab;
471
					$resultat_json[$nnv] = &$tab;
469
				}
-
 
470
				else {
472
				} else {
471
					$resultat_json[$nnv]['num_taxon'] = $tab['num_taxon'];
473
					$resultat_json[$nnv]['num_taxon'] = $tab['num_taxon'];
472
					$resultat_json[$nnv]['nom_retenu.code'] = $tab['num_taxon'];
474
					$resultat_json[$nnv]['nom_retenu.code'] = $tab['num_taxon'];
473
					$resultat_json[$nnv]['taxon'] = $tab['num_taxon'];
475
					$resultat_json[$nnv]['taxon'] = $tab['num_taxon'];
474
					$resultat_json[$nnv]['href'] = $this->ajouterHref('noms-vernaculaires', $tab['id']);
476
					$resultat_json[$nnv]['href'] = $this->ajouterHref('noms-vernaculaires', $tab['id']);
475
				}
477
				}
Line 482... Line 484...
482
			// récupérons désormais les ontologies
484
			// récupérons désormais les ontologies
483
			$this->ajouterChampsOntologieLigneTousResultats($resultat_json);
485
			$this->ajouterChampsOntologieLigneTousResultats($resultat_json);
484
		}
486
		}
Line 485... Line 487...
485
 
487
 
486
		if ($this->retour_format == 'max') {
488
		if ($this->retour_format == 'max') {
487
			// On est obligé de faire un deuxième boucle pour demander tous les taxons présents en une 
489
			// Deuxième boucle pour demander tous lestaxons présents en une
488
			// fois et les attribuer aux noms car c'est beaucoup plus rapide
490
			// fois et les attribuer aux noms car c'est beaucoup plus rapide
489
			$noms_sci = $this->recupererNomTaxons();
491
			$noms_sci = $this->recupererNomTaxons();
490
			foreach ($resultat_json as $num_nom => &$tab) {
492
			foreach ($resultat_json as $num_nom => &$tab) {
491
				$tab = $this->ajouterTaxonsAttributionsLigneResultat($tab, $noms_sci);
493
				$tab = $this->ajouterTaxonsAttributionsLigneResultat($tab, $noms_sci);
Line 795... Line 797...
795
			$this->signification_code[$url] = $valeur;
797
			$this->signification_code[$url] = $valeur;
796
		}
798
		}
797
		return $valeur;
799
		return $valeur;
798
	}
800
	}
Line -... Line 801...
-
 
801
 
-
 
802
	/**
-
 
803
	 * Apparemment, regroupe les noms vernaculaires par taxons (élimine donc
-
 
804
	 * certains noms) - j'ai bon ?
799
 
805
	 */
800
	public function afficherTaxons() {
806
	public function afficherTaxons() {
801
		$resultat = $this->recupererNomTaxons();
807
		$resultat = $this->recupererNomTaxons();
802
		foreach ($this->table_retour['attributions'] as $code_langue=>$langue) {
808
		foreach ($this->table_retour['attributions'] as $code_langue=>$langue) {
803
			foreach ($langue as $num_nom=>$taxon) {
809
			foreach ($langue as $num_nom=>$taxon) {
Line 810... Line 816...
810
		}
816
		}
811
	}
817
	}
Line 812... Line 818...
812
	
818
	
813
	public function recupererNomTaxons() {
819
	public function recupererNomTaxons() {
-
 
820
		$taxons = array_unique($this->taxons);
814
		$taxons = array_unique($this->taxons);
821
		// @TODO attention à la limite de taille de l'URL - faire un POST plutôt
815
		$url = Config::get('url_service_base').'bdtfx/taxons?navigation.limite=500&ns.structure=au&masque.nt='.implode(',', $taxons);
822
		$url = Config::get('url_service_base').'bdtfx/taxons?navigation.limite=500&ns.structure=au&masque.nt='.implode(',', $taxons);
816
		$res = $this->consulterHref($url);
823
		$res = $this->consulterHref($url);
817
		foreach ($res->resultat as $id=>$taxon) {
824
		foreach ($res->resultat as $id => $taxon) {
818
			$resultat[$taxon->num_taxonomique]['id'] = 'bdtfx.nn:'.$id;
825
			$resultat[$taxon->num_taxonomique]['id'] = 'bdtfx.nn:'.$id;
819
			$resultat[$taxon->num_taxonomique]['nom_sci'] = $taxon->nom_sci_complet;
826
			$resultat[$taxon->num_taxonomique]['nom_sci'] = $taxon->nom_sci_complet;
820
		}
827
		}
821
		return $resultat;
828
		return $resultat;
Line 844... Line 851...
844
			if (in_array('biblio', $champs) != false && array_search('biblio.num_ref', $this->table_retour) != false) $this->table_retour['biblio'] = null;
851
			if (in_array('biblio', $champs) != false && array_search('biblio.num_ref', $this->table_retour) != false) $this->table_retour['biblio'] = null;
845
		}
852
		}
846
		return $this->table_retour;
853
		return $this->table_retour;
847
	}
854
	}
Line -... Line 855...
-
 
855
 
-
 
856
	/**
-
 
857
	 * Quelqu'un sait-il ce que fait cette foutue fonction ? :-/
848
 
858
	 */
849
	public function afficherPoint($champ, $valeur, $langue, $num_nom) {
859
	public function afficherPoint($champ, $valeur, $langue, $num_nom) {
-
 
860
		$aMatche = preg_match('/^(.*)\.code$/', $champ, $match);
850
		preg_match('/^(.*)\.code$/', $champ, $match);
861
		if ($aMatche !== false && $aMatche !== 0) {
851
		$champ = $match[1];
862
			$champ = $match[1];
852
		if (isset(self::$champ_infos[$champ])) {
863
			if (isset(self::$champ_infos[$champ])) {
853
			extract(self::$champ_infos[$champ]);
864
				extract(self::$champ_infos[$champ]);
854
			$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur, $projet);
865
				$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur, $projet);
855
			$projet .= '.';
866
				$projet .= '.';
856
		}
867
			}
857
 
868
 
858
		$champs = explode(' ', $this->ressources[1]);
869
			$champs = explode(' ', $this->ressources[1]);
859
		if (in_array($champ.'.*', $champs) !== false && isset($projet)) {
870
			if (in_array($champ.'.*', $champs) !== false && isset($projet)) {
860
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.code'] = $projet.$ressource.$valeur;
871
				$this->table_retour['attributions'][$langue][$num_nom][$champ.'.code'] = $projet.$ressource.$valeur;
861
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.href'] = $url;
872
				$this->table_retour['attributions'][$langue][$num_nom][$champ.'.href'] = $url;
862
		}
873
			}
863
		if (in_array($champ.'.code', $champs) !== false && isset($projet)) {
874
			if (in_array($champ.'.code', $champs) !== false && isset($projet)) {
864
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.code'] = $projet.$ressource.$valeur;
875
				$this->table_retour['attributions'][$langue][$num_nom][$champ.'.code'] = $projet.$ressource.$valeur;
865
		}
876
			}
866
		if (in_array($champ.'.href', $champs) !== false && isset($projet)) {
877
			if (in_array($champ.'.href', $champs) !== false && isset($projet)) {
867
			$this->table_retour['attributions'][$langue][$num_nom][$champ.'.href'] = $url;
878
				$this->table_retour['attributions'][$langue][$num_nom][$champ.'.href'] = $url;
868
		}
879
			}
869
		if (in_array($champ, $champs) !== false) {
880
			if (in_array($champ, $champs) !== false) {
870
			if (isset($url)) {
881
				if (isset($url)) {
871
				$this->table_retour['attributions'][$langue][$num_nom][$champ] = $this->chercherSignificationCode($url, $nom);
882
					$this->table_retour['attributions'][$langue][$num_nom][$champ] = $this->chercherSignificationCode($url, $nom);
872
			} else {
883
				} else {
-
 
884
					$this->table_retour['attributions'][$langue][$champ] = $valeur;
873
				$this->table_retour['attributions'][$langue][$champ] = $valeur;
885
				}
874
			}
886
			}
875
		}
887
		}
Line 876... Line 888...
876
	}
888
	}