Subversion Repositories Applications.projet

Rev

Rev 11 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 ddelon 1
<?php
2
// +------------------------------------------------------------------------------------------------------+
3
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org)                                         |
4
// +------------------------------------------------------------------------------------------------------+
5
// | This library is free software; you can redistribute it and/or                                        |
6
// | modify it under the terms of the GNU General Public                                                  |
7
// | License as published by the Free Software Foundation; either                                         |
8
// | version 2.1 of the License, or (at your option) any later version.                                   |
9
// |                                                                                                      |
10
// | This library is distributed in the hope that it will be useful,                                      |
11
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                                       |
12
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                                    |
13
// | General Public License for more details.                                                             |
14
// |                                                                                                      |
15
// | You should have received a copy of the GNU General Public                                            |
16
// | License along with this library; if not, write to the Free Software                                  |
17
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                            |
18
// +------------------------------------------------------------------------------------------------------+
19
// CVS : $Id: participe.class.php,v 1.1 2005-09-22 14:02:47 ddelon Exp $
20
/**
21
* Application projet
22
*
23
* La classe partiicpe assure la jointure entre projet et Auth
24
* Elle se base sur la table projet_statut_utilisateur
25
*
26
*@package projet
27
//Auteur original :
28
*@author        Alexandre Granier <alexandre@tela-botanica.org>
29
//Autres auteurs :
30
*@author        Aucun
31
*@copyright     Tela-Botanica 2000-2004
32
*@version       $Revision: 1.1 $
33
// +------------------------------------------------------------------------------------------------------+
34
*/
35
 
36
 
37
// +------------------------------------------------------------------------------------------------------+
38
// |                                            ENTETE du PROGRAMME                                       |
39
// +------------------------------------------------------------------------------------------------------+
40
 
41
 
42
/**
43
 * class participe
44
 *
45
 */
46
class participe
47
{
48
    /*** Attributes: ***/
49
 
50
    /**
51
     * Date d'inscription au projet de l'utilisateur.
52
     * @access private
53
     */
54
    var $_date_inscription;
55
    /**
56
     * Statut de l'utilisateur, un entier.
57
     * @access private
58
     */
59
    var $_statut;
60
    /**
61
     * Connexion à la base de donnée.
62
     * @access private
63
     */
64
    var $_db;
65
 
66
    /**
67
     * Constructeur. Nécessite un objet DB valide connecté à la base contenant les
68
     * tables projets.
69
     *
70
     * @param DB objetDB Un objet PEAR:DB valide.
71
     * @return void
72
     * @access public
73
     */
74
    function participe( &$objetDB )
75
    {
76
        $this->_db = $objetDB ;
77
    } // end of member function participe
78
 
79
    /**
80
     * Renvoie la liste des inscrit à un projet avec leur statut.
81
     *
82
     * @return Array
83
     * @access public
84
     */
85
    function getInscrits($id_projet, $droits )
86
    {
87
        $tableau_resultat = array() ;
88
 
89
        $requete = 'select psu_id_utilisateur,'.PROJET_CHAMPS_NOM.','.PROJET_CHAMPS_PRENOM.',' ;
90
        $requete .= PROJET_CHAMPS_MAIL.', ' ;
91
        $requete .= 'psu_date_inscription,  ps_id_statut '.
92
                    ' from projet_statut_utilisateurs, projet_statut,'.PROJET_ANNUAIRE.
93
                    ' where psu_id_projet='.$id_projet.' and psu_id_utilisateur='.PROJET_CHAMPS_ID.
94
                    ' and psu_id_statut=ps_id_statut order by ps_id_statut,'.PROJET_CHAMPS_NOM;
95
        $resultat = $this->_db->query ($requete) ;
96
        if (DB::isError($resultat)) {
97
            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
98
        }
99
        while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ORDERED)) {
100
            array_push ($tableau_resultat, $ligne) ;
101
        }
102
        $resultat->free() ;
103
        return $tableau_resultat ;
104
    } // end of member function getInscrits
105
 
106
    /**
107
     * Renvoie un tableau contenant la liste des identifiants des projets et des statuts
108
     * d'un inscrit. 0 => ['psu_id_utilisateur']          ['psu_id_statut'] 1 => ...
109
     *
110
     * @param int id_utilisateur Un identifiant d'utilisateur pour le champs
111
     * projet_statut_utilisateurs:psu_id_utilisateur
112
     * @return Array
113
     * @access public
114
     */
115
    function getIdProjetsStatuts( $id_utilisateur )
116
    {
117
        $tableau_resultat = array() ;
118
        $requete = "select psu_id_utilisateur, psu_id_statut from projet_statut_utilisateurs".
119
                    " where psu_id_utilisateur=".$id_utilisateur ;
120
        $resultat = $this->_db->query ($requete) ;
121
        if (DB::isError($resultat)) {
122
            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
123
        }
124
        while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
125
            array_push ($tableau_resultat, $ligne) ;
126
        }
127
        $resultat->free() ;
128
        return $tableau_resultat ;
129
    } // end of member function getIdProjetsStatuts
130
 
131
 
132
    /**
133
     * Renvoie un tableau à 2 dimensions avec les informations sur l'inscription aux
134
     * différents projets d'un utilisateur. 0 => ['p_titre']         Le titre du projet
135
     *         ['ps_label']    Le statut de l'utilisateur 1 => .... (autant que de
136
     * projets)
137
     *
138
     * @param int id_utilisateur L'identifiant d'un utilisateur.
139
     * @return Array
140
     * @access public
141
     */
142
    function getInformationsUtilisateurs( $id_utilisateur )
143
    {
144
        $tableau_resultat = array() ;
145
        $requete = "select p_titre, ps_statut_nom, psu_id_statut, psu_id_projet from projet_statut_utilisateurs, projet, projet_statut".
146
                    " where psu_id_utilisateur=".$id_utilisateur.
147
                    " and psu_id_projet = p_id and psu_id_statut = ps_id_statut" ;
148
        $resultat = $this->_db->query ($requete) ;
149
        if (DB::isError($resultat)) {
150
            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
151
        }
152
        while ($ligne = $resultat->fetchRow()) {
153
            array_push ($tableau_resultat, $ligne) ;
154
        }
155
        $resultat->free() ;
156
        return $tableau_resultat ;
157
    } // end of member function getInformationsUtilisateurs
158
 
159
 
160
    /**
161
     * Renvoie le statut du projet passé en paramètre.
162
     *
163
     * @param int id_utilisateur
164
     * @param int id_projet
165
     * @param int dbObject
166
     * @return int
167
     * @static
168
     * @access public
169
     */
170
    function getStatutSurProjetCourant( $id_utilisateur,  $id_projet,  &$dbObject )
171
    {
172
        $requete = 'select psu_id_statut from projet_statut_utilisateurs'.
173
                    ' where psu_id_utilisateur="'.$id_utilisateur.'" and psu_id_projet ='.$id_projet ;
174
        $resultat = $dbObject->query ($requete) ;
175
        if (DB::isError ($resultat)) {
176
            echo ('Echec de la requete : '.$requete.'<br />'.$resultat->getMessage()) ;
177
        }
178
        $ligne = $resultat->fetchRow(DB_FETCHMODE_OBJECT) ;
179
        if (!$resultat->numRows()) {
180
            return 4 ;      // Le statut ne participe pas
181
        }
182
        return $ligne->psu_id_statut ;
183
    } // end of member function getStatutSurProjetCourant
184
 
185
    /**
186
     * Réalise une requête dans projet_statut_utilisateurs et renvoie true si l'utilisateur
187
     * est administrateur de l'application projet.
188
     *
189
     * @param int id_utilisateur L'identifiant d'un utilisateur.
190
     * @param DB objetDB Un objet PEAR::DB
191
     * @return bool
192
     * @access public
193
     */
194
    function isAdministrateur( $id_utilisateur, $objetDB = "" )
195
    {
196
    	//$id_utilisateur=0;
197
        // La table projet_statut_utilisateurs possède une entré avec psu_id_projet = 0
198
        // pour indiquer un administrateur
199
        $requete = "select psu_id_statut from projet_statut_utilisateurs where psu_id_utilisateur=$id_utilisateur".
200
                    " and psu_id_projet=0" ;
201
        if ($objetDB != "") {
202
            $resultat = $objetDB->query ($requete) ;
203
        } else {
204
            $resultat = $this->_db->query ($requete) ;
205
        }
206
        if (DB::isError ($resultat)) {
207
            die ('Echec de la requete : '.$requete.'<br />'.$resultat->getMessage()) ;
208
        }
209
        if ($resultat->numRows () != 0) {
210
            return true;
211
        }
212
        return false ;
213
    } // end of member function isAdministrateur
214
 
215
    /**
216
     * Met à jour le statut d'un utilisateur sur un projet
217
     *
218
     * @param int id_statut L'identifiant du statut à ajouter ou mettre à jour
219
     * @param int id_utilisateur Identifiant de l'utilisateur
220
     * @param int id_projet Identifiant du projet
221
     * @return bool
222
     * @access public
223
     */
224
    function setStatut( $id_statut,  $id_utilisateur,  $id_projet )
225
    {
226
        $requete = 'update projet_statut_utilisateurs set psu_id_statut='.$id_statut.
227
                    ' where psu_id_utilisateur='.$id_utilisateur.' and psu_id_projet='.$id_projet;
228
 
229
        if (participe::getStatutSurProjetCourant($id_utilisateur, $id_projet, $this->_db) == 4) {
230
            $requete = 'insert into projet_statut_utilisateurs set psu_id_statut='.$id_statut.
231
                    ', psu_id_utilisateur='.$id_utilisateur.',psu_id_projet='.$id_projet.
232
                    ', psu_date_inscription=NOW()';
233
        }
234
        if ($id_statut == 4) {  // Si le statut est ne participe pas, on supprime l'inscrit
235
            $requete = 'delete from projet_statut_utilisateurs where psu_id_utilisateur='.$id_utilisateur.' and psu_id_projet='.$id_projet ;
236
        }
237
        $resultat = $this->_db->query ($requete) ;
238
        if (DB::isError ($resultat)) {
239
            die ('Echec de la requete : '.$requete.'<br />'.$resultat->getMessage()) ;
240
        }
241
        return true ;
242
    } // end of member function setStatut
243
 
244
    /**
245
     * Renvoie vrai si l'utilisateur est coordinateur, faux dans les autres cas
246
     *
247
     * @param int id_utilisateur L'identifiant d'un utilisateur
248
     * @param DB objetDB Optionnel, nécessaire si on appelle cette méthode statiquement
249
     * @return bool
250
     * @static
251
     * @access public
252
     */
253
    function isCoordinateur( $id_utilisateur, $id_projet, &$objetDB )
254
    {
255
        $statut = $this->getStatutSurProjetCourant($id_utilisateur,  $id_projet, $objetDB) ;
256
        if ($statut == 1) {
257
            return true;
258
        }
259
        return false ;
260
    } // end of member function isCoordinateur
261
 
262
    /**
263
     * Renvoie la liste des projets auquels l'utilisateur passé en paramètre ne
264
     * participe pas.
265
     *
266
     * @param int id_utilisateur L'identifiant de l'utilisateur.
267
     * @return Array
268
     * @access public
269
     */
270
    function getProjetsNonParticipant( $id_utilisateur )
271
    {
272
        $tableau_resultat = array() ;
273
        $requete = 'select p_id from projet'.
274
                    ' where p_id not in (select psu_id_projet from projet_statut_utilisateurs where psu_id_utilisateur="'.$id_utilisateur.'")' ;
275
        $resultat = $this->_db->query ($requete) ;
276
        if (DB::isError($resultat)) {
277
            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
278
        }
279
        while ($ligne = $resultat->fetchRow(DB_FETCHMODE_OBJECT)) {
280
            array_push ($tableau_resultat, new projet ($this->_db, $ligne->p_id)) ;
281
        }
282
        $resultat->free() ;
283
        return $tableau_resultat ;
284
    } // end of member function getProjetsNonParticipant
285
 
286
    /**
287
     * Renvoie true si l'utilisateur passé en paramètre est observateur du projet passé
288
     * en paramètre.
289
     *
290
     * @param int id_utilisateur L'identifiant de l'utilisateur
291
     * @param int id_projet L'identifiant du projet
292
     * @return bool
293
     * @access public
294
     */
295
    function isObservateur( $id_utilisateur,  $id_projet, &$objetDB )
296
    {
297
        if ($this->getStatutSurProjetCourant($id_utilisateur, $id_projet, $objetDB) == 3) {
298
            return true;
299
        }
300
        return false ;
301
    } // end of member function isObservateur
302
 
303
    /**
304
     * Renvoie true si l'utilisateur passé en paramètre est contributeur du projet passé
305
     * en paramètre.
306
     *
307
     * @param int id_utilisateur L'identifiant de l'utilisateur
308
     * @param int id_projet L'identifiant du projet
309
     * @return bool
310
     * @access public
311
     */
312
    function isContributeur( $id_utilisateur,  $id_projet, &$objetDB )
313
    {
314
        if ($this->getStatutSurProjetCourant($id_utilisateur, $id_projet, $objetDB) == 4) return false;
315
        if ($this->getStatutSurProjetCourant($id_utilisateur, $id_projet, $objetDB) == 2) {
316
            return true;
317
        }
318
        return false ;
319
    } // end of member function isObservateur
320
 
321
 
322
 
323
 
324
} // end of participe
325
?>