Subversion Repositories Applications.projet

Rev

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

Rev Author Line No. Line
2 ddelon 1
<?php
2
/*vim: set expandtab tabstop=4 shiftwidth=4: */
3
// +------------------------------------------------------------------------------------------------------+
4
// | PHP version 4.1                                                                                      |
5
// +------------------------------------------------------------------------------------------------------+
6
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org)                                         |
7
// +------------------------------------------------------------------------------------------------------+
8
// | This library is free software; you can redistribute it and/or                                        |
9
// | modify it under the terms of the GNU General Public                                                  |
10
// | License as published by the Free Software Foundation; either                                         |
11
// | version 2.1 of the License, or (at your option) any later version.                                   |
12
// |                                                                                                      |
13
// | This library is distributed in the hope that it will be useful,                                      |
14
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                                       |
15
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                                    |
16
// | General Public License for more details.                                                             |
17
// |                                                                                                      |
18
// | You should have received a copy of the GNU General Public                                            |
19
// | License along with this library; if not, write to the Free Software                                  |
20
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                            |
21
// +------------------------------------------------------------------------------------------------------+
249 alexandre_ 22
// CVS : $Id: document.class.php,v 1.8 2007-06-25 12:15:06 alexandre_tb Exp $
2 ddelon 23
/**
24
* Application projet
25
*
26
* La classe document
27
*
28
*@package projet
29
//Auteur original :
30
*@author        Alexandre Granier <alexandre@tela-botanica.org>
31
//Autres auteurs :
32
*@author        Aucun
33
*@copyright     Tela-Botanica 2000-2004
249 alexandre_ 34
*@version       $Revision: 1.8 $
2 ddelon 35
// +------------------------------------------------------------------------------------------------------+
36
*/
37
 
38
 
39
// +------------------------------------------------------------------------------------------------------+
40
// |                                            ENTETE du PROGRAMME                                       |
41
// +------------------------------------------------------------------------------------------------------+
42
 
43
include_once PROJET_CHEMIN_CLASSES.'fichier.class.php' ;
44
 
45
// +------------------------------------------------------------------------------------------------------+
46
// |                                            ENTETE du PROGRAMME                                       |
47
// +------------------------------------------------------------------------------------------------------+
48
 
49
/**
50
 * class document
51
 * Représente un document associé à un projet. C'est à dire un fichier
52
 * téléchargeable disposant en plus d'une visibilité, d'un nom long, d'une
53
 * description et d'une url.
54
 */
55
class document extends fichier
56
{
57
    /*** Attributes: ***/
58
 
59
    /**
60
     * Description qui apparaitra à l'écran.
61
     * @access private
62
     */
63
    var $_description;
64
    /**
65
     * Date de dernière mise à jour des attributs du fichier.
66
     * @access private
67
     */
68
    var $_date_mise_a_jour;
69
    /**
70
     * Soit public, soit privé.
71
     * @access private
72
     */
73
    var $_visibilite;
74
    /**
75
     * Le nom du fichier tel qu'il apparaitra à l'écran.
76
     * @access private
77
     */
78
    var $_nom_long;
79
    /**
80
     * Un objet PEAR:DB
81
     * @access private
82
     */
83
    var $_db;
84
 
85
    /**
86
     * L'identifiant du document dans la table projet_document.
87
     * @access private
88
     */
89
    var $_id;
90
 
91
    /**
92
     *
93
     * @access private
94
     */
95
    var $_chemin_icone;
96
 
97
    /**
98
     * L'identifiant du père, peut être à NULL
99
     * @access private
100
     */
101
    var $_id_pere;
102
 
103
    /**
104
     * L'identifiant du propriétaire. Provient d'un annuaire. Peut être à NULL.
105
     * @access private
106
     */
107
    var $_id_proprietaire;
108
    /**
109
     * L'identifiant du projet auquel appartient le document. Peut être à NULL.
110
     * @access private
111
     */
112
    var $_id_projet;
113
 
114
    /**
115
    *   Le chemin du fichier, depuis le répertoire du projet
116
    *
117
    */
118
    var $_pd_lien ;
249 alexandre_ 119
 
120
    var $nom_fichier ;
2 ddelon 121
    /**
122
     *
123
     *
124
     * @param int id_document L'identifiant du document dans la base.
125
     * @param int objetDB un objet PEAR:DB
126
     * @return void
127
     * @access public
128
     */
129
    function document( $id_document = "",  &$objetDB, $chemin = '', $chemin_icones = '')
130
    {
131
        $this->_db = $objetDB ;
132
        $this->_chemin_icone = $chemin_icones ;
249 alexandre_ 133
 
2 ddelon 134
        if ($id_document != "") {
135
            $requete = "select * from projet_documents where pd_id=".$id_document ;
136
            $resultat = $this->_db->query ($requete) ;
137
            if (DB::isError($resultat)) {
138
                die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
139
            }
140
            $ligne = $resultat->fetchRow (DB_FETCHMODE_OBJECT) ;
15 ddelon 141
    		if ($resultat->numRows()>0) {
249 alexandre_ 142
	            $this->nom_fichier = $ligne->pd_lien;
143
	            $this->_id_projet = $ligne->pd_ce_projet;
15 ddelon 144
	            $this->_id = $ligne->pd_id ;
249 alexandre_ 145
	            fichier::fichier($chemin.$this->getChemin(), $this->_db) ;
146
 
15 ddelon 147
	            if (is_object ($this->_type_mime)) $this->_type_mime->setCheminIcone ($chemin_icones) ;
148
	            $this->_id_proprietaire = $ligne->pd_ce_utilisateur ;
149
	            $this->_nom_long = $ligne->pd_nom ;
150
	            $this->_visibilite = $ligne->pd_visibilite ;
151
	            $this->_date_mise_a_jour = $ligne->pd_date_de_mise_a_jour ;
152
	            $this->_description = $ligne->pd_description ;
153
	            $this->_pd_lien = $ligne->pd_lien;
249 alexandre_ 154
 
15 ddelon 155
	            if ($this->_isRacine($ligne->pd_pere)) {
156
	                $this->_id_pere = 0 ;
157
	            } else {
158
	                $this->_id_pere = $ligne->pd_pere ;
159
	            }
160
    		}
2 ddelon 161
        }
162
 
163
    } // end of member function document
164
 
165
    /**
166
     *
167
     *
168
     * @param int id_document L'identifiant du document dans la base.
169
     * @param int objetDB Un objet PEAR:DB
170
     * @return document
171
     * @access public
172
     */
15 ddelon 173
    function __construct( $id_document = "",  &$objetDB, $chemin = '', $chemin_icones = '' )
2 ddelon 174
    {
15 ddelon 175
 
176
       $this->document($id_document, $objetDB, $chemin, $chemin_icones);
2 ddelon 177
 
178
    } // end of member function __construct
179
 
180
 
181
    /**
182
     * Renvoie le nom long du fichier.
183
     *
184
     * @return string
185
     * @access public
186
     */
187
    function getNomLong( )
188
    {
189
        return $this->_nom_long ;
190
    } // end of member function getNomLong
191
 
192
    /**
193
     * Renvoie la visibilité du document, soit "public" soit "prive"
194
     *
195
     * @return visibilite
196
     * @access public
197
     */
198
    function getVisibilite( )
199
    {
200
        return $this->_visibilite ;
201
    } // end of member function getVisibilite
202
 
203
    /**
204
     * Renvoie la description du document, sous forme de chaine.
205
     *
206
     * @return string
207
     * @access public
208
     */
209
    function getDescription( )
210
    {
211
        return $this->_description ;
212
    } // end of member function getDescription
213
 
214
    /**
215
     * Renvoie la date de création ou de mise à jour du fichier.
216
     *
217
     * @return date
218
     * @access public
219
     */
220
    function getDateMiseAJour( )
221
    {
222
        return $this->_date_mise_a_jour ;
223
    } // end of member function getDateMiseAJour
224
 
225
    /**
226
     * Renvoie l'identifiant d'un document.
227
     *
228
     * @return int
229
     * @access public
230
     */
231
    function getIdDocument( )
232
    {
233
        return $this->_id ;
234
    } // end of member function getIdDocument
235
 
236
    /**
237
     * Renvoie le chemin de l'icone du fichier. Fait un appel à type_fichier_mime.
238
     *
239
     * @return string
240
     * @access public
241
     */
242
    function getCheminIcone()
243
    {
244
        if ($this->isRepertoire()) {
245
            return $this->_chemin_icone."repertoire.gif" ;
246
        } else {
249 alexandre_ 247
            if (is_object ($this->_type_mime)) return $this->_type_mime->getCheminIcone() ;
2 ddelon 248
        }
249
    } // end of member function getCheminIcone
250
 
251
    /**
252
     * Permet de récupérer le nom du répertoire racine associé à un projet.
253
     *
254
     * @param int id_projet L'identifiant du projet dont on veux récupérer le répertoire racine.
255
     * @param DB objetDB Un objet PEAR:DB
256
     * @return string
257
     * @static
258
     * @access public
259
     */
260
    function getNomRepertoireProjet( $id_projet , &$objetDB)
261
    {
262
        // Dans la table projet_documents, pour les répertoires racines, pd_pere = null
263
        $requete = "select pd_nom from projet_documents where pd_ce_projet=$id_projet and pd_pere is null" ;
264
        $resultat = $objetDB->query ($requete) ;
265
        if (DB::isError($resultat)) {
266
            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
267
        }
268
        $ligne = $resultat->fetchRow (DB_FETCHMODE_OBJECT) ;
269
        return $ligne->pd_nom ;
270
    } // end of member function getNomRepertoireProjet
271
 
272
 
273
    /**
274
     * Renvoie true si le document passé en paramètre est le répertoire racine.
275
     *
276
     * @param int id_document L'identifiant du document dont on veut savoir si c'est la racine.
277
     * @return bool
278
     * @access public
279
     */
280
    function _isRacine( $id_document )
281
    {
15 ddelon 282
    	if ($id_document) {
283
	        $requete = "select pd_pere from projet_documents where pd_id=".$id_document ;
284
	        $resultat = $this->_db->query ($requete) ;
285
	        if (DB::isError($resultat)) {
286
	            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
287
	        }
288
	        $ligne = $resultat->fetchRow(DB_FETCHMODE_OBJECT) ;
289
	        if ($resultat->numRows() >0) {
290
	        	if ($ligne->pd_pere == null){
291
	            	return true ;
292
	        	}
293
	        }
294
    	}
2 ddelon 295
        return false ;
296
    } // end of member function _isRacine
297
 
298
    /**
299
     * Renvoie le chemin d'un fichier ou d'un répertoire. Contrairement à la classe
300
     * mère, cette méthode renvoie une URL projet et non pas un fichier.
301
     *
302
     * @return string
303
     * @access public
304
     */
249 alexandre_ 305
    function getChemin($prefixe = '')
2 ddelon 306
    {
249 alexandre_ 307
        $chemin_repertoire_entre_racine_et_fichier = '';
308
 
309
        include_once PROJET_CHEMIN_CLASSES.'projet.class.php';
310
        $projet = new projet ($this->_db, $this->_id_projet);
311
        // l arborescence des repertoires
312
 
313
        $tableau_navigation = $this->getPath($this->_id) ;
314
        if (is_array ($tableau_navigation))$tableau_navigation = array_reverse($tableau_navigation);
315
        for ($i = 0; $i < count ($tableau_navigation); $i++) {
316
        	$chemin_repertoire_entre_racine_et_fichier.= $tableau_navigation[$i]."/";
2 ddelon 317
        }
249 alexandre_ 318
        return $projet->getNomRepertoire().'/'.$chemin_repertoire_entre_racine_et_fichier.$this->nom_fichier ;
319
    }
2 ddelon 320
 
321
 
322
    /**
249 alexandre_ 323
     * Renvoie pour le repertoire ou le fichier courant, les identifiants et les noms de tous les
2 ddelon 324
     * répertoires père jusqu'à la racine. 0 => ['id'], ['nom'] 1 => [id'], ['nom'] etc.
325
     * En commençant par la racine et en descendant.  Pour la racine id vaut "" et nom
326
     * vaut "".
327
     *
328
     * @param int id_repertoire L'identifiant d'un répertoire.
329
     * @return Array
330
     * @access public
331
     */
249 alexandre_ 332
 
333
    function getCheminIdRepertoire( $id_doc, &$objetDB )
2 ddelon 334
    {
249 alexandre_ 335
        if ($id_doc == "") $id_doc = 0;
2 ddelon 336
        // on commence par rechercher le répertoire père, dans la base de donnée
249 alexandre_ 337
        $requete = 'select pd_pere, pd_nom, pd_id, pd_ce_type from projet_documents where pd_id='.$id_doc ;
2 ddelon 338
        $resultat = $objetDB->query ($requete) ;
339
        if (DB::isError($resultat)) {
340
            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
341
        }
342
        $ligne = $resultat->fetchRow (DB_FETCHMODE_OBJECT) ;
343
        $chemin_rep_id_nom = array() ;
15 ddelon 344
        if ($resultat->numRows()>0) {
345
    	    if ($ligne->pd_pere == 0) {
249 alexandre_ 346
        	    return ; //array ($ligne->pd_pere);
15 ddelon 347
        	}
249 alexandre_ 348
            array_push ($chemin_rep_id_nom, $ligne->pd_pere) ;
349
            $tab = document::getCheminIdRepertoire($ligne->pd_pere, $objetDB) ;
350
            $chemin_rep_id_nom = array_merge ($tab, $chemin_rep_id_nom) ;
2 ddelon 351
        }
249 alexandre_ 352
        return array_reverse($chemin_rep_id_nom);
353
    }
354
	function getPath( $id_doc)
355
    {
356
        if ($id_doc == "") $id_doc = 0;
357
        // on commence par rechercher le répertoire père, dans la base de donnée
358
        $requete = 'select pd_pere, pd_nom, pd_id, pd_ce_type from projet_documents where pd_id='.$id_doc ;
359
        $resultat = $GLOBALS['projet_db']->query ($requete) ;
360
        if (DB::isError($resultat)) {
361
            return ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
2 ddelon 362
        }
249 alexandre_ 363
        $ligne = $resultat->fetchRow (DB_FETCHMODE_OBJECT) ;
364
        $chemin_rep_id_nom = array() ;
365
        if ($resultat->numRows()>0) {
366
    	    if ($ligne->pd_pere == 0) {
367
        	    return;
368
        	}
369
            array_push ($chemin_rep_id_nom, $ligne->pd_pere) ;
370
            $chemin_rep_id_nom = array_merge ($chemin_rep_id_nom, document::getPath($ligne->pd_pere) );
371
        }
372
        return $chemin_rep_id_nom;
373
    }
2 ddelon 374
    /**
375
     *  Calcule le chemin vers le fichier ou le répertoire uploadé
376
     *  renvoie un chaine de la forme dir1/dir2/fichier.ext
377
     *  En prenant comme racine le répertoire du projet, exclu.
378
     * @return  string  Le chemin
379
     */
380
 
381
    function calculeCheminUploaded ($radical) {
249 alexandre_ 382
 
383
        if (isset($_FILES['fichier']['name'])) {
384
        	$extension = preg_replace("/^([^\.]+)\.(\w+$)/", "\\2", $_FILES['fichier']['name']) ;
385
        }
386
 
2 ddelon 387
        if ($this->_id_pere != '') {
388
            // On appelle la méthode getCheminIdRepertoire qui renvoie un tableau avec la liste
389
            // des répertoires jusqu'à la racine, on enlève la racine ($i = 0) et on concatène
390
            // toutes les entrées pour obtenir le chemin jusqu'au répertoire courant
391
            $chemin_repertoire_entre_racine_et_repertoire_a_cree = '' ;
249 alexandre_ 392
            $doc_pere = new document ($this->_id_pere, $this->_db);
393
            return $doc_pere->getChemin();
394
            $tableau_navigation = $this->getPath($this->_id_pere) ;
395
 
396
            for ($i = 0; $i < count ($tableau_navigation); $i++) $chemin_repertoire_entre_racine_et_repertoire_a_cree.= $tableau_navigation[$i]."/";
397
            $chemin = $chemin_repertoire_entre_racine_et_repertoire_a_cree ;
2 ddelon 398
        } else {
249 alexandre_ 399
            // Si l'on est à la racine du projet, le chemin vide
400
            return $radical ;
2 ddelon 401
        }
402
        return $chemin ;
403
    }
404
 
405
    /**
406
     * Enregistre une ligne dans la table projet_document
407
     * Le tableau de valeur doit contenir les éléments suivants 'document_nom','document_description','document_visibilite','fichier'
408
     *
409
     * @param Array tableau_de_valeur Le tableau de valeur a insérer dans la base avec pour clé les noms des éléments
410
     * @access  public
411
     * @return void
412
     */
413
 
414
    function enregistrerSQL ($valeur, $chemin) {
415
 
416
        // On teste si on a affaire à un répertoire ou un fichier
417
        if (isset ($_FILES['fichier']['name'])) {
418
            // On tente de déterminer le type du fichier à partir de son nom dans $valeur['$fichier']
419
            $tableau_nom = explode (".", $_FILES['fichier']['name']) ;
420
 
421
            // On prend le dernier élément du tableau, si c'est un tableau
422
            if (is_array($tableau_nom)) {
423
                $extension = array_pop($tableau_nom) ;
424
                $type = type_fichier_mime::factory($extension, $this->_db) ;
425
                $id_extension = $type->getIdType() ;
426
            } else {
427
                $id_extension = 12 ;
428
            }
429
            $pd_lien = $chemin ;
430
        } else {    // Le cas ou on a affaire à un répertoire
431
            $id_extension = 0 ;
432
            // Le nom du répertoire est son identifiant avec un slash à la fin
433
            $pd_lien = $chemin."/" ;
434
            if ($this->_id_pere != '') {
435
                // On appelle la méthode getCheminIdRepertoire qui renvoie un tableau avec la liste
436
                // des répertoires jusqu'à la racine, on enlève la racine ($i = 0) et on concatène
437
                // toutes les entrées pour obtenir le chemin jusqu'au répertoire courant
438
                $chemin_repertoire_entre_racine_et_repertoire_a_cree = '' ;
439
                $tableau_navigation = $this->getCheminIdRepertoire($this->_id_pere, $this->_db) ;
440
                for ($i = 0; $i < count ($tableau_navigation); $i+=2) $chemin_repertoire_entre_racine_et_repertoire_a_cree.= $tableau_navigation[$i]."/";
441
                $pd_lien .= $chemin_repertoire_entre_racine_et_repertoire_a_cree ;
442
            }
249 alexandre_ 443
            //$pd_lien .= SQL_obtenirNouveauId($this->_db, 'projet_documents', 'pd_id')."/" ;
444
            $pd_lien = SQL_obtenirNouveauId($this->_db, 'projet_documents', 'pd_id')."/" ;
2 ddelon 445
        }
446
        $id = SQL_obtenirNouveauId($this->_db, 'projet_documents', 'pd_id') ;
447
 
448
        $requete = "insert into projet_documents set pd_id=".$id ;
449
        $requete .= ", pd_nom=\"".$valeur['document_nom']."\", pd_description=\"".$valeur['document_description']."\"".
450
                    ", pd_visibilite=\"".$valeur['document_visibilite']."\", pd_date_de_mise_a_jour=NOW(),".
451
                    "pd_ce_projet=\"".$this->_id_projet."\", pd_ce_utilisateur=\"".$this->_id_proprietaire."\"".
452
                    ", pd_pere=\"$this->_id_pere\", pd_ce_type=\"$id_extension\", pd_lien=\"$pd_lien\"" ;
453
 
454
        $resultat = $this->_db->query ($requete) ;
455
        if (DB::isError($resultat)) {
456
            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
457
        }
458
        $this->_id = $id ;
459
        return $pd_lien;
460
    }
461
 
249 alexandre_ 462
	function genereNouveauNom ($radical, $ancien_nom, $id) {
463
		$extension = preg_replace("/^([^\.]+)\.(\w+$)/", "\\2", $ancien_nom) ;
464
        $nouveau_nom = $radical."_".$id.".".$extension ;
465
        return $nouveau_nom;
466
	}
2 ddelon 467
 
468
    /**
469
     * Met à jour une ligne dans la table projet_document
470
     * Le tableau de valeur doit contenir les éléments suivants 'document_nom','document_description','document_visibilite','fichier'
471
     *
472
     * @param Array tableau_de_valeur Le tableau de valeur a insérer dans la base avec pour clé les noms des éléments
473
     * @access  public
474
     * @return void
475
     */
476
 
477
    function majSQL ($valeur) {
478
        $requete = "update projet_documents set pd_nom=\"".$valeur['document_nom']."\", pd_description=\"".$valeur['document_description']."\"".
479
                    ", pd_visibilite=\"".$valeur['document_visibilite']."\", pd_date_de_mise_a_jour=NOW()".
480
                    " where pd_id=".$this->_id;
481
 
482
        $resultat = $this->_db->query ($requete) ;
483
        if (DB::isError($resultat)) {
484
            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
485
        }
486
        return ;
487
    }
488
 
489
    /** Supprime les donnéexs du document dans la table projet_documents
490
     *
491
     *
492
     * @return true en cas de succès
493
     */
494
 
495
    function suppressionSQL () {
496
        $requete = 'delete from projet_documents where pd_id='.$this->_id ;
497
        $resultat = $this->_db->query ($requete) ;
498
        if ($this->_db->affectedRows()) return true ;
499
        return false ;
500
    }
501
 
502
    /**
503
     * Déplace un document au sein d'un même projet
504
     *
505
     * @param int repertoire_destination L'identifiant du répertoire destination.
506
     * @return bool
507
     * @access public
508
     */
509
    function deplace( $repertoire_destination, $repertoire_projet )
510
    {
249 alexandre_ 511
 
2 ddelon 512
        // On récupère les informations du répertoire cible
513
        if ($repertoire_destination != 0) {
514
            $repertoire_cible = new document ($repertoire_destination, $this->_db) ;
249 alexandre_ 515
            $chemin_rep_cible = $repertoire_cible->getChemin();
2 ddelon 516
        } else {
249 alexandre_ 517
        	// Si le repertoire destination est la racine cad id =0
518
        	// on cree un document qui aura pour chemin le repertoire du projet
519
        	include_once PROJET_CHEMIN_CLASSES.'projet.class.php';
520
            $projet = new projet ($this->_db, $this->_id_projet);
521
        	$chemin_rep_cible = $projet->getNomRepertoire().'/';
2 ddelon 522
        }
249 alexandre_ 523
 
524
        $nom_fichier = $this->_pd_lien ;
525
        $requete = 'update projet_documents set pd_pere='.$repertoire_destination.' where pd_id='.$this->_id ;
2 ddelon 526
        $resultat = $this->_db->query ($requete) ;
527
        if (DB::isError($resultat)) {
528
            echo ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
529
            return false ;
530
        }
249 alexandre_ 531
        //echo $this->_chemin.'<br>'.PROJET_CHEMIN_FICHIER.$chemin_rep_cible.$nom_fichier;
532
        return fichier::deplace ($this->_chemin, PROJET_CHEMIN_FICHIER.$chemin_rep_cible.$nom_fichier) ;
2 ddelon 533
 
534
    } // end of member function deplace
535
 
536
 
537
    /**
538
     * Pour modifier l'identifiant du projet auquel appartient un document.
539
     *
540
     * @param int id_projet L'identifiant du projet.
541
     * @return void
542
     * @access public
543
     */
544
    function setIdProjet( $id_projet )
545
    {
546
        $this->_id_projet = $id_projet ;
547
    } // end of member function setIdProjet
548
 
549
    /**
550
     * Permet de modifier l'identifiant du propietaire d'un projet.
551
     *
552
     * @param int id_proprietaire L'identifiant du proprietaire d'un document.
553
     * @return void
554
     * @access public
555
     */
556
    function setIdProprietaire( $id_proprietaire )
557
    {
558
        $this->_id_proprietaire = $id_proprietaire ;
559
    } // end of member function setIdProprietaire
560
 
561
    /**
562
     * Permet de modifier l'identifiant du répertoire d'un document.
563
     *
564
     * @param int id_repertoire L'identifiant du repertoire d'un document.
565
     * @return void
566
     * @access public
567
     */
568
    function setIdRepertoire( $id_repertoire )
569
    {
570
        $this->_id_pere = $id_repertoire;
571
    } // end of member function setIdRepertoire
572
 
573
    /**
574
     * initAttributes sets all document attributes to its default                    value make
575
     * sure to call this method within your class constructor
576
     */
577
    function initAttributes( )
578
    {
579
        $this->_visibilite = "public";
580
    }
581
 
582
    /**
583
     * Renvoie les derniers documents de l'ensemble des projets.
584
     *
585
     * @param int nombre Le nombre de document à renvoyer
586
     * @return Array
587
     * @static
588
     * @access public
589
     */
97 alexandre_ 590
    function getDocumentsRecents( $nombre = 10, &$objetDB, $chemin, $chemin_icones, $id_projet = '', $visible = true)
2 ddelon 591
    {
201 alexandre_ 592
        // on recherche les documents, hors repertoire
2 ddelon 593
        $requete = 'select pd_id from projet_documents where pd_ce_type<>0 ';
594
        if ($id_projet != '') $requete .= ' and pd_ce_projet='.$id_projet.' ';
97 alexandre_ 595
        if (!$visible) $requete .= ' and pd_visibilite="public" ';
2 ddelon 596
        $requete .= 'order by pd_date_de_mise_a_jour desc limit 0,'.$nombre ;
597
        $resultat = $objetDB->query ($requete) ;
598
        if (DB::isError ($resultat)) {
599
            die ('Echec de la requete : '.$requete.'<br />'.$resultat->getMessage()) ;
600
        }
601
        $tableau_document = array() ;
602
 
603
        while ($ligne = $resultat->fetchRow (DB_FETCHMODE_OBJECT)) {
604
            array_push ($tableau_document, new document ($ligne->pd_id, $objetDB, $chemin, $chemin_icones)) ;
605
        }
606
        return $tableau_document ;
607
    } // end of member function getDocumentsRecents
608
 
201 alexandre_ 609
    /**
610
     * Renvoie les documents du projet passe en parametre sous forme d arbre d objet document
611
     *
612
     * @param int l identifiant du projet
613
     * @return Array
614
     * @static
615
     * @access public
616
     */
617
	function getArbreDocument($id_projet, $objetDB = '') {
618
		$requete = 'select pd_id, pd_nom, pd_ce_type, pd_pere from projet_documents where pd_ce_projet='.$id_projet;
619
		$resultat = $GLOBALS['projet_db']->getAll($requete, null, DB_FETCHMODE_OBJECT);
620
		if (DB::isError ($resultat)) {
621
            return ('Echec de la requete : '.$requete.'<br />'.$resultat->getMessage()) ;
622
        }
623
 
624
      	return $resultat;
625
	}
626
	 /**
627
     * Renvoie la taille du document formatee avec une unite adapte
628
     *
629
     * @return string La taille formate
630
     * @access public
631
     */
632
	function getTailleFormatee($precision = 1) {
633
		$taille = $this->getTaille();
634
		if ($taille > 1000000) {
635
			$diviseur = 1000000;
636
			$unite = 'Mo';
637
		} else {
638
			$diviseur = 1000 ;
639
			$unite = 'Ko';
640
		}
641
		return round ($taille / $diviseur, $precision).'&nbsp;'.$unite;
642
	}
249 alexandre_ 643
 
644
	/**
645
     * Renvoie une liste de document, enfant du document courant
646
     * qui doit etre un repertoire bien sur
647
     *
648
     * @return mixed un tableau de document
649
     * @access public
650
     */
651
	function getDocumentsEnfant() {
652
 
653
	}
201 alexandre_ 654
 
2 ddelon 655
} // end of document
656
 
657
 
658
?>