Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 1107 | Rev 1109 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1107 Rev 1108
Line 227... Line 227...
227
                 $this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $c);
227
                 $this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $c);
228
             }
228
             }
229
         }
229
         }
230
     }
230
     }
Line 231... Line 231...
231
 
231
 
232
     //+------------------------------------------------------------------------------------------------------+
232
	 // fait du neuf avec du vieux
-
 
233
	public function assemblerLaRequete() {
-
 
234
		$requete = false;
-
 
235
		if ($this->format_reponse == 'noms-vernaculaires') {
-
 
236
			// mode liste
-
 
237
			$requete = $this->assemblerRequeteListe();
-
 
238
		} else {
-
 
239
			$requete = $this->assemblerRequeteAutre();
-
 
240
		}
-
 
241
		return $requete;
-
 
242
	}
-
 
243
 
-
 
244
	/**
-
 
245
	 * Exécute un astucieux GROUP BY afin que le service retourne ce qu'il
-
 
246
	 * annonce qu'il retourne (truc de ouf!) - pour le mode "liste"
-
 
247
	 */
-
 
248
	protected function assemblerRequeteListe() {
-
 
249
		$count = $this->recupererTotalResultat();
-
 
250
		$limiteClause = self::formerRequeteLimite( // LIMIT
-
 
251
			$this->limite_requete['depart'],
-
 
252
			$count,
-
 
253
			$this->limite_requete['limite']
-
 
254
		);
-
 
255
 
-
 
256
        $req = sprintf(
-
 
257
            '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',
-
 
259
 
-
 
260
            in_array('*', $this->requete_champ) ? ' * ' : implode(', ', $this->requete_champ),
-
 
261
            $this->table,
-
 
262
            $this->requete_condition ? implode(' AND ', $this->requete_condition) : 'TRUE',
-
 
263
			$this->tri ? ($this->tri . ' ' . $this->tri_ordre . ', ') : '',
-
 
264
            $limiteClause,
-
 
265
            __FILE__, __LINE__);
-
 
266
		//echo "REQ: $req\n";
-
 
267
		return $req;
-
 
268
	}
-
 
269
 
-
 
270
	 /**
-
 
271
	  * Ancien système d'assemblage de requête
-
 
272
	  */
233
     public function assemblerLaRequete() {
273
	protected function assemblerRequeteAutre() {
234
         $nolimit = in_array(
274
        $nolimit = in_array(
235
             $this->format_reponse,
275
            $this->format_reponse,
236
             array($this->service.'/id', $this->service.'/id/champs'));
276
            array($this->service.'/id', $this->service.'/id/champs'));
237
         if(!$nolimit) {
277
        if(!$nolimit) {
Line 250... Line 290...
250
             $this->table,
290
            $this->table,
251
             $this->requete_condition ? implode(' AND ', $this->requete_condition) : 'TRUE',
291
            $this->requete_condition ? implode(' AND ', $this->requete_condition) : 'TRUE',
252
			 $this->tri ? ($this->tri . ' ' . $this->tri_ordre . ', ') : '',
292
			$this->tri ? ($this->tri . ' ' . $this->tri_ordre . ', ') : '',
253
             $nolimit ? '' : $limiteClause,
293
            $nolimit ? '' : $limiteClause,
254
             __FILE__, __LINE__);
294
            __FILE__, __LINE__);
-
 
295
		//echo "REQ 2: $req\n";
255
		 return $req;
296
		return $req;
256
     }
297
	}
Line 257... Line 298...
257
 
298
 
258
	//ajout d'une limite seulement pour les listes (pas plus de 100 resultats retournés pr les requetes
299
	//ajout d'une limite seulement pour les listes (pas plus de 100 resultats retournés pr les requetes
Line 306... Line 347...
306
			case 'noms-vernaculaires/attributions'	: $reponse = $this->formaterNomsVernaculairesAttributions($resultat);	break;
347
			case 'noms-vernaculaires/attributions'	: $reponse = $this->formaterNomsVernaculairesAttributions($resultat);	break;
307
			case 'noms-vernaculaires/id'			: $reponse = $this->formaterNomsVernaculairesId($resultat);			break;
348
			case 'noms-vernaculaires/id'			: $reponse = $this->formaterNomsVernaculairesId($resultat);			break;
308
			case 'noms-vernaculaires/id/champ'		: $reponse = $this->formaterNomsVernaculairesIdChamp($resultat);	break;
349
			case 'noms-vernaculaires/id/champ'		: $reponse = $this->formaterNomsVernaculairesIdChamp($resultat);	break;
309
			default									:																	break;
350
			default									:																	break;
310
		}
351
		}
-
 
352
		//echo "\nCOMPTE: " . count($reponse['resultat']) . "\n\n";
311
		return $reponse;
353
		return $reponse;
312
	}
354
	}
Line 313... Line 355...
313
	
355
	
314
	public function ajouterJsonEnTeteNV() {
356
	public function ajouterJsonEnTeteNV() {
Line 324... Line 366...
324
			$table_retour_json['href.suivant']   = $url['suivant'];
366
			$table_retour_json['href.suivant']   = $url['suivant'];
325
		}
367
		}
326
		return $table_retour_json;
368
		return $table_retour_json;
327
	}
369
	}
Line -... Line 370...
-
 
370
 
-
 
371
	/**
-
 
372
	 * @TODO Ne devrait pas retourner un oblet mais un Array (conserve l'ordre,
-
 
373
	 * évite d'écraser des clefs etc.)
328
	
374
	 */
-
 
375
	public function ajouterJsonResultatNV($resultat) {
-
 
376
		//echo "CPT RES: " . count($resultat) . "\n\n";
329
	public function ajouterJsonResultatNV($resultat) {
377
		$resultat_json = array();
-
 
378
		foreach ($resultat as $tab) {
330
		foreach ($resultat as $tab) {
379
			$this->table_retour = array();
331
			foreach ($tab as $key => $valeur) {
380
			foreach ($tab as $key => $valeur) {
332
				if ($valeur != '') {
381
				if ($valeur != '') {
333
					switch ($key) {
382
					switch ($key) {
334
						case 'id'				: $num = $valeur;								break;
383
						case 'id'				: $num = $valeur;								break;
Line 341... Line 390...
341
					}
390
					}
342
				}
391
				}
343
			}
392
			}
344
		    if ($this->retour_format == 'max') $this->table_retour['href'] = $this->ajouterHref('noms-vernaculaires', $num);
393
		    if ($this->retour_format == 'max') $this->table_retour['href'] = $this->ajouterHref('noms-vernaculaires', $num);
345
			$resultat_json[$num] = $this->table_retour;
394
			$resultat_json[$num] = $this->table_retour;
346
			$this->table_retour = array();
-
 
347
		}
395
		}
348
		return  $resultat_json;
396
		return $resultat_json;
349
	}
397
	}