Subversion Repositories Applications.projet

Rev

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

Rev Author Line No. Line
431 mathias 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
// +------------------------------------------------------------------------------------------------------+
22
// CVS : $Id: type_fichier_mime.class.php,v 1.2 2005-09-27 16:42:00 alexandre_tb Exp $
23
/**
24
* Application projet
25
*
26
* La classe type_fichier_mime
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
34
*@version       $Revision: 1.2 $
35
// +------------------------------------------------------------------------------------------------------+
36
*/
37
 
38
 
39
// +------------------------------------------------------------------------------------------------------+
40
// |                                            ENTETE du PROGRAMME                                       |
41
// +------------------------------------------------------------------------------------------------------+
42
 
43
 
44
// +------------------------------------------------------------------------------------------------------+
45
// |                                            ENTETE du PROGRAMME                                       |
46
// +------------------------------------------------------------------------------------------------------+
47
 
48
/**
49
 * class type_fichier_mime
50
 *
51
 */
52
class type_fichier_mime
53
{
54
    /*** Attributes: ***/
55
 
56
    /**
57
     * Le nom du type en français (ex Image jpg)
58
     * @access private
59
     */
60
    var $_nom;
61
    /**
62
     * L'extension du fichier (ex: png)
63
     * @access private
64
     */
65
    var $_extension;
66
    /**
67
     * Le nom du fichier de l'icône représentant ce fichier.
68
     * @access private
69
     */
70
    var $_icone;
71
    /**
72
     * Le type mime.
73
     * @access private
74
     */
75
    var $_type_mime;
76
    /**
77
     *
78
     * @access private
79
     */
80
    var $_description;
81
    /**
82
     * Le chemin UNIX ou Windows vers le dossier des icônes. Il ne commence pas par un
83
     * slash et termine par slash.
84
     * @access private
85
     */
86
    var $_chemin_icone = "icones/";
87
    /**
88
     * Un objet PEAR:DB
89
     * @access private
90
     */
91
    var $_db;
92
    /**
93
     * L'identifiant du type dans la table gen_type_de_fichier
94
     * @access private
95
     */
96
    var $_id_type;
97
 
98
    /**
99
     * Renvoie le chemin vers les icônes.
100
     *
101
     * @return string
102
     * @access public
103
     */
104
    function getCheminIcone( )
105
    {
106
        return $this->_chemin_icone.$this->_icone ; ;
107
    } // end of member function getCheminIcone
108
 
109
    /**
110
     *
111
     *
112
     * @param string chemin Le chemin vers l'icône.
113
     * @return void
114
     * @access public
115
     */
116
    function setCheminIcone( $chemin )
117
    {
118
        $this->_chemin_icone = $chemin ;
119
    } // end of member function setCheminIcone
120
 
121
    /**
122
     *
123
     *
124
     * @param DB objetDB un objet PEAR:DB
125
     * @param int id_type
126
     * @return void
127
     * @access public
128
     */
129
    function type_fichier_mime(  $id_type = '', $chemin_icones = "icones/" )
130
    {
131
 
132
        $requete = 'select * from gen_type_de_fichier where ' ;
133
        if (is_numeric ($id_type)) {
134
            $requete .= 'gtf_id_type='.$GLOBALS['projet_db']->escapeSimple($id_type) ;
135
        } else {
136
            $requete .= 'gtf_type_mime="'.$id_type.'"' ;
137
        }
138
        $resultat = $GLOBALS['projet_db']->query ($requete) ;
139
        if (DB::isError($resultat)) {
140
            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
141
        }
142
        $ligne = $resultat->fetchRow (DB_FETCHMODE_OBJECT) ;
143
        $this->_chemin_icone = $chemin_icones ;
144
        $this->_icone = $ligne->gtf_type_icone ;
145
        $this->_id_type = $ligne->gtf_id_type ;
146
    } // end of member function type_fichier_mime
147
 
148
    /**
149
     * Tente de renvoyer un objet type_fichier_mime à partir de l'extension passé en
150
     * paramètre. S'il elle n'y arrive pas, elle renvoie 'inconnue'.
151
     *
152
     * @param string extension On passe un extension en paramètre, pour déterminer le type mime.
153
     * @param DB objetDB un objet PEAR:DB
154
     * @return type_fichier_mime
155
     * @static
156
     * @access public
157
     */
158
    function factory( $extension, $objetDB = '')
159
    {
160
        if (is_object($objetDB)) {
161
        	$GLOBALS['projet_db'] = $objetDB;
162
        }
163
        $requete = "select * from gen_type_de_fichier where gtf_extension=\"$extension\" or gtf_type_mime=\"$extension\"" ;
164
        $resultat = $GLOBALS['projet_db']->query ($requete) ;
165
        if (DB::isError($resultat)) {
166
            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
167
        }
168
        if ($resultat->numRows() != 0) {
169
            $ligne = $resultat->fetchRow (DB_FETCHMODE_OBJECT) ;
170
            return new type_fichier_mime ( $ligne->gtf_id_type) ;
171
        } else {
172
            // si il n'y a pas de résultat, on renvoie inconnue
173
            return new type_fichier_mime (12) ;
174
        }
175
    } // end of member function factory
176
 
177
    /**
178
     * Renvoie l'identifiant du type Mime de la table gen_type_de_fichier
179
     *
180
     * @return int
181
     * @access public
182
     */
183
    function getIdType( )
184
    {
185
        return $this->_id_type;
186
    } // end of member function getIdType
187
 
188
 
189
} // end of type_fichier_mime
190
?>