Subversion Repositories eFlore/Applications.coel

Compare Revisions

Ignore whitespace Rev 1687 → Rev 1688

/trunk/jrest/services/CoelStructure.php
65,23 → 65,28
// Initialisation des variables
$info = array();
 
$whereClause = array();
if(isset($p['id_projet'])) $whereClause[] = "cs_ce_projet = {$p['id_projet']}";
if(isset($p['id_structure'])) $whereClause[] = "cs_id_structure = {$p['id_structure']}";
if(isset($p['recherche'])) $whereClause[] = "(" . implode(" OR ", array("cs_nom LIKE {$p['recherche']}", "cs_ville LIKE {$p['recherche']}")) . ")";
 
 
// Construction de la requête
$requete = (($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' cs.*, csc.*, csv.*, '.
' cmhl_date_modification, cmhl_notes, cmhl_source, cmhl_ce_modifier_par, cmhl_ce_etat, cmhl_ip '.
'FROM coel_structure AS cs '.
' LEFT JOIN coel_meta_historique_ligne ON (cs_ce_meta = cmhl_id_historique_ligne) '.
' LEFT JOIN coel_structure_conservation AS csc ON (cs_id_structure = csc_id_structure) '.
' LEFT JOIN coel_structure_valorisation AS csv ON (cs_id_structure = csv_id_structure) '.
((count($p) != 0) ? 'WHERE ' : '').
((isset($p['id_projet'])) ? "AND cs_ce_projet = {$p['id_projet']} " : '').
((isset($p['id_structure'])) ? "AND cs_id_structure = {$p['id_structure']} " : '').
(isset($p['recherche']) ? $this->construireWhereRecherche($p['recherche']) : '').
'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby : 'cs.cs_nom ASC').' ';
$requete = str_replace('WHERE AND', 'WHERE', $requete);
$requete_compte = $requete;
$requete .= "LIMIT $this->start, $this->limit ";
$requete = sprintf(
'SELECT SQL_CALC_FOUND_ROWS %s cs.*, csc.*, csv.*, cmhl_date_modification, cmhl_notes, cmhl_source, cmhl_ce_modifier_par, cmhl_ce_etat, cmhl_ip '
. ' FROM coel_structure AS cs '
. ' LEFT JOIN coel_meta_historique_ligne ON (cs_ce_meta = cmhl_id_historique_ligne) '
. ' LEFT JOIN coel_structure_conservation AS csc ON (cs_id_structure = csc_id_structure) '
. ' LEFT JOIN coel_structure_valorisation AS csv ON (cs_id_structure = csv_id_structure) '
. ' WHERE %s ORDER BY %s LIMIT %d, %d -- %s:%d',
 
$this->distinct ? 'DISTINCT' : '',
$whereClause ? implode(" AND ", $whereClause) : TRUE,
is_null($this->orderby) ? 'cs.cs_nom ASC' : $this->orderby,
$this->start, $this->limit,
__FILE__, __LINE__);
 
 
// Récupération des résultats
try {
// SPÉCIAL :
91,8 → 96,8
$this->messages[] = "La requête a retourné aucun résultat.";
}
$elements_nbre = $this->bdd->query($requete_compte)->rowCount();
$info['nbElements'] = $elements_nbre;
$elements_nbre = $this->bdd->query("SELECT FOUND_ROWS() AS c")->fetch(PDO::FETCH_ASSOC);
$info['nbElements'] = $elements_nbre['c'];
$info['structures'] = $donnees;
} catch (PDOException $e) {
$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage());
101,15 → 106,6
return $info;
}
private function construireWhereRecherche($recherche) {
$recherche = "AND ".
"(".
"cs_nom LIKE {$recherche} OR ".
"cs_ville LIKE {$recherche} ".
")";
return $recherche;
}
/* Méthode pour récupérer le nombre de structure par zone géographique.
* Appelée avec les paramêtres d'url suivant :
* /CoelStructure/ParZoneGeo/_