Subversion Repositories Applications.projet

Rev

Rev 263 | Details | Compare with Previous | 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
// +------------------------------------------------------------------------------------------------------+
260 alexandre_ 19
// CVS : $Id: participe.class.php,v 1.5 2007-10-10 13:56:23 alexandre_tb Exp $
2 ddelon 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
260 alexandre_ 32
*@version       $Revision: 1.5 $
2 ddelon 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()) ;
260 alexandre_ 177
            return;
2 ddelon 178
        }
179
        $ligne = $resultat->fetchRow(DB_FETCHMODE_OBJECT) ;
180
        if (!$resultat->numRows()) {
181
            return 4 ;      // Le statut ne participe pas
182
        }
183
        return $ligne->psu_id_statut ;
184
    } // end of member function getStatutSurProjetCourant
185
 
186
    /**
187
     * Réalise une requête dans projet_statut_utilisateurs et renvoie true si l'utilisateur
188
     * est administrateur de l'application projet.
189
     *
190
     * @param int id_utilisateur L'identifiant d'un utilisateur.
191
     * @param DB objetDB Un objet PEAR::DB
192
     * @return bool
193
     * @access public
194
     */
195
    function isAdministrateur( $id_utilisateur, $objetDB = "" )
196
    {
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" ;
203 alexandre_ 201
 
202
        if (is_object ($objetDB)) {
2 ddelon 203
            $resultat = $objetDB->query ($requete) ;
204
        } else {
205
            $resultat = $this->_db->query ($requete) ;
206
        }
207
        if ($resultat->numRows () != 0) {
208
            return true;
209
        }
210
        return false ;
211
    } // end of member function isAdministrateur
212
 
213
    /**
214
     * Met à jour le statut d'un utilisateur sur un projet
215
     *
216
     * @param int id_statut L'identifiant du statut à ajouter ou mettre à jour
217
     * @param int id_utilisateur Identifiant de l'utilisateur
218
     * @param int id_projet Identifiant du projet
219
     * @return bool
220
     * @access public
221
     */
222
    function setStatut( $id_statut,  $id_utilisateur,  $id_projet )
223
    {
224
        $requete = 'update projet_statut_utilisateurs set psu_id_statut='.$id_statut.
225
                    ' where psu_id_utilisateur='.$id_utilisateur.' and psu_id_projet='.$id_projet;
226
 
227
        if (participe::getStatutSurProjetCourant($id_utilisateur, $id_projet, $this->_db) == 4) {
228
            $requete = 'insert into projet_statut_utilisateurs set psu_id_statut='.$id_statut.
229
                    ', psu_id_utilisateur='.$id_utilisateur.',psu_id_projet='.$id_projet.
230
                    ', psu_date_inscription=NOW()';
231
        }
232
        if ($id_statut == 4) {  // Si le statut est ne participe pas, on supprime l'inscrit
233
            $requete = 'delete from projet_statut_utilisateurs where psu_id_utilisateur='.$id_utilisateur.' and psu_id_projet='.$id_projet ;
234
        }
235
        $resultat = $this->_db->query ($requete) ;
236
        if (DB::isError ($resultat)) {
237
            die ('Echec de la requete : '.$requete.'<br />'.$resultat->getMessage()) ;
238
        }
239
        return true ;
240
    } // end of member function setStatut
241
 
242
    /**
243
     * Renvoie vrai si l'utilisateur est coordinateur, faux dans les autres cas
244
     *
245
     * @param int id_utilisateur L'identifiant d'un utilisateur
246
     * @param DB objetDB Optionnel, nécessaire si on appelle cette méthode statiquement
247
     * @return bool
248
     * @static
249
     * @access public
250
     */
251
    function isCoordinateur( $id_utilisateur, $id_projet, &$objetDB )
252
    {
260 alexandre_ 253
        if (!is_object($objetDB)) $objetDB = $this->_db;
2 ddelon 254
        $statut = $this->getStatutSurProjetCourant($id_utilisateur,  $id_projet, $objetDB) ;
255
        if ($statut == 1) {
256
            return true;
257
        }
258
        return false ;
259
    } // end of member function isCoordinateur
260
 
261
    /**
262
     * Renvoie la liste des projets auquels l'utilisateur passé en paramètre ne
263
     * participe pas.
264
     *
265
     * @param int id_utilisateur L'identifiant de l'utilisateur.
266
     * @return Array
267
     * @access public
268
     */
269
    function getProjetsNonParticipant( $id_utilisateur )
270
    {
271
        $tableau_resultat = array() ;
272
        $requete = 'select p_id from projet'.
273
                    ' where p_id not in (select psu_id_projet from projet_statut_utilisateurs where psu_id_utilisateur="'.$id_utilisateur.'")' ;
274
        $resultat = $this->_db->query ($requete) ;
275
        if (DB::isError($resultat)) {
276
            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
277
        }
278
        while ($ligne = $resultat->fetchRow(DB_FETCHMODE_OBJECT)) {
279
            array_push ($tableau_resultat, new projet ($this->_db, $ligne->p_id)) ;
280
        }
281
        $resultat->free() ;
282
        return $tableau_resultat ;
283
    } // end of member function getProjetsNonParticipant
284
 
285
    /**
286
     * Renvoie true si l'utilisateur passé en paramètre est observateur du projet passé
287
     * en paramètre.
288
     *
289
     * @param int id_utilisateur L'identifiant de l'utilisateur
290
     * @param int id_projet L'identifiant du projet
291
     * @return bool
292
     * @access public
293
     */
294
    function isObservateur( $id_utilisateur,  $id_projet, &$objetDB )
295
    {
260 alexandre_ 296
        if (!is_object($objetDB)) $objetDB = $this->_db;
2 ddelon 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
    {
260 alexandre_ 314
        if (!is_object($objetDB)) $objetDB = $this->_db;
2 ddelon 315
        if ($this->getStatutSurProjetCourant($id_utilisateur, $id_projet, $objetDB) == 4) return false;
316
        if ($this->getStatutSurProjetCourant($id_utilisateur, $id_projet, $objetDB) == 2) {
317
            return true;
318
        }
319
        return false ;
320
    } // end of member function isObservateur
321
 
120 alexandre_ 322
    /**
323
     * Renvoie true si l'utilisateur passé en paramètre est contributeur du projet passé
324
     * en paramètre.
325
     *
326
     * @param int id_utilisateur L'identifiant de l'utilisateur
327
     * @param int id_projet L'identifiant du projet
328
     * @return bool
329
     * @access public
330
     */
331
    function isEnAttente( $id_utilisateur,  $id_projet, &$objetDB )
332
    {
333
        if ($this->getStatutSurProjetCourant($id_utilisateur, $id_projet, $objetDB) == 3) {
334
            return true;
335
        }
336
        return false ;
337
    } // end of member function isObservateur
2 ddelon 338
 
120 alexandre_ 339
	/**
340
     * Renvoie les infos sur les coordinateurs d'un projet
341
     *
342
     * @param int id_projet L'identifiant du projet
343
     * @return array	Un tableau contenant les infos concernants les coordinateurs du projet
344
     * @access public
345
     */
346
    function getCoordinateurs($id_projet)
347
    {
348
        $tableau_resultat = array() ;
349
 
350
        $requete = 'select psu_id_utilisateur,'.PROJET_CHAMPS_NOM.','.PROJET_CHAMPS_PRENOM.',' ;
351
        $requete .= PROJET_CHAMPS_MAIL.', ' ;
352
        $requete .= 'psu_date_inscription,  ps_id_statut '.
353
                    ' from projet_statut_utilisateurs, projet_statut,'.PROJET_ANNUAIRE.
354
                    ' where psu_id_projet='.$id_projet.' and psu_id_utilisateur='.PROJET_CHAMPS_ID.
355
                    ' and psu_id_statut=ps_id_statut and psu_id_statut=1 order by ps_id_statut,'.PROJET_CHAMPS_NOM;
356
        $resultat = $this->_db->query ($requete) ;
357
        if (DB::isError($resultat)) {
358
            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
359
        }
360
        while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ORDERED)) {
361
            array_push ($tableau_resultat, $ligne) ;
362
        }
363
        $resultat->free() ;
364
        return $tableau_resultat ;
365
    } // end of member function getCoordinateurs
2 ddelon 366
} // end of participe
367
?>