Subversion Repositories Sites.obs-saisons.fr

Compare Revisions

Ignore whitespace Rev 319 → Rev 320

/trunk/applications/saisie/controleurs/Observation.php
12,193 → 12,177
* @version SVN: $Id: Fiche.php 152 2010-09-06 16:19:12Z jpm $
*/
class Observation extends aControleur {
 
private $id_observation_en_cours = null;
 
public function __construct() {
 
parent::__construct();
$this->initialiser();
}
 
public function initialiser() {
 
if(isset($_GET['$id_observation'])) {
$this->id_observation_en_cours = $_GET['id_observation'];
}
$this->setNavigation();
}
 
public function executerActionParDefaut() {
return $this->afficherFormulaireAjoutIndividu();
}
 
 
public function afficherFormulaireAjoutObservation($id_individu) {
$donnees = array();
$formulaire = $this->getVue('formulaires/observation_saisie',$donnees);
$this->setSortie(self::RENDU_CORPS, $formulaire);
$this->setSortie(self::RENDU_CORPS, $formulaire);
}
 
public function afficherFormulaireModificationObservation() {
 
$id_individu_a_modifier_observation = $_GET['id_individu'];
 
$id_espece = $_GET['id_espece'];
$id_station = $_GET['id_station'];
 
$id_utilisateur = AppControleur::getUtilisateur()->getIdentifiantNumerique();
 
$espece = new Espece();
$evenements = $espece->getListeEvenementPourEspece($id_espece);
 
$station = new Station();
 
$individus = $station->getIndividusStationPourEspece($id_station,$id_espece);
foreach($individus as &$individu) {
 
$observation = new Observation();
$individu['observations'] = $observation->getListeObservationsPourIndividu($individu['id_individu']);
$individu['url'] = Liens::getUrlConsultationFicheIndividu($id_station,$id_espece, $individu['id_individu']);
 
}
 
$donnees['evenements'] = $evenements;
$donnees['stades'] = $this->aplatirListeEvenementHierachiseeEnListeParStades($evenements);
$donnees['individus'] = $individus;
$donnees['id_station'] = $_GET['id_station'];
$donnees['id_espece'] = $_GET['id_espece'];
 
if(isset($_GET['annee'])) {
$donnees['annee'] = $_GET['annee'];
} else {
$donnees['annee'] = date('Y');
}
 
$donnees['id_individu_a_modifier_observation'] = $id_individu_a_modifier_observation;
 
$this->setSortie(self::RENDU_CORPS, $this->getVue('formulaires/evenement_modification', $donnees));
}
 
// +---------------------------------------------------------------------------------------------------------------+
// METHODES POUR FABRIQUER LE MENU
// METHODES POUR FABRIQUER LE MENU
public function setNavigation() {
 
$station = new Station();
$this->setSortie(self::RENDU_NAVIGATION, $station->construireMenuNavigation());
}
 
// +---------------------------------------------------------------------------------------------------------------+
// METHODES APPELEES LORS DE LA VALIDATION D'UN FORMULAIRE
public function validerFormulaireAjoutObservation() {
 
$valeurs_formulaires = $_POST;
 
$valeurs_verifiees = array();
 
$observation_dao = new ObservationDao();
$observation_dao->ajouterObservation($valeurs_verifiees);
 
}
 
public function validerFormulaireModificationObservation() {
 
$valeurs_verifiees = $this->collecterValeursFormulaireModificationObservation();
 
$observation_dao = new ObservationDao();
$observation_dao->modifierObservation($valeurs_verifiees['id_individu'], $valeurs_verifiees);
 
$individu = new Individu();
 
$this->setSortie(self::RENDU_CORPS, $individu->getListeIndividu());
 
}
 
public function validerFormulaireModificationObservationAjax() {
 
$valeurs_verifiees = $this->collecterValeursFormulaireModificationObservation();
 
$observation_dao = new ObservationDao();
$observation_dao->modifierObservation($valeurs_verifiees['id_individu'],$valeurs_verifiees);
$retour = array('reponse' => 'OK');
$data = $observation_dao->modifierObservation($valeurs_verifiees['id_individu'],$valeurs_verifiees);
 
$retour = array('reponse' => 'OK', 'data' => $data);
 
header('Content-type: text/json');
echo json_encode($retour);
exit;
}
 
private function collecterValeursFormulaireModificationObservation() {
$valeurs_verifiees = array();
foreach($_POST as $nom_champ => $valeur) {
$id_si_est_champ_observation = $this->renvoyerIdEvenementSiChampDeFormulaireObservation($nom_champ);
if($id_si_est_champ_observation && trim($valeur) != '') {
$valeurs_verifiees[$nom_champ] = $valeur;
}
}
 
$valeurs_verifiees = array();
 
$valeurs_verifiees['id_individu'] = $_POST['id_individu'];
$valeurs_verifiees['annee_en_cours'] = $_POST['annee_en_cours'];
//TODO: verifier valeurs plus complètement
 
$valeurs_verifiees['id_evenement'] = $_POST['id_evenement'];
$valeurs_verifiees['date_evenement'] = $_POST['date_evenement'];
 
if(!empty($_POST['id_observation'])) {
$valeurs_verifiees['id_observation'] = $_POST['id_observation'];
}
 
return $valeurs_verifiees;
}
private function renvoyerIdEvenementSiChampDeFormulaireObservation($champ) {
$tab_champ = explode('observation_',$champ);
if(count($tab_champ) > 1 && is_numeric($tab_champ[1])) {
return $tab_champ[1];
}
return false;
}
 
// +---------------------------------------------------------------------------------------------------------------+
// METHODES DE RECHERCHE DE DONNEES
// METHODES DE RECHERCHE DE DONNEES
public function getListeObservationsPourIndividu($id_individu, $annee = null) {
 
$observation_dao = new ObservationDao();
$observations_pour_individu = $observation_dao->getListeObservationsPourIndividu($id_individu, $annee);
 
return $observations_pour_individu;
}
 
 
private function aplatirListeEvenementHierachiseeEnListeParStades($liste_evenements_hierarchisee) {
 
$liste_evenements_plate_par_stade = array();
 
foreach($liste_evenements_hierarchisee as $evenement_hierarchise) {
foreach($evenement_hierarchise['stades'] as $id_stade => $stade) {
$liste_evenements_plate_par_stade[$id_stade] = $stade;
}
}
 
return $liste_evenements_plate_par_stade;
}
 
// +---------------------------------------------------------------------------------------------------------------+
// METHODES UTILITAIRES STATIQUES (UTILES POUR LES FORMULAIRES)
public static function individuAObservationValidePourStade($individu, $annee, $evenement, $id_stade) {
 
return (isset($individu['observations'][$annee][$evenement][$id_stade]) && trim($individu['observations'][$annee][$evenement][$id_stade]) != '');
}
 
public static function renvoyerObservationStadePourIndividu($individu, $annee, $evenement, $id_stade) {
 
if(self::individuAObservationValidePourStade($individu, $annee, $evenement, $id_stade)) {
return $individu['observations'][$annee][$evenement][$id_stade];
}
 
return '';
}
}
}
?>
?>