31 |
aurelien |
1 |
<?php
|
|
|
2 |
// declare(encoding='UTF-8');
|
|
|
3 |
/**
|
|
|
4 |
* Classe de gestion des observations.
|
|
|
5 |
*
|
|
|
6 |
* @package ODS_saisie
|
|
|
7 |
* @category Php 5.2
|
|
|
8 |
* @author Aurélien Peronnet <aurelien@tela-botanica.org>
|
|
|
9 |
* @copyright 2010 Tela-Botanica
|
|
|
10 |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
|
|
|
11 |
* @license http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
|
|
|
12 |
* @version SVN: $Id: Fiche.php 152 2010-09-06 16:19:12Z jpm $
|
|
|
13 |
*/
|
|
|
14 |
class Observation extends aControleur {
|
|
|
15 |
|
|
|
16 |
private $id_observation_en_cours = null;
|
|
|
17 |
|
|
|
18 |
public function __construct() {
|
|
|
19 |
|
|
|
20 |
parent::__construct();
|
|
|
21 |
$this->initialiser();
|
|
|
22 |
}
|
|
|
23 |
|
|
|
24 |
public function initialiser() {
|
|
|
25 |
|
70 |
aurelien |
26 |
if(isset($_GET['$id_observation'])) {
|
|
|
27 |
$this->id_observation_en_cours = $_GET['id_observation'];
|
|
|
28 |
}
|
43 |
aurelien |
29 |
$this->setNavigation();
|
31 |
aurelien |
30 |
}
|
|
|
31 |
|
|
|
32 |
public function executerActionParDefaut() {
|
|
|
33 |
return $this->afficherFormulaireAjoutIndividu();
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
|
|
|
37 |
public function afficherFormulaireAjoutObservation($id_individu) {
|
|
|
38 |
$donnees = array();
|
|
|
39 |
$formulaire = $this->getVue('formulaires/observation_saisie',$donnees);
|
|
|
40 |
$this->setSortie(self::RENDU_CORPS, $formulaire);
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
public function afficherFormulaireModificationObservation() {
|
|
|
44 |
|
|
|
45 |
$id_individu_a_modifier_observation = $_GET['id_individu'];
|
|
|
46 |
|
|
|
47 |
$id_espece = $_GET['id_espece'];
|
|
|
48 |
$id_station = $_GET['id_station'];
|
|
|
49 |
|
|
|
50 |
$id_utilisateur = AppControleur::getUtilisateur()->getIdentifiantNumerique();
|
|
|
51 |
|
|
|
52 |
$espece = new Espece();
|
|
|
53 |
$evenements = $espece->getListeEvenementPourEspece($id_espece);
|
|
|
54 |
|
|
|
55 |
$station = new Station();
|
|
|
56 |
|
43 |
aurelien |
57 |
$individus = $station->getIndividusStationPourEspece($id_station,$id_espece);
|
31 |
aurelien |
58 |
foreach($individus as &$individu) {
|
|
|
59 |
|
|
|
60 |
$observation = new Observation();
|
44 |
aurelien |
61 |
$individu['observations'] = $observation->getListeObservationsPourIndividu($individu['id_individu']);
|
70 |
aurelien |
62 |
$individu['url'] = Liens::getUrlConsultationFicheIndividu($id_station,$id_espece, $individu['id_individu']);
|
44 |
aurelien |
63 |
|
31 |
aurelien |
64 |
}
|
44 |
aurelien |
65 |
|
31 |
aurelien |
66 |
$donnees['evenements'] = $evenements;
|
44 |
aurelien |
67 |
$donnees['stades'] = $this->aplatirListeEvenementHierachiseeEnListeParStades($evenements);
|
31 |
aurelien |
68 |
$donnees['individus'] = $individus;
|
|
|
69 |
$donnees['id_station'] = $_GET['id_station'];
|
|
|
70 |
$donnees['id_espece'] = $_GET['id_espece'];
|
44 |
aurelien |
71 |
|
|
|
72 |
if(isset($_GET['annee'])) {
|
|
|
73 |
$donnees['annee'] = $_GET['annee'];
|
|
|
74 |
} else {
|
|
|
75 |
$donnees['annee'] = date('Y');
|
|
|
76 |
}
|
|
|
77 |
|
31 |
aurelien |
78 |
$donnees['id_individu_a_modifier_observation'] = $id_individu_a_modifier_observation;
|
|
|
79 |
|
|
|
80 |
$this->setSortie(self::RENDU_CORPS, $this->getVue('formulaires/evenement_modification', $donnees));
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
// +---------------------------------------------------------------------------------------------------------------+
|
43 |
aurelien |
84 |
// METHODES POUR FABRIQUER LE MENU
|
|
|
85 |
public function setNavigation() {
|
|
|
86 |
|
|
|
87 |
$station = new Station();
|
|
|
88 |
$this->setSortie(self::RENDU_NAVIGATION, $station->construireMenuNavigation());
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
// +---------------------------------------------------------------------------------------------------------------+
|
31 |
aurelien |
92 |
// METHODES APPELEES LORS DE LA VALIDATION D'UN FORMULAIRE
|
|
|
93 |
public function validerFormulaireAjoutObservation() {
|
|
|
94 |
|
43 |
aurelien |
95 |
$valeurs_formulaires = $_POST;
|
31 |
aurelien |
96 |
|
|
|
97 |
$valeurs_verifiees = array();
|
|
|
98 |
|
|
|
99 |
$observation_dao = new ObservationDao();
|
|
|
100 |
$observation_dao->ajouterObservation($valeurs_verifiees);
|
44 |
aurelien |
101 |
|
31 |
aurelien |
102 |
}
|
|
|
103 |
|
|
|
104 |
public function validerFormulaireModificationObservation() {
|
44 |
aurelien |
105 |
|
|
|
106 |
$valeurs_verifiees = $this->collecterValeursFormulaireModificationObservation();
|
31 |
aurelien |
107 |
|
44 |
aurelien |
108 |
$observation_dao = new ObservationDao();
|
|
|
109 |
$observation_dao->modifierObservation($valeurs_verifiees['id_individu'], $valeurs_verifiees);
|
31 |
aurelien |
110 |
|
44 |
aurelien |
111 |
$individu = new Individu();
|
43 |
aurelien |
112 |
|
44 |
aurelien |
113 |
$this->setSortie(self::RENDU_CORPS, $individu->getListeIndividu());
|
31 |
aurelien |
114 |
|
44 |
aurelien |
115 |
}
|
|
|
116 |
|
63 |
aurelien |
117 |
public function validerFormulaireModificationObservationAjax() {
|
|
|
118 |
|
|
|
119 |
$valeurs_verifiees = $this->collecterValeursFormulaireModificationObservation();
|
|
|
120 |
|
|
|
121 |
$observation_dao = new ObservationDao();
|
|
|
122 |
$observation_dao->modifierObservation($valeurs_verifiees['id_individu'],$valeurs_verifiees);
|
|
|
123 |
|
|
|
124 |
$retour = array('reponse' => 'OK');
|
|
|
125 |
|
|
|
126 |
echo json_encode($retour);
|
|
|
127 |
exit;
|
|
|
128 |
}
|
|
|
129 |
|
44 |
aurelien |
130 |
private function collecterValeursFormulaireModificationObservation() {
|
|
|
131 |
|
|
|
132 |
$valeurs_verifiees = array();
|
|
|
133 |
|
|
|
134 |
foreach($_POST as $nom_champ => $valeur) {
|
|
|
135 |
|
|
|
136 |
$id_si_est_champ_observation = $this->renvoyerIdEvenementSiChampDeFormulaireObservation($nom_champ);
|
|
|
137 |
|
|
|
138 |
if($id_si_est_champ_observation && trim($valeur) != '') {
|
|
|
139 |
$valeurs_verifiees[$nom_champ] = $valeur;
|
|
|
140 |
}
|
|
|
141 |
}
|
|
|
142 |
|
|
|
143 |
$valeurs_verifiees['id_individu'] = $_POST['id_individu'];
|
|
|
144 |
$valeurs_verifiees['annee_en_cours'] = $_POST['annee_en_cours'];
|
|
|
145 |
|
|
|
146 |
//TODO: verifier valeurs plus complètement
|
|
|
147 |
|
|
|
148 |
return $valeurs_verifiees;
|
31 |
aurelien |
149 |
|
|
|
150 |
}
|
|
|
151 |
|
44 |
aurelien |
152 |
private function renvoyerIdEvenementSiChampDeFormulaireObservation($champ) {
|
|
|
153 |
|
|
|
154 |
$tab_champ = split('observation_',$champ);
|
|
|
155 |
|
|
|
156 |
if(count($tab_champ) > 1 && is_numeric($tab_champ[1])) {
|
|
|
157 |
return $tab_champ[1];
|
|
|
158 |
}
|
|
|
159 |
|
|
|
160 |
return false;
|
|
|
161 |
}
|
|
|
162 |
|
31 |
aurelien |
163 |
// +---------------------------------------------------------------------------------------------------------------+
|
|
|
164 |
// METHODES DE RECHERCHE DE DONNEES
|
|
|
165 |
public function getListeObservationsPourIndividu($id_individu, $annee = null) {
|
|
|
166 |
|
|
|
167 |
$observation_dao = new ObservationDao();
|
|
|
168 |
$observations_pour_individu = $observation_dao->getListeObservationsPourIndividu($id_individu, $annee);
|
|
|
169 |
|
|
|
170 |
return $observations_pour_individu;
|
|
|
171 |
}
|
44 |
aurelien |
172 |
|
|
|
173 |
|
|
|
174 |
private function aplatirListeEvenementHierachiseeEnListeParStades($liste_evenements_hierarchisee) {
|
|
|
175 |
|
|
|
176 |
$liste_evenements_plate_par_stade = array();
|
|
|
177 |
|
|
|
178 |
foreach($liste_evenements_hierarchisee as $evenement_hierarchise) {
|
|
|
179 |
foreach($evenement_hierarchise['stades'] as $id_stade => $stade) {
|
|
|
180 |
$liste_evenements_plate_par_stade[$id_stade] = $stade;
|
|
|
181 |
}
|
|
|
182 |
}
|
|
|
183 |
|
|
|
184 |
return $liste_evenements_plate_par_stade;
|
|
|
185 |
}
|
|
|
186 |
|
|
|
187 |
// +---------------------------------------------------------------------------------------------------------------+
|
|
|
188 |
// METHODES UTILITAIRES STATIQUES (UTILES POUR LES FORMULAIRES)
|
|
|
189 |
public static function individuAObservationValidePourStade($individu, $annee, $evenement, $id_stade) {
|
|
|
190 |
|
|
|
191 |
return (isset($individu['observations'][$annee][$evenement][$id_stade]) && trim($individu['observations'][$annee][$evenement][$id_stade]) != '');
|
|
|
192 |
}
|
|
|
193 |
|
|
|
194 |
public static function renvoyerObservationStadePourIndividu($individu, $annee, $evenement, $id_stade) {
|
|
|
195 |
|
|
|
196 |
if(self::individuAObservationValidePourStade($individu, $annee, $evenement, $id_stade)) {
|
|
|
197 |
return $individu['observations'][$annee][$evenement][$id_stade];
|
|
|
198 |
}
|
|
|
199 |
|
|
|
200 |
return '';
|
|
|
201 |
}
|
70 |
aurelien |
202 |
}
|
|
|
203 |
?>
|