Subversion Repositories Applications.projet

Rev

Rev 399 | Details | Compare with Previous | Last modification | View Log | RSS feed

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