460 |
delphine |
1 |
<?php
|
|
|
2 |
class Dao extends Bdd {
|
|
|
3 |
|
|
|
4 |
// +-------------------------------------------------------------------------------------------------------------------+
|
|
|
5 |
// Requête d'intégration sur table sophy_publication
|
|
|
6 |
public function integrerBiblio($biblio){
|
|
|
7 |
$biblio = array_map(array($this, 'proteger'), $biblio);
|
|
|
8 |
$requete = 'INSERT INTO sophy_publication VALUES ('.implode(', ', $biblio).');';
|
|
|
9 |
$resultat = $this->requeter($requete);
|
|
|
10 |
if ($resultat === false) {
|
|
|
11 |
$info = $biblio['id_publi']." n'est pas intégrée.\n";
|
|
|
12 |
} else {
|
|
|
13 |
$info = $biblio['id_publi']." est intégrée.\n";
|
|
|
14 |
}
|
|
|
15 |
return $info;
|
|
|
16 |
}
|
|
|
17 |
|
|
|
18 |
// +-------------------------------------------------------------------------------------------------------------------+
|
|
|
19 |
// Requête d'intégration sur table sophy_tableau
|
|
|
20 |
public function integrerTableau($titre) {
|
|
|
21 |
$titre = array_map(array($this, 'proteger'), $titre);
|
|
|
22 |
$requete_integre_tableau = 'INSERT INTO sophy_tableau VALUES ('.implode(', ', $titre).');';
|
|
|
23 |
$reponse_requete_int_tab = $this->requeter($requete_integre_tableau);
|
|
|
24 |
if ($reponse_requete_int_tab === false) {
|
|
|
25 |
$info = "tableau ".$titre['numPubli']."-".$titre['numTableau']." non intégrée.";
|
|
|
26 |
} else {
|
|
|
27 |
$info = '';
|
|
|
28 |
}
|
|
|
29 |
return $info;
|
|
|
30 |
}
|
|
|
31 |
// +-------------------------------------------------------------------------------------------------------------------+
|
|
|
32 |
// Requêtes sur table sophy_station
|
|
|
33 |
// Requête d'intégration qui retourne l'id de la dernière station insérée (rechercheIdStation)
|
|
|
34 |
public function integrerStation($station) {
|
|
|
35 |
$station = array_map(array($this, 'proteger'), $station);
|
|
|
36 |
$reponse['id_station'] = null;
|
|
|
37 |
$requete_integre_station = 'INSERT INTO sophy_station (`ss_num_source`, `ss_poste_meteo`, `ss_localisation`,
|
|
|
38 |
`ss_latitude`, `ss_pays`, `ss_longitude`,`ss_code_departement`, `ss_altitude`, `ss_code_insee_commune`,
|
|
|
39 |
`ss_ce_precision_geographique`, `ss_systeme_projection`, `ss_latitude_dms`, `ss_longitude_dms`, `ss_latitude_wgs`,
|
|
|
40 |
`ss_longitude_wgs`, `ss_utmNorthing`, `ss_utmEasting`, `ss_utmZone`) VALUES
|
|
|
41 |
('.implode(', ', $station).');';
|
|
|
42 |
|
|
|
43 |
$reponse_requete_int_stat = $this->requeter($requete_integre_station);
|
|
|
44 |
if ($reponse_requete_int_stat === false) {
|
|
|
45 |
$reponse['info'] = "station ".$station['numSource']." non intégrée. $requete_integre_station";
|
|
|
46 |
} else {
|
|
|
47 |
$reponse['id_station'] = $this->rechercheIdStation();
|
|
|
48 |
$reponse['info'] = '';
|
|
|
49 |
}
|
|
|
50 |
return $reponse;
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
// Retourne le dernier identifiant de la table station
|
|
|
54 |
public function rechercheIdStation() {
|
|
|
55 |
$requete_select_id = "SELECT MAX(ss_id_station) as idMax FROM sophy_station;";
|
|
|
56 |
$resultat_requete_id = $this->recuperer($requete_select_id);
|
|
|
57 |
return $resultat_requete_id['idMax'];
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
public function rechercherCoordonneesWgs() {
|
|
|
61 |
$requete = "SELECT `ss_longitude_wgs` as longitude, `ss_latitude_wgs` as latitude
|
|
|
62 |
FROM `sophy_station`
|
|
|
63 |
GROUP BY `longitude` , `latitude`";
|
|
|
64 |
/* Les stations restantes avec coordonnées sans code insee
|
|
|
65 |
SELECT COUNT( * ) AS `Lignes` , `ss_longitude_wgs` , `ss_latitude_wgs`
|
|
|
66 |
FROM `sophy_station`
|
|
|
67 |
WHERE `ss_latitude_wgs` != ''
|
|
|
68 |
AND `ss_code_insee_calculee` =0
|
|
|
69 |
GROUP BY `ss_longitude_wgs` , `ss_latitude_wgs`
|
|
|
70 |
ORDER BY `Lignes` DESC
|
|
|
71 |
*/
|
|
|
72 |
$resultat = $this->recupererTous($requete);
|
|
|
73 |
return $resultat;
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
public function creerColonneCodeInseeCalculee() {
|
|
|
77 |
$create = "ALTER TABLE `sophy_station` ADD `ss_code_insee_calculee` VARCHAR( 5 ) NOT NULL ,
|
|
|
78 |
ADD INDEX ( `ss_code_insee_calculee` )";
|
|
|
79 |
$this->requeter($create);
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
public function ajouterCodeInseeCalculee($latitude, $longitude, $code_insee) {
|
|
|
83 |
$insert = "UPDATE `sophy_station` SET `ss_code_insee_calculee` = '$code_insee' ".
|
|
|
84 |
"WHERE ss_latitude_wgs = '$latitude' AND ss_longitude_wgs = '$longitude'";
|
|
|
85 |
$this->requeter($insert);
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
// +-------------------------------------------------------------------------------------------------------------------+
|
|
|
89 |
// Requête d'intégration sur table sophy_releve
|
|
|
90 |
public function integrerReleve($titre, $numReleve, $idStation) {
|
|
|
91 |
$requete_integre_releve = "INSERT INTO sophy_releve VALUES (".$titre['numPubli'].", ".
|
|
|
92 |
$titre['numTableau'].", ".$numReleve.", ".$idStation.");";
|
|
|
93 |
$reponse_requete_int_tab = $this->requeter($requete_integre_releve);
|
|
|
94 |
if ($reponse_requete_int_tab === false) {
|
|
|
95 |
$info = "releve ".$titre['numPubli']."-".$titre['numTableau']."-".$numReleve." non intégrée.";
|
|
|
96 |
echo $requete_integre_releve."\n";
|
|
|
97 |
} else {
|
|
|
98 |
$info = '';
|
|
|
99 |
}
|
|
|
100 |
return $info;
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
// +-------------------------------------------------------------------------------------------------------------------+
|
|
|
104 |
// Requête d'intégration sur table sophy_observation
|
|
|
105 |
public function integrerObservation($observations) {
|
|
|
106 |
$requete = "INSERT INTO `sophy_observation` (`so_id_publi`, `so_id_tableau`, `so_id_releve`, `so_num_ligne`,".
|
|
|
107 |
" `so_id_taxon`, `so_id_strate`, `so_ce_abondance`) VALUES ";
|
|
|
108 |
foreach ($observations as $plante) {
|
|
|
109 |
if (isset($plante)) {
|
|
|
110 |
foreach ($plante as $observation) {
|
|
|
111 |
$observation = array_map(array($this, 'proteger'), $observation);
|
|
|
112 |
$requete .= " (".implode(', ', $observation)." ),";
|
|
|
113 |
}
|
|
|
114 |
}
|
|
|
115 |
}
|
|
|
116 |
$requete = substr($requete,0,-1).";";
|
|
|
117 |
$resultat = $this->requeter($requete);
|
|
|
118 |
if ($resultat === false) {
|
|
|
119 |
echo $requete."\n";
|
|
|
120 |
$info = " n'est pas intégrée.\n";
|
|
|
121 |
} else {
|
|
|
122 |
$info = '';
|
|
|
123 |
}
|
|
|
124 |
return $info;
|
|
|
125 |
}
|
|
|
126 |
|
|
|
127 |
|
|
|
128 |
// +-------------------------------------------------------------------------------------------------------------------+
|
|
|
129 |
// Requête pour calculer les statistiques sur toutes les tables
|
|
|
130 |
public function getNombreLigne($tables) {
|
|
|
131 |
$requete = null;
|
|
|
132 |
foreach ($tables as $nomTable => $colonnes) {
|
|
|
133 |
$requete = "SELECT COUNT(*) as nombreTotal";
|
|
|
134 |
foreach ($colonnes as $recherche => $nom) {
|
|
|
135 |
$requete .= ", count(distinct {$recherche}) as {$nom}";
|
|
|
136 |
}
|
|
|
137 |
$requete .= " FROM {$nomTable}; ";
|
|
|
138 |
$resultat[$nomTable] = $this->recupererTous($requete);
|
|
|
139 |
}
|
|
|
140 |
return $resultat;
|
|
|
141 |
}
|
|
|
142 |
|
|
|
143 |
// +-------------------------------------------------------------------------------------------------------------------+
|
|
|
144 |
// Requête de création et d'insertion sur table sophy_tapir
|
|
|
145 |
public function creerTapir() {
|
|
|
146 |
$info = 'Créé';
|
|
|
147 |
$requete = "DROP TABLE IF EXISTS `sophy_tapir`;
|
|
|
148 |
CREATE table `sophy_tapir` AS
|
|
|
149 |
SELECT CONCAT(_utf8'urn:lsid:tela-botanica.org:sophy:',o.so_id_publi,'.',
|
|
|
150 |
o.so_id_tableau,'.',o.so_id_releve,'.',o.so_num_ligne,'.',
|
|
|
151 |
o.so_id_taxon,'.',o.so_id_strate) AS `guid`,
|
|
|
152 |
CONCAT(o.so_id_publi,'.',o.so_id_tableau,'.',o.so_id_releve,'.',
|
|
|
153 |
o.so_num_ligne,'.',o.so_id_taxon,'.',o.so_id_strate) AS `observation_id`,
|
|
|
154 |
p.sp_date AS observation_date,
|
|
|
155 |
t.st_nom AS nom_scientifique_complet,
|
|
|
156 |
CONCAT(s.ss_code_departement,s.ss_code_insee_commune) AS lieu_commune_code_insee,
|
|
|
157 |
s.ss_localisation AS `lieu_station_nom`,
|
|
|
158 |
s.ss_latitude_wgs AS `lieu_station_latitude`,
|
|
|
159 |
s.ss_longitude_wgs AS `lieu_station_longitude`,
|
|
|
160 |
s.ss_utmEasting AS `lieu_station_utm_est`,
|
|
|
161 |
s.ss_utmNorthing AS `lieu_station_utm_nord`,
|
|
|
162 |
s.ss_utmZone AS `lieu_station_utm_zone`,
|
|
|
163 |
p.sp_auteur AS observateur_nom_complet
|
|
|
164 |
FROM sophy_observation o LEFT JOIN sophy_taxon t ON (o.so_id_taxon = t.st_id_taxon)
|
|
|
165 |
LEFT JOIN sophy_releve r ON (r.sr_id_publi = o.so_id_publi AND r.sr_id_tableau = o.so_id_tableau AND r.sr_id_releve = o.so_id_releve )
|
|
|
166 |
LEFT JOIN sophy_station s ON (r.sr_id_station = s.ss_id_station)
|
|
|
167 |
LEFT JOIN sophy_publication p ON (r.sr_id_publi = p.sp_id_publi);";
|
|
|
168 |
$reponse = $this->requeter($requete);
|
|
|
169 |
if ($reponse === false) {
|
|
|
170 |
$info = "Erreur";
|
|
|
171 |
}
|
|
|
172 |
return $info;
|
|
|
173 |
}
|
|
|
174 |
}
|
|
|
175 |
?>
|