Subversion Repositories Applications.papyrus

Rev

Rev 448 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
448 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
// +------------------------------------------------------------------------------------------------------+
474 alexandre_ 19
// CVS : $Id: participe.class.php,v 1.2 2005-09-27 16:42:00 alexandre_tb Exp $
448 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
474 alexandre_ 32
*@version       $Revision: 1.2 $
448 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()) ;
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
        // La table projet_statut_utilisateurs possède une entré avec psu_id_projet = 0
197
        // pour indiquer un administrateur
198
        $requete = "select psu_id_statut from projet_statut_utilisateurs where psu_id_utilisateur=$id_utilisateur".
199
                    " and psu_id_projet=0" ;
200
        if ($objetDB != "") {
201
            $resultat = $objetDB->query ($requete) ;
202
        } else {
203
            $resultat = $this->_db->query ($requete) ;
204
        }
205
        if ($resultat->numRows () != 0) {
206
            return true;
207
        }
208
        return false ;
209
    } // end of member function isAdministrateur
210
 
211
    /**
212
     * Met à jour le statut d'un utilisateur sur un projet
213
     *
214
     * @param int id_statut L'identifiant du statut à ajouter ou mettre à jour
215
     * @param int id_utilisateur Identifiant de l'utilisateur
216
     * @param int id_projet Identifiant du projet
217
     * @return bool
218
     * @access public
219
     */
220
    function setStatut( $id_statut,  $id_utilisateur,  $id_projet )
221
    {
222
        $requete = 'update projet_statut_utilisateurs set psu_id_statut='.$id_statut.
223
                    ' where psu_id_utilisateur='.$id_utilisateur.' and psu_id_projet='.$id_projet;
224
 
225
        if (participe::getStatutSurProjetCourant($id_utilisateur, $id_projet, $this->_db) == 4) {
226
            $requete = 'insert into projet_statut_utilisateurs set psu_id_statut='.$id_statut.
227
                    ', psu_id_utilisateur='.$id_utilisateur.',psu_id_projet='.$id_projet.
228
                    ', psu_date_inscription=NOW()';
229
        }
230
        if ($id_statut == 4) {  // Si le statut est ne participe pas, on supprime l'inscrit
231
            $requete = 'delete from projet_statut_utilisateurs where psu_id_utilisateur='.$id_utilisateur.' and psu_id_projet='.$id_projet ;
232
        }
233
        $resultat = $this->_db->query ($requete) ;
234
        if (DB::isError ($resultat)) {
235
            die ('Echec de la requete : '.$requete.'<br />'.$resultat->getMessage()) ;
236
        }
237
        return true ;
238
    } // end of member function setStatut
239
 
240
    /**
241
     * Renvoie vrai si l'utilisateur est coordinateur, faux dans les autres cas
242
     *
243
     * @param int id_utilisateur L'identifiant d'un utilisateur
244
     * @param DB objetDB Optionnel, nécessaire si on appelle cette méthode statiquement
245
     * @return bool
246
     * @static
247
     * @access public
248
     */
249
    function isCoordinateur( $id_utilisateur, $id_projet, &$objetDB )
250
    {
251
        $statut = $this->getStatutSurProjetCourant($id_utilisateur,  $id_projet, $objetDB) ;
252
        if ($statut == 1) {
253
            return true;
254
        }
255
        return false ;
256
    } // end of member function isCoordinateur
257
 
258
    /**
259
     * Renvoie la liste des projets auquels l'utilisateur passé en paramètre ne
260
     * participe pas.
261
     *
262
     * @param int id_utilisateur L'identifiant de l'utilisateur.
263
     * @return Array
264
     * @access public
265
     */
266
    function getProjetsNonParticipant( $id_utilisateur )
267
    {
268
        $tableau_resultat = array() ;
269
        $requete = 'select p_id from projet'.
270
                    ' where p_id not in (select psu_id_projet from projet_statut_utilisateurs where psu_id_utilisateur="'.$id_utilisateur.'")' ;
271
        $resultat = $this->_db->query ($requete) ;
272
        if (DB::isError($resultat)) {
273
            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
274
        }
275
        while ($ligne = $resultat->fetchRow(DB_FETCHMODE_OBJECT)) {
276
            array_push ($tableau_resultat, new projet ($this->_db, $ligne->p_id)) ;
277
        }
278
        $resultat->free() ;
279
        return $tableau_resultat ;
280
    } // end of member function getProjetsNonParticipant
281
 
282
    /**
283
     * Renvoie true si l'utilisateur passé en paramètre est observateur du projet passé
284
     * en paramètre.
285
     *
286
     * @param int id_utilisateur L'identifiant de l'utilisateur
287
     * @param int id_projet L'identifiant du projet
288
     * @return bool
289
     * @access public
290
     */
291
    function isObservateur( $id_utilisateur,  $id_projet, &$objetDB )
292
    {
293
        if ($this->getStatutSurProjetCourant($id_utilisateur, $id_projet, $objetDB) == 3) {
294
            return true;
295
        }
296
        return false ;
297
    } // end of member function isObservateur
298
 
299
    /**
300
     * Renvoie true si l'utilisateur passé en paramètre est contributeur du projet passé
301
     * en paramètre.
302
     *
303
     * @param int id_utilisateur L'identifiant de l'utilisateur
304
     * @param int id_projet L'identifiant du projet
305
     * @return bool
306
     * @access public
307
     */
308
    function isContributeur( $id_utilisateur,  $id_projet, &$objetDB )
309
    {
310
        if ($this->getStatutSurProjetCourant($id_utilisateur, $id_projet, $objetDB) == 4) return false;
311
        if ($this->getStatutSurProjetCourant($id_utilisateur, $id_projet, $objetDB) == 2) {
312
            return true;
313
        }
314
        return false ;
315
    } // end of member function isObservateur
316
 
317
 
318
 
319
 
320
} // end of participe
321
?>