Subversion Repositories Sites.obs-saisons.fr

Rev

Rev 320 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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