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 |
|
|
|
26 |
$this->id_observation_en_cours = $_GET['id_observation'];
|
43 |
aurelien |
27 |
$this->setNavigation();
|
31 |
aurelien |
28 |
}
|
|
|
29 |
|
|
|
30 |
public function executerActionParDefaut() {
|
|
|
31 |
return $this->afficherFormulaireAjoutIndividu();
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
|
|
|
35 |
public function afficherFormulaireAjoutObservation($id_individu) {
|
|
|
36 |
$donnees = array();
|
|
|
37 |
$formulaire = $this->getVue('formulaires/observation_saisie',$donnees);
|
|
|
38 |
$this->setSortie(self::RENDU_CORPS, $formulaire);
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
public function afficherFormulaireModificationObservation() {
|
|
|
42 |
|
|
|
43 |
$id_individu_a_modifier_observation = $_GET['id_individu'];
|
|
|
44 |
|
|
|
45 |
$id_espece = $_GET['id_espece'];
|
|
|
46 |
$id_station = $_GET['id_station'];
|
|
|
47 |
|
|
|
48 |
$id_utilisateur = AppControleur::getUtilisateur()->getIdentifiantNumerique();
|
|
|
49 |
|
|
|
50 |
$espece = new Espece();
|
|
|
51 |
$evenements = $espece->getListeEvenementPourEspece($id_espece);
|
|
|
52 |
|
|
|
53 |
$station = new Station();
|
|
|
54 |
|
43 |
aurelien |
55 |
$individus = $station->getIndividusStationPourEspece($id_station,$id_espece);
|
31 |
aurelien |
56 |
foreach($individus as &$individu) {
|
|
|
57 |
|
|
|
58 |
$observation = new Observation();
|
44 |
aurelien |
59 |
$individu['observations'] = $observation->getListeObservationsPourIndividu($individu['id_individu']);
|
63 |
aurelien |
60 |
$individu['url'] = Liens::instance()->getUrlConsultationFicheIndividu($id_station,$id_espece, $individu['id_individu']);
|
44 |
aurelien |
61 |
|
31 |
aurelien |
62 |
}
|
44 |
aurelien |
63 |
|
31 |
aurelien |
64 |
$donnees['evenements'] = $evenements;
|
44 |
aurelien |
65 |
$donnees['stades'] = $this->aplatirListeEvenementHierachiseeEnListeParStades($evenements);
|
31 |
aurelien |
66 |
$donnees['individus'] = $individus;
|
|
|
67 |
$donnees['id_station'] = $_GET['id_station'];
|
|
|
68 |
$donnees['id_espece'] = $_GET['id_espece'];
|
44 |
aurelien |
69 |
|
|
|
70 |
if(isset($_GET['annee'])) {
|
|
|
71 |
$donnees['annee'] = $_GET['annee'];
|
|
|
72 |
} else {
|
|
|
73 |
$donnees['annee'] = date('Y');
|
|
|
74 |
}
|
|
|
75 |
|
31 |
aurelien |
76 |
$donnees['id_individu_a_modifier_observation'] = $id_individu_a_modifier_observation;
|
|
|
77 |
|
|
|
78 |
$this->setSortie(self::RENDU_CORPS, $this->getVue('formulaires/evenement_modification', $donnees));
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
// +---------------------------------------------------------------------------------------------------------------+
|
43 |
aurelien |
82 |
// METHODES POUR FABRIQUER LE MENU
|
|
|
83 |
public function setNavigation() {
|
|
|
84 |
|
|
|
85 |
$station = new Station();
|
|
|
86 |
$this->setSortie(self::RENDU_NAVIGATION, $station->construireMenuNavigation());
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
// +---------------------------------------------------------------------------------------------------------------+
|
31 |
aurelien |
90 |
// METHODES APPELEES LORS DE LA VALIDATION D'UN FORMULAIRE
|
|
|
91 |
public function validerFormulaireAjoutObservation() {
|
|
|
92 |
|
43 |
aurelien |
93 |
$valeurs_formulaires = $_POST;
|
31 |
aurelien |
94 |
|
|
|
95 |
$valeurs_verifiees = array();
|
|
|
96 |
|
|
|
97 |
$observation_dao = new ObservationDao();
|
|
|
98 |
$observation_dao->ajouterObservation($valeurs_verifiees);
|
44 |
aurelien |
99 |
|
31 |
aurelien |
100 |
}
|
|
|
101 |
|
|
|
102 |
public function validerFormulaireModificationObservation() {
|
44 |
aurelien |
103 |
|
|
|
104 |
$valeurs_verifiees = $this->collecterValeursFormulaireModificationObservation();
|
31 |
aurelien |
105 |
|
44 |
aurelien |
106 |
$observation_dao = new ObservationDao();
|
|
|
107 |
$observation_dao->modifierObservation($valeurs_verifiees['id_individu'], $valeurs_verifiees);
|
31 |
aurelien |
108 |
|
44 |
aurelien |
109 |
$individu = new Individu();
|
43 |
aurelien |
110 |
|
44 |
aurelien |
111 |
$this->setSortie(self::RENDU_CORPS, $individu->getListeIndividu());
|
31 |
aurelien |
112 |
|
44 |
aurelien |
113 |
}
|
|
|
114 |
|
63 |
aurelien |
115 |
public function validerFormulaireModificationObservationAjax() {
|
|
|
116 |
|
|
|
117 |
$valeurs_verifiees = $this->collecterValeursFormulaireModificationObservation();
|
|
|
118 |
|
|
|
119 |
$observation_dao = new ObservationDao();
|
|
|
120 |
$observation_dao->modifierObservation($valeurs_verifiees['id_individu'],$valeurs_verifiees);
|
|
|
121 |
|
|
|
122 |
$retour = array('reponse' => 'OK');
|
|
|
123 |
|
|
|
124 |
echo json_encode($retour);
|
|
|
125 |
exit;
|
|
|
126 |
}
|
|
|
127 |
|
44 |
aurelien |
128 |
private function collecterValeursFormulaireModificationObservation() {
|
|
|
129 |
|
|
|
130 |
$valeurs_verifiees = array();
|
|
|
131 |
|
|
|
132 |
foreach($_POST as $nom_champ => $valeur) {
|
|
|
133 |
|
|
|
134 |
$id_si_est_champ_observation = $this->renvoyerIdEvenementSiChampDeFormulaireObservation($nom_champ);
|
|
|
135 |
|
|
|
136 |
if($id_si_est_champ_observation && trim($valeur) != '') {
|
|
|
137 |
$valeurs_verifiees[$nom_champ] = $valeur;
|
|
|
138 |
}
|
|
|
139 |
}
|
|
|
140 |
|
|
|
141 |
$valeurs_verifiees['id_individu'] = $_POST['id_individu'];
|
|
|
142 |
$valeurs_verifiees['annee_en_cours'] = $_POST['annee_en_cours'];
|
|
|
143 |
|
|
|
144 |
//TODO: verifier valeurs plus complètement
|
|
|
145 |
|
|
|
146 |
return $valeurs_verifiees;
|
31 |
aurelien |
147 |
|
|
|
148 |
}
|
|
|
149 |
|
44 |
aurelien |
150 |
private function renvoyerIdEvenementSiChampDeFormulaireObservation($champ) {
|
|
|
151 |
|
|
|
152 |
$tab_champ = split('observation_',$champ);
|
|
|
153 |
|
|
|
154 |
if(count($tab_champ) > 1 && is_numeric($tab_champ[1])) {
|
|
|
155 |
return $tab_champ[1];
|
|
|
156 |
}
|
|
|
157 |
|
|
|
158 |
return false;
|
|
|
159 |
}
|
|
|
160 |
|
31 |
aurelien |
161 |
// +---------------------------------------------------------------------------------------------------------------+
|
|
|
162 |
// METHODES DE RECHERCHE DE DONNEES
|
|
|
163 |
public function getListeObservationsPourIndividu($id_individu, $annee = null) {
|
|
|
164 |
|
|
|
165 |
$observation_dao = new ObservationDao();
|
|
|
166 |
$observations_pour_individu = $observation_dao->getListeObservationsPourIndividu($id_individu, $annee);
|
|
|
167 |
|
|
|
168 |
return $observations_pour_individu;
|
|
|
169 |
}
|
44 |
aurelien |
170 |
|
|
|
171 |
|
|
|
172 |
private function aplatirListeEvenementHierachiseeEnListeParStades($liste_evenements_hierarchisee) {
|
|
|
173 |
|
|
|
174 |
$liste_evenements_plate_par_stade = array();
|
|
|
175 |
|
|
|
176 |
foreach($liste_evenements_hierarchisee as $evenement_hierarchise) {
|
|
|
177 |
foreach($evenement_hierarchise['stades'] as $id_stade => $stade) {
|
|
|
178 |
$liste_evenements_plate_par_stade[$id_stade] = $stade;
|
|
|
179 |
}
|
|
|
180 |
}
|
|
|
181 |
|
|
|
182 |
return $liste_evenements_plate_par_stade;
|
|
|
183 |
}
|
|
|
184 |
|
|
|
185 |
// +---------------------------------------------------------------------------------------------------------------+
|
|
|
186 |
// METHODES UTILITAIRES STATIQUES (UTILES POUR LES FORMULAIRES)
|
|
|
187 |
public static function individuAObservationValidePourStade($individu, $annee, $evenement, $id_stade) {
|
|
|
188 |
|
|
|
189 |
return (isset($individu['observations'][$annee][$evenement][$id_stade]) && trim($individu['observations'][$annee][$evenement][$id_stade]) != '');
|
|
|
190 |
}
|
|
|
191 |
|
|
|
192 |
public static function renvoyerObservationStadePourIndividu($individu, $annee, $evenement, $id_stade) {
|
|
|
193 |
|
|
|
194 |
if(self::individuAObservationValidePourStade($individu, $annee, $evenement, $id_stade)) {
|
|
|
195 |
return $individu['observations'][$annee][$evenement][$id_stade];
|
|
|
196 |
}
|
|
|
197 |
|
|
|
198 |
return '';
|
|
|
199 |
}
|
31 |
aurelien |
200 |
}
|