Subversion Repositories Applications.projet

Rev

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

Rev 370 Rev 374
1
<?php
1
<?php
2
/**
2
/**
3
* PHP Version 5
3
* PHP Version 5
4
*
4
*
5
* @category  PHP
5
* @category  PHP
6
* @package   projet_bp
6
* @package   projet_bp
7
* @author    aurelien <aurelien@tela-botanica.org>
7
* @author    aurelien <aurelien@tela-botanica.org>
8
* @copyright 2010 Tela-Botanica
8
* @copyright 2010 Tela-Botanica
9
* @license   http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
9
* @license   http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
10
* @version   SVN: <svn_id>
10
* @version   SVN: <svn_id>
11
* @link      /doc/projet_bp/
11
* @link      /doc/projet_bp/
12
*/
12
*/
13
 
13
 
14
class ProjetService extends JRestService {
14
class ProjetService extends JRestService {
15
	
15
	
16
	public function __construct($config, $demarrer_session= true) {
16
	public function __construct($config, $demarrer_session= true) {
17
		parent::__construct($config, $demarrer_session);
17
		parent::__construct($config, $demarrer_session);
18
	}
18
	}
19
 
19
 
20
	protected function obtenirProjetsPourParticipant($id_utilisateur) {
20
	protected function obtenirProjetsPourParticipant($id_utilisateur) {
21
 
21
 
22
		// on selectionne la liste des projets auxquel on est inscrit
22
		// on selectionne la liste des projets auxquel on est inscrit
23
		$requete_projets = 	'SELECT DISTINCT *'.
23
		$requete_projets = 	'SELECT DISTINCT *'.
24
						   	' FROM projet'.
24
						   	' FROM projet'.
25
						   	' WHERE p_id'.
25
						   	' WHERE p_id'.
26
							' IN '.
26
							' IN '.
27
							'(SELECT psu_id_projet FROM projet_statut_utilisateurs'.
27
							'(SELECT psu_id_projet FROM projet_statut_utilisateurs'.
28
							' WHERE psu_id_utilisateur = '.$id_utilisateur.')'.
28
							' WHERE psu_id_utilisateur = '.$id_utilisateur.')'.
29
							' GROUP BY p_id';
29
							' GROUP BY p_id';
30
 
30
 
31
		try {
31
		try {
32
			$projets = $this->bdd->query($requete_projets)->fetchAll(PDO::FETCH_ASSOC);
32
			$projets = $this->bdd->query($requete_projets)->fetchAll(PDO::FETCH_ASSOC);
33
		} catch (PDOException $e) {
33
		} catch (PDOException $e) {
34
			Log::getInstance()->ajouterEntree('projet','Fichier: '.$e->getFile().' Ligne: '.$e->getLine().' '.$e->getMessage());
34
			Log::getInstance()->ajouterEntree('projet','Fichier: '.$e->getFile().' Ligne: '.$e->getLine().' '.$e->getMessage());
35
			return array();
35
			return array();
36
		}
36
		}
37
 
37
 
38
		// pas de projets ? alors c'est fait !
38
		// pas de projets ? alors c'est fait !
39
		if(!$projets || count($projets) <= 0) {
39
		if(!$projets || count($projets) <= 0) {
40
			return array();
40
			return array();
41
		}
41
		}
42
 
42
 
43
		return $projets;
43
		return $projets;
44
	}
44
	}
45
	
45
	
46
	protected function obtenirInformationsProjet($id_projet) {
46
	protected function obtenirInformationsProjet($id_projet) {
47
		
47
		
48
		$requete_informations_projet = 'SELECT DISTINCT *'.
48
		$requete_informations_projet = 'SELECT DISTINCT *'.
49
						   	' FROM projet'.
49
						   	' FROM projet'.
50
						   	' WHERE p_id = '.$id_projet ;
50
						   	' WHERE p_id = '.$id_projet ;
51
		
51
		
52
		try {
52
		try {
53
			$projet = $this->bdd->query($requete_informations_projet)->fetchAll(PDO::FETCH_ASSOC);
53
			$projet = $this->bdd->query($requete_informations_projet)->fetchAll(PDO::FETCH_ASSOC);
54
		} catch (PDOException $e) {
54
		} catch (PDOException $e) {
55
			Log::getInstance()->ajouterEntree('projet','Fichier: '.$e->getFile().' Ligne: '.$e->getLine().' '.$e->getMessage());
55
			Log::getInstance()->ajouterEntree('projet','Fichier: '.$e->getFile().' Ligne: '.$e->getLine().' '.$e->getMessage());
56
			return false;
56
			return false;
57
		}
57
		}
58
 
58
 
59
		// pas de projets ? alors c'est fait !
59
		// pas de projets ? alors c'est fait !
60
		if(!$projet) {
60
		if(!$projet) {
61
			return false;
61
			return false;
62
		}
62
		}
63
 
63
 
64
		return $projet;
64
		return $projet;
65
	}
65
	}
66
 
66
 
67
	protected function obtenirListesAssocieesAuProjet($id_projet) {
67
	protected function obtenirListesAssocieesAuProjet($id_projet) {
68
 
68
 
69
		$requete_liste_projets = 'SELECT * FROM projet_liste '.
69
		$requete_liste_projets = 'SELECT * FROM projet_liste '.
70
								 'WHERE pl_id_liste IN '.
70
								 'WHERE pl_id_liste IN '.
71
								 '(SELECT pl_id_liste from projet_lien_liste '.
71
								 '(SELECT pl_id_liste from projet_lien_liste '.
72
								 		'WHERE pl_id_projet='.$id_projet.')' ;
72
								 		'WHERE pl_id_projet='.$id_projet.')' ;
73
 
73
 
74
		try {
74
		try {
75
			$listes_projets = $this->bdd->query($requete_liste_projets)->fetchAll(PDO::FETCH_ASSOC);
75
			$listes_projets = $this->bdd->query($requete_liste_projets)->fetchAll(PDO::FETCH_ASSOC);
76
		} catch (PDOException $e) {
76
		} catch (PDOException $e) {
77
			Log::getInstance()->ajouterEntree('projet','Fichier: '.$e->getFile().' Ligne: '.$e->getLine().' '.$e->getMessage());
77
			Log::getInstance()->ajouterEntree('projet','Fichier: '.$e->getFile().' Ligne: '.$e->getLine().' '.$e->getMessage());
78
			return array();
78
			return array();
79
		}
79
		}
80
 
80
 
81
 
81
 
82
		if(!$listes_projets || count($listes_projets) <= 0) {
82
		if(!$listes_projets || count($listes_projets) <= 0) {
83
			return array();
83
			return array();
84
		}
84
		}
85
 
85
 
86
		return $listes_projets;
86
		return $listes_projets;
87
	}
87
	}
88
	
88
	
89
	protected function supprimerInscriptionAListeProjet($id_utilisateur, $id_liste) {
89
	protected function supprimerInscriptionAListeProjet($id_utilisateur, $id_liste) {
90
	
90
	
91
		$requete_suppression_liste = 'DELETE FROM projet_inscription_liste '.
91
		$requete_suppression_liste = 'DELETE FROM projet_inscription_liste '.
92
											   'WHERE pil_id_utilisateur='.$id_utilisateur.' and pil_id_liste='.$id_liste ;
92
											   'WHERE pil_id_utilisateur='.$id_utilisateur.' and pil_id_liste='.$id_liste ;
93
 
93
 
94
		try {
94
		try {
95
			$requete_suppression_liste = $this->bdd->query($requete_suppression_liste);
95
			$requete_suppression_liste = $this->bdd->query($requete_suppression_liste);
96
		} catch (PDOException $e) {
96
		} catch (PDOException $e) {
97
			Log::getInstance()->ajouterEntree('projet','Fichier: '.$e->getFile().' Ligne: '.$e->getLine().' '.$e->getMessage().' '.$requete_suppression_liste);
97
			Log::getInstance()->ajouterEntree('projet','Fichier: '.$e->getFile().' Ligne: '.$e->getLine().' '.$e->getMessage().' '.$requete_suppression_liste);
98
			return false;
98
			return false;
99
		}
99
		}
100
	
100
	
101
	}
101
	}
102
 
102
 
103
	protected function supprimerParticipantAProjet($id_utilisateur, $id_projet) {
103
	protected function supprimerParticipantAProjet($id_utilisateur, $id_projet) {
104
		$requete_suppression_projets = 'DELETE FROM projet_statut_utilisateurs '.
104
		$requete_suppression_projets = 'DELETE FROM projet_statut_utilisateurs '.
105
											   'WHERE psu_id_utilisateur='.$id_utilisateur.' and psu_id_projet='.$id_projet ;
105
											   'WHERE psu_id_utilisateur='.$id_utilisateur.' and psu_id_projet='.$id_projet ;
106
 
106
 
107
		try {
107
		try {
108
			$requete_suppression_projets = $this->bdd->query($requete_suppression_projets);
108
			$requete_suppression_projets = $this->bdd->query($requete_suppression_projets);
109
		} catch (PDOException $e) {
109
		} catch (PDOException $e) {
110
			Log::getInstance()->ajouterEntree('projet','Fichier: '.$e->getFile().' Ligne: '.$e->getLine().' '.$e->getMessage().' '.$requete_suppression_projets);
110
			Log::getInstance()->ajouterEntree('projet','Fichier: '.$e->getFile().' Ligne: '.$e->getLine().' '.$e->getMessage().' '.$requete_suppression_projets);
111
			return false;
111
			return false;
112
		}
112
		}
113
		
113
		
114
		return true;
114
		return true;
115
	}
115
	}
116
 
116
 
117
	protected function estAbonneAListe($nom_liste, $mail) {
117
	protected function estAbonneAListe($nom_liste, $mail) {
118
 
118
 
119
		try {
119
		try {
120
			$est_abonne = '0' ;
120
			$est_abonne = '0' ;
-
 
121
			// TODO: externaliser l'adresse
121
			$xml_abonne = new SimpleXMLElement(file_get_contents('http://vpopmail.tela-botanica.org/est_abonne.php?domaine=tela-botanica.org&liste='.$nom_liste.'&mail='.$mail)) ;
122
			$xml_abonne = new SimpleXMLElement(file_get_contents('http://vpopmail.tela-botanica.org/est_abonne.php?domaine=tela-botanica.org&liste='.$nom_liste.'&mail='.$mail)) ;
122
			$est_abonne = $xml_abonne[0] ;
123
			$est_abonne = $xml_abonne[0] ;
123
 
124
 
124
			if($est_abonne == '1') {
125
			if($est_abonne == '1') {
125
				return true;
126
				return true;
126
			} else {
127
			} else {
127
				return false;
128
				return false;
128
			}
129
			}
129
		}
130
		}
130
		catch(Exception $e) {
131
		catch(Exception $e) {
131
			trigger_error($e->getMessage()) ;
132
			trigger_error($e->getMessage()) ;
132
			return false;
133
			return false;
133
		}
134
		}
134
 
135
 
135
	}
136
	}
136
 
137
 
137
	protected function modifierMailPourListe($nom_liste, $ancien_mail, $nouveau_mail) {
138
	protected function modifierMailPourListe($nom_liste, $ancien_mail, $nouveau_mail) {
138
		return ($this->desinscriptionListe($nom_liste, $ancien_mail) && $this->inscriptionListe($nom_liste, $nouveau_mail));
139
		return ($this->desinscriptionListe($nom_liste, $ancien_mail) && $this->inscriptionListe($nom_liste, $nouveau_mail));
139
	}
140
	}
140
 
141
 
141
	protected function inscriptionListe($nom_liste, $mail) {
142
	protected function inscriptionListe($nom_liste, $mail) {
-
 
143
		// TODO: externaliser l'adresse
142
		return $inscription_abonne = file_get_contents('http://vpopmail.tela-botanica.org/ajout_abonne.php?domaine=tela-botanica.org&liste='.$nom_liste.'&mail='.$mail) ;
144
		return $inscription_abonne = file_get_contents('http://vpopmail.tela-botanica.org/ajout_abonne.php?domaine=tela-botanica.org&liste='.$nom_liste.'&mail='.$mail) ;
143
	}
145
	}
144
 
146
 
145
	protected function desinscriptionListe($nom_liste, $mail) {
147
	protected function desinscriptionListe($nom_liste, $mail) {
-
 
148
		// TODO: externaliser l'adresse
146
		return $suppression_abonne = file_get_contents('http://vpopmail.tela-botanica.org/suppression_abonne.php?domaine=tela-botanica.org&liste='.$nom_liste.'&mail='.$mail) ;
149
		return $suppression_abonne = file_get_contents('http://vpopmail.tela-botanica.org/suppression_abonne.php?domaine=tela-botanica.org&liste='.$nom_liste.'&mail='.$mail) ;
147
	}
150
	}
148
}
151
}
149
?>
152
?>