Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 1107 | Rev 1109 | Go to most recent revision | Show entire file | Ignore 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() {
233
	public function assemblerLaRequete() {
234
         $nolimit = in_array(
-
 
235
             $this->format_reponse,
234
		$requete = false;
236
             array($this->service.'/id', $this->service.'/id/champs'));
235
		if ($this->format_reponse == 'noms-vernaculaires') {
237
         if(!$nolimit) {
236
			// mode liste
238
             $count = $this->recupererTotalResultat();
237
			$requete = $this->assemblerRequeteListe();
239
             $limiteClause = self::formerRequeteLimite( // LIMIT
238
		} else {
-
 
239
			$requete = $this->assemblerRequeteAutre();
240
                 $this->limite_requete['depart'],
240
		}
241
                 $count,
-
 
242
                 $this->limite_requete['limite']);
241
		return $requete;
Line -... Line 242...
-
 
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
	  */
-
 
273
	protected function assemblerRequeteAutre() {
-
 
274
        $nolimit = in_array(
-
 
275
            $this->format_reponse,
-
 
276
            array($this->service.'/id', $this->service.'/id/champs'));
-
 
277
        if(!$nolimit) {
-
 
278
            $count = $this->recupererTotalResultat();
-
 
279
            $limiteClause = self::formerRequeteLimite( // LIMIT
-
 
280
                $this->limite_requete['depart'],
-
 
281
                $count,
-
 
282
                $this->limite_requete['limite']);
243
         }
283
        }
244
 
284
 
245
         $req = sprintf(
285
        $req = sprintf(
246
             'SELECT %s, IF(num_statut="",1,0) AS is_null' .
286
            'SELECT %s, IF(num_statut="",1,0) AS is_null' .
247
             ' FROM %s WHERE %s ORDER BY %s is_null ASC, num_statut ASC %s -- %s:%d',
287
            ' FROM %s WHERE %s ORDER BY %s is_null ASC, num_statut ASC %s -- %s:%d',
248
 
288
 
249
             in_array('*', $this->requete_champ) ? ' * ' : implode(', ', $this->requete_champ),
289
            in_array('*', $this->requete_champ) ? ' * ' : implode(', ', $this->requete_champ),
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 . ', ') : '',
-
 
293
            $nolimit ? '' : $limiteClause,
253
             $nolimit ? '' : $limiteClause,
294
            __FILE__, __LINE__);
254
             __FILE__, __LINE__);
295
		//echo "REQ 2: $req\n";
Line 255... Line 296...
255
		 return $req;
296
		return $req;
256
     }
297
	}
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 323... Line 365...
323
		if (isset($url['suivant']) && $url['suivant']   != '') {
365
		if (isset($url['suivant']) && $url['suivant']   != '') {
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
	}
328
	
370
 
-
 
371
	/**
-
 
372
	 * @TODO Ne devrait pas retourner un oblet mais un Array (conserve l'ordre,
-
 
373
	 * évite d'écraser des clefs etc.)
-
 
374
	 */
329
	public function ajouterJsonResultatNV($resultat) {
375
	public function ajouterJsonResultatNV($resultat) {
-
 
376
		//echo "CPT RES: " . count($resultat) . "\n\n";
-
 
377
		$resultat_json = array();
330
		foreach ($resultat as $tab) {
378
		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;
335
						case 'nom_vernaculaire'	: $this->table_retour['nom'] = $valeur;			break;
384
						case 'nom_vernaculaire'	: $this->table_retour['nom'] = $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
	}
Line 350... Line 398...
350
 
398
 
351
	
399