Subversion Repositories eFlore/Applications.coel

Compare Revisions

Ignore whitespace Rev 1710 → Rev 1711

/trunk/jrest/services/CoelStructure.php
19,18 → 19,18
);
 
// ATTENTION : tjrs garder la table principale en premier, puis mettre les tables spécialisées.
protected $tables = array( 120 => array(
'nom' => 'coel_structure',
'prefixe' => 'cs',
'id' => array('cs_id_structure')),
122 => array(
'nom' => 'coel_structure_conservation',
'prefixe' => 'csc',
'id' => array('csc_id_structure')),
123 => array(
'nom' => 'coel_structure_valorisation',
'prefixe' => 'csv',
'id' => array('csv_id_structure')));
protected $tables = array( 120 => array(
'nom' => 'coel_structure',
'prefixe' => 'cs',
'id' => array('cs_id_structure')),
122 => array(
'nom' => 'coel_structure_conservation',
'prefixe' => 'csc',
'id' => array('csc_id_structure')),
123 => array(
'nom' => 'coel_structure_valorisation',
'prefixe' => 'csv',
'id' => array('csv_id_structure')));
 
/**
* Méthode principale appelée avec une requête de type GET.
76,7 → 76,7
if(isset($p['id_structure'])) $whereClause[] = "cs_id_structure = {$p['id_structure']}";
 
if(isset($p['recherche'])) {
if(@$this->searchCity && trim($this->searchCity) == true) {
if(@$this->searchCity && trim($this->searchCity) == 'true') {
$whereClause[] = "(" . implode(" OR ", array("cs_nom LIKE {$p['recherche']}", "cs_ville LIKE {$p['recherche']}")) . ")";
} else {
$whereClause[] = "cs_nom LIKE {$p['recherche']}";
141,41 → 141,41
$p = $this->traiterParametresUrl(array('type', 'projets'), $param);
if (!isset($p['type'])) {
$this->messages[] = "Il est obligatoire d'indiquer type de recherche pour utiliser ce service.";
return array();
return array();
}
 
// Construction de la requête
$requete = (($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' '.
' IF ( SUBSTRING( cs_code_postal FROM 1 FOR 2 ) >= 96, '.
' SUBSTRING( cs_code_postal FROM 1 FOR 3 ), '.
' SUBSTRING( cs_code_postal FROM 1 FOR 2 ) ) AS id, '.
' COUNT( cs_id_structure ) AS nbre '.
'FROM coel_structure '.
'WHERE cs_ce_truk_pays = 2654 '.
(isset($p['projets']) ? " AND cs_ce_projet IN ({$p['projets']}) " : '').
'GROUP BY IF ( SUBSTRING( cs_code_postal FROM 1 FOR 2 ) >= 96, '.
' SUBSTRING( cs_code_postal FROM 1 FOR 3 ), '.
' SUBSTRING( cs_code_postal FROM 1 FOR 2 ) ) '.
'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby : 'id ASC').' ';
// Construction de la requête
$requete = (($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' '.
' IF ( SUBSTRING( cs_code_postal FROM 1 FOR 2 ) >= 96, '.
' SUBSTRING( cs_code_postal FROM 1 FOR 3 ), '.
' SUBSTRING( cs_code_postal FROM 1 FOR 2 ) ) AS id, '.
' COUNT( cs_id_structure ) AS nbre '.
'FROM coel_structure '.
'WHERE cs_ce_truk_pays = 2654 '.
(isset($p['projets']) ? " AND cs_ce_projet IN ({$p['projets']}) " : '').
'GROUP BY IF ( SUBSTRING( cs_code_postal FROM 1 FOR 2 ) >= 96, '.
' SUBSTRING( cs_code_postal FROM 1 FOR 3 ), '.
' SUBSTRING( cs_code_postal FROM 1 FOR 2 ) ) '.
'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby : 'id ASC').' ';
 
// Récupération des résultats
try {
$donnees = $this->bdd->query($requete)->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage());
}
// Récupération des résultats
try {
$donnees = $this->bdd->query($requete)->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage());
}
 
if ($donnees === false) {
$this->messages[] = "La requête a retourné aucun résultat.";
return array();
}
if ($donnees === false) {
$this->messages[] = "La requête a retourné aucun résultat.";
return array();
}
 
$info = array();
foreach ($donnees as $donnee) {
$info[$donnee['id']] = $donnee['nbre'];
}
return $info;
}
$info = array();
foreach ($donnees as $donnee) {
$info[$donnee['id']] = $donnee['nbre'];
}
return $info;
}
 
 
static function NULLifNotNum(&$params, $keys_to_null) {
308,52 → 308,52
// NOTES : une structure ne peut pas être supprimée si elle possède des collections liées.
// Vérification de la présence des id passés par l'url
if (!isset($uid[0]) || !isset($uid[1])) {
$this->messages[] = "Identifiant de structure ou d'utilisateur manquant. Vous ne devriez pas avoir accès à ce service.";
$this->envoyer();
return;
$this->messages[] = "Identifiant de structure ou d'utilisateur manquant. Vous ne devriez pas avoir accès à ce service.";
$this->envoyer();
return;
}
 
// Identification de l'utilisateur
list($id_utilisateur, $id_session) = $this->getIdentification($uid[0]);
// Contrôle du non détournement de l'utilisateur
if (! $this->etreAutorise($id_utilisateur)) {
$this->envoyer();
return;
}
// Identification de l'utilisateur
list($id_utilisateur, $id_session) = $this->getIdentification($uid[0]);
// Contrôle du non détournement de l'utilisateur
if (! $this->etreAutorise($id_utilisateur)) {
$this->envoyer();
return;
}
 
// Récupération des id passés par l'url
$identifiants = explode(',', rtrim($uid[1], ','));
// Récupération des id passés par l'url
$identifiants = explode(',', rtrim($uid[1], ','));
 
if (count($identifiants) == 0) {
$this->messages[] = "Aucun enregistrement n'a été supprimé.";
$this->envoyer();
return;
}
if (count($identifiants) == 0) {
$this->messages[] = "Aucun enregistrement n'a été supprimé.";
$this->envoyer();
return;
}
try {
foreach ($identifiants as $id_structure) {
// Vérification que la structure ne possède pas de collections liées
if (self::verifierPresenceCollection($this->bdd, $id_structure)) {
$this->messages[] = "La structure '$id_structure' ne peut pas être supprimée car elle possède des collections liées.";
continue;
}
try {
foreach ($identifiants as $id_structure) {
// Vérification que la structure ne possède pas de collections liées
if (self::verifierPresenceCollection($this->bdd, $id_structure)) {
$this->messages[] = "La structure '$id_structure' ne peut pas être supprimée car elle possède des collections liées.";
continue;
}
 
$params = array('cs_id_structure' => $id_structure, 'csc_id_structure' => $id_structure, 'csv_id_structure' => $id_structure);
$tables_a_modifier = $this->recupererTablesAModifier($params);
$params = array('cs_id_structure' => $id_structure, 'csc_id_structure' => $id_structure, 'csv_id_structure' => $id_structure);
$tables_a_modifier = $this->recupererTablesAModifier($params);
foreach ($tables_a_modifier as $table_id => $table) {
if (! $this->avoirEnregistrement($table)) continue;
foreach ($tables_a_modifier as $table_id => $table) {
if (! $this->avoirEnregistrement($table)) continue;
 
if ($this->supprimer($table) === true) {
// Historisation (Ajout des méta-données)
$cle = $this->recupererCle($table);
$this->historiser($table_id, $cle, 'NULL', $id_utilisateur, 3, $id_session);
}
}
}
} catch (PDOException $e) {
$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage(), $requete);
}
if ($this->supprimer($table) === true) {
// Historisation (Ajout des méta-données)
$cle = $this->recupererCle($table);
$this->historiser($table_id, $cle, 'NULL', $id_utilisateur, 3, $id_session);
}
}
}
} catch (PDOException $e) {
$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage(), $requete);
}
 
// Envoie sur la sortie standard
$this->envoyer();
361,36 → 361,36
static function verifierPresenceCollection($db, $id_structure) {
// Vérification que la structure ne possède pas de collections liées
return ($db->query(sprintf(
'SELECT COUNT(cc_id_collection) AS nbre_collection FROM coel_collection ' .
' WHERE cc_ce_structure = %d GROUP BY cc_ce_structure ',
$id_structure))->fetchColumn() != 0);
return ($db->query(sprintf(
'SELECT COUNT(cc_id_collection) AS nbre_collection FROM coel_collection ' .
' WHERE cc_ce_structure = %d GROUP BY cc_ce_structure ',
$id_structure))->fetchColumn() != 0);
}
 
static function callNominatim(&$params, $db = NULL) {
// lon/lat déjà saisies ?
// lon/lat déjà saisies ?
if (@$params['cs_latitude'] && @$params['cs_longitude']) return FALSE;
 
// ni adresse, ni CP, ni ville ? rien n'est possible
if (!@$params['cs_adresse_01'] && !@$params['cs_code_postal'] && !@$params['cs_ville']) return FALSE;
// ni adresse, ni CP, ni ville ? rien n'est possible
if (!@$params['cs_adresse_01'] && !@$params['cs_code_postal'] && !@$params['cs_ville']) return FALSE;
 
$lonlat = array();
if(Coel::coordGuess(Coel::addrReStruct($params, $db), $lonlat)) {
$params['cs_latitude'] = $lonlat['lat'];
$params['cs_longitude'] = $lonlat['lon'];
return TRUE;
}
$lonlat = array();
if(Coel::coordGuess(Coel::addrReStruct($params, $db), $lonlat)) {
$params['cs_latitude'] = $lonlat['lat'];
$params['cs_longitude'] = $lonlat['lon'];
return TRUE;
}
 
// second guess, sans code postal
if(@$params['cs_code_postal']) {
$params2 = $params;
unset($params2['cs_code_postal']);
if(Coel::coordGuess(Coel::addrReStruct($params2, $db), $lonlat)) {
$params['cs_latitude'] = $lonlat['lat'];
$params['cs_longitude'] = $lonlat['lon'];
return TRUE;
}
}
// second guess, sans code postal
if(@$params['cs_code_postal']) {
$params2 = $params;
unset($params2['cs_code_postal']);
if(Coel::coordGuess(Coel::addrReStruct($params2, $db), $lonlat)) {
$params['cs_latitude'] = $lonlat['lat'];
$params['cs_longitude'] = $lonlat['lon'];
return TRUE;
}
}
return FALSE;
}