Subversion Repositories eFlore/Projets.eflore-projets

Compare Revisions

Ignore whitespace Rev 1107 → Rev 1108

/trunk/services/modules/0.1/nvjfl/NomsVernaculaires.php
229,32 → 229,73
}
}
 
//+------------------------------------------------------------------------------------------------------+
public function assemblerLaRequete() {
$nolimit = in_array(
$this->format_reponse,
array($this->service.'/id', $this->service.'/id/champs'));
if(!$nolimit) {
$count = $this->recupererTotalResultat();
$limiteClause = self::formerRequeteLimite( // LIMIT
$this->limite_requete['depart'],
$count,
$this->limite_requete['limite']);
}
// fait du neuf avec du vieux
public function assemblerLaRequete() {
$requete = false;
if ($this->format_reponse == 'noms-vernaculaires') {
// mode liste
$requete = $this->assemblerRequeteListe();
} else {
$requete = $this->assemblerRequeteAutre();
}
return $requete;
}
 
$req = sprintf(
'SELECT %s, IF(num_statut="",1,0) AS is_null' .
' FROM %s WHERE %s ORDER BY %s is_null ASC, num_statut ASC %s -- %s:%d',
/**
* Exécute un astucieux GROUP BY afin que le service retourne ce qu'il
* annonce qu'il retourne (truc de ouf!) - pour le mode "liste"
*/
protected function assemblerRequeteListe() {
$count = $this->recupererTotalResultat();
$limiteClause = self::formerRequeteLimite( // LIMIT
$this->limite_requete['depart'],
$count,
$this->limite_requete['limite']
);
 
in_array('*', $this->requete_champ) ? ' * ' : implode(', ', $this->requete_champ),
$this->table,
$this->requete_condition ? implode(' AND ', $this->requete_condition) : 'TRUE',
$this->tri ? ($this->tri . ' ' . $this->tri_ordre . ', ') : '',
$nolimit ? '' : $limiteClause,
__FILE__, __LINE__);
return $req;
}
$req = sprintf(
'SELECT %s, group_concat(num_taxon) as num_taxon, IF(num_statut="",1,0) AS is_null' .
' FROM %s WHERE %s GROUP BY id ORDER BY %s is_null ASC, num_statut ASC %s -- %s:%d',
 
in_array('*', $this->requete_champ) ? ' * ' : implode(', ', $this->requete_champ),
$this->table,
$this->requete_condition ? implode(' AND ', $this->requete_condition) : 'TRUE',
$this->tri ? ($this->tri . ' ' . $this->tri_ordre . ', ') : '',
$limiteClause,
__FILE__, __LINE__);
//echo "REQ: $req\n";
return $req;
}
 
/**
* Ancien système d'assemblage de requête
*/
protected function assemblerRequeteAutre() {
$nolimit = in_array(
$this->format_reponse,
array($this->service.'/id', $this->service.'/id/champs'));
if(!$nolimit) {
$count = $this->recupererTotalResultat();
$limiteClause = self::formerRequeteLimite( // LIMIT
$this->limite_requete['depart'],
$count,
$this->limite_requete['limite']);
}
 
$req = sprintf(
'SELECT %s, IF(num_statut="",1,0) AS is_null' .
' FROM %s WHERE %s ORDER BY %s is_null ASC, num_statut ASC %s -- %s:%d',
 
in_array('*', $this->requete_champ) ? ' * ' : implode(', ', $this->requete_champ),
$this->table,
$this->requete_condition ? implode(' AND ', $this->requete_condition) : 'TRUE',
$this->tri ? ($this->tri . ' ' . $this->tri_ordre . ', ') : '',
$nolimit ? '' : $limiteClause,
__FILE__, __LINE__);
//echo "REQ 2: $req\n";
return $req;
}
 
//ajout d'une limite seulement pour les listes (pas plus de 100 resultats retournés pr les requetes
// suivantes : /noms-vernaculaires et /noms-vernaculaires/#id/relations)
static function formerRequeteLimite(&$depart, $total, $limite) {
308,6 → 349,7
case 'noms-vernaculaires/id/champ' : $reponse = $this->formaterNomsVernaculairesIdChamp($resultat); break;
default : break;
}
//echo "\nCOMPTE: " . count($reponse['resultat']) . "\n\n";
return $reponse;
}
325,9 → 367,16
}
return $table_retour_json;
}
 
/**
* @TODO Ne devrait pas retourner un oblet mais un Array (conserve l'ordre,
* évite d'écraser des clefs etc.)
*/
public function ajouterJsonResultatNV($resultat) {
//echo "CPT RES: " . count($resultat) . "\n\n";
$resultat_json = array();
foreach ($resultat as $tab) {
$this->table_retour = array();
foreach ($tab as $key => $valeur) {
if ($valeur != '') {
switch ($key) {
343,9 → 392,8
}
if ($this->retour_format == 'max') $this->table_retour['href'] = $this->ajouterHref('noms-vernaculaires', $num);
$resultat_json[$num] = $this->table_retour;
$this->table_retour = array();
}
return $resultat_json;
return $resultat_json;
}