31,11 → 31,15 |
} |
|
// Envoie sur la sortie standard |
if($this->formatRetour == 'text/plain') { |
$this->envoyer($info, 'text/plain', 'utf-8', false); |
exit; |
} |
$this->envoyer($info); |
} |
|
/* Méthode pour récupérer une liste d'information sur les collections et/ou structures en fonction de mots et de |
* restrictions. |
/* Méthode pour récupérer une liste d'information sur les collections et/ou structures en fonction de mots et de |
* restrictions. |
* Appelée avec les paramêtres d'url suivant : |
* /CoelRecherche/ParDefaut/_ |
* ou les _ représentent dans l'ordre : mots |
48,25 → 52,25 |
// Pré traitement des paramêtres |
$p = $this->pretraiterParametresUrl($param); |
|
$fromClause = $whereClause = $joinClause = array(); |
self::construireFromEtWhere($p, $fromClause, $joinClause, $whereClause); |
$fromClause = $whereClause = $joinClause = array(); |
self::construireFromEtWhere($p, $fromClause, $joinClause, $whereClause); |
|
// Construction de la requête |
$requete = sprintf( |
'SELECT %s cs_id_structure, cs_ville, cs_nom, cs_code_postal, cs_latitude, cs_longitude, cc_id_collection, cc_nom' |
. ' FROM %s %s' |
. ' WHERE %s ORDER BY %s %s -- %s:%d', |
'SELECT %s cs_id_structure, cs_ville, cs_nom, cs_code_postal, cs_latitude, cs_longitude, cc_id_collection, cc_nom' |
. ' FROM %s %s' |
. ' WHERE %s ORDER BY %s %s -- %s:%d', |
|
$this->distinct ? 'DISTINCT' : '', |
$this->distinct ? 'DISTINCT' : '', |
|
implode(',', $fromClause), |
implode(' ', $joinClause), |
implode(',', $fromClause), |
implode(' ', $joinClause), |
|
$whereClause ? implode(" AND ", $whereClause) : TRUE, |
is_null($this->orderby) ? 'cs_ville ASC, cs_nom ASC, cc_nom ASC' : $this->orderby, |
$whereClause ? implode(" AND ", $whereClause) : TRUE, |
is_null($this->orderby) ? 'cs_ville ASC, cs_nom ASC, cc_nom ASC' : $this->orderby, |
|
$this->limit != -1 ? "LIMIT {$this->start}, {$this->limit}" : "", |
__FILE__, __LINE__); |
$this->limit != -1 ? "LIMIT {$this->start}, {$this->limit}" : "", |
__FILE__, __LINE__); |
|
|
// Récupération des résultats |
84,7 → 88,7 |
} |
|
/* Méthode pour récupérer une liste d'information sur les collections et/ou structures en fonction de mots et de |
* restrictions. |
* restrictions. |
* Appelée avec les paramêtres d'url suivant : |
* /CoelRecherche/ParDefaut/_ |
* ou les _ représentent dans l'ordre : mots |
97,25 → 101,25 |
// Pré traitement des paramêtres |
$p = $this->pretraiterParametresUrl($param); |
|
$fromClause = $whereClause = $joinClause = array(); |
self::construireFromEtWhere($p, $fromClause, $joinClause, $whereClause); |
$fromClause = $whereClause = $joinClause = array(); |
self::construireFromEtWhere($p, $fromClause, $joinClause, $whereClause); |
|
// Construction de la requête |
// Il est important de compter le nombre d'association structure-collection différentes pour obtenir le bon nombre |
$requete = sprintf( |
'SELECT %s COUNT(cs_id_structure) AS nbre, cc_id_collection ' |
. ' FROM %s %s' |
. ' WHERE %s ORDER BY %s LIMIT %d, %d -- %s:%d', |
'SELECT %s COUNT(cs_id_structure) AS nbre, cc_id_collection ' |
. ' FROM %s %s' |
. ' WHERE %s ORDER BY %s LIMIT %d, %d -- %s:%d', |
|
$this->distinct ? 'DISTINCT' : '', |
$this->distinct ? 'DISTINCT' : '', |
|
implode(',', $fromClause), |
implode(' ', $joinClause), |
implode(',', $fromClause), |
implode(' ', $joinClause), |
|
$whereClause ? implode(" AND ", $whereClause) : TRUE, |
is_null($this->orderby) ? 'cs_ville ASC, cs_nom ASC' : $this->orderby, |
$this->start, $this->limit, |
__FILE__, __LINE__); |
$whereClause ? implode(" AND ", $whereClause) : TRUE, |
is_null($this->orderby) ? 'cs_ville ASC, cs_nom ASC' : $this->orderby, |
$this->start, $this->limit, |
__FILE__, __LINE__); |
|
|
// Récupération des résultats |
135,13 → 139,14 |
|
private function pretraiterParametresUrl($param) { |
// Tableau des paramêtres qui peuvent être passés dans l'url |
$params_passes = array('mots' => 'str', |
$params_passes = array( |
'mots' => 'str', |
'sci' => 'bool', |
'bot' => 'int', |
'zg' => 'str', |
'p' => 'str', |
'pr' => 'int', |
'str-d' => 'defaut', |
'str-d' => 'frdepliste', |
'veg' => 'int', |
'projets' => 'int'); |
|
188,7 → 193,11 |
$valeur = null; |
} |
} |
|
|
if ($type == 'frdepliste') { |
$valeur = array_filter(explode(',', $valeur), create_function('$val', 'return preg_match("/^(\d+|2A|2B)$/i", $val);')); |
} |
|
$p[$param_passe] = $valeur; |
} |
} |
197,14 → 206,14 |
} |
|
static function construireFromEtWhere($p, &$from, &$join, &$where) { |
$from = array('coel_collection'); |
$join = array('LEFT JOIN coel_structure ON (cc_ce_structure = cs_id_structure)'); |
$from = array('coel_collection'); |
$join = array('LEFT JOIN coel_structure ON (cc_ce_structure = cs_id_structure)'); |
$where = array(); |
|
// Gestion du from en fonction des paramêtres |
if (isset($p['str-d'])) {// ATTENTION : Remplace $from, doit être situé en première position! |
$from = array('coel_structure'); |
$join = array('LEFT JOIN coel_collection ON (cs_id_structure = cc_ce_structure)'); |
$join = array('LEFT JOIN coel_collection ON (cs_id_structure = cc_ce_structure)'); |
} |
|
// Construire from et where en fonction des paramêtres |
252,7 → 261,7 |
} |
if (isset($p['str-d'])) { |
$where[] = 'cs_ce_truk_pays = 2654'; |
$where[] = "cs_code_postal LIKE '{$p['str-d']}%'"; |
$where[] = sprintf("cs_code_postal REGEXP '^(%s).*'", implode('|', $p['str-d'])); |
} |
|
if (isset($p['veg'])) { |
272,7 → 281,7 |
|
if (isset($p['projets'])) { |
$where[] = "cc_ce_projet IN ({$p['projets']})"; |
$where[] = "cs_ce_projet IN ({$p['projets']})"; |
$where[] = "cs_ce_projet IN ({$p['projets']})"; |
} |
|
|
288,5 → 297,5 |
if (isset($p['p'])) { |
$join[] = 'LEFT JOIN coel_personne ON (ccap_id_personne = cp_id_personne)'; |
} |
} |
} |
} |