Subversion Repositories Sites.obs-saisons.fr

Rev

Rev 44 | Rev 70 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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