Subversion Repositories Applications.projet

Rev

Rev 431 | 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
    /**
442 mathias 57
     * Le nom du type en fran�ais (ex Image jpg)
431 mathias 58
     * @access private
59
     */
60
    var $_nom;
61
    /**
62
     * L'extension du fichier (ex: png)
63
     * @access private
64
     */
65
    var $_extension;
66
    /**
442 mathias 67
     * Le nom du fichier de l'ic�ne repr�sentant ce fichier.
431 mathias 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
    /**
442 mathias 82
     * Le chemin UNIX ou Windows vers le dossier des ic�nes. Il ne commence pas par un
431 mathias 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
    /**
442 mathias 99
     * Renvoie le chemin vers les ic�nes.
431 mathias 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
     *
442 mathias 112
     * @param string chemin Le chemin vers l'ic�ne.
431 mathias 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 ;
442 mathias 144
        if ($ligne) {
145
	        $this->_icone = $ligne->gtf_type_icone ;
146
	        $this->_id_type = $ligne->gtf_id_type ;
147
        }
431 mathias 148
    } // end of member function type_fichier_mime
149
 
150
    /**
442 mathias 151
     * Tente de renvoyer un objet type_fichier_mime � partir de l'extension pass� en
152
     * param�tre. S'il elle n'y arrive pas, elle renvoie 'inconnue'.
431 mathias 153
     *
442 mathias 154
     * @param string extension On passe un extension en param�tre, pour d�terminer le type mime.
431 mathias 155
     * @param DB objetDB un objet PEAR:DB
156
     * @return type_fichier_mime
157
     * @static
158
     * @access public
159
     */
160
    function factory( $extension, $objetDB = '')
161
    {
162
        if (is_object($objetDB)) {
163
        	$GLOBALS['projet_db'] = $objetDB;
164
        }
165
        $requete = "select * from gen_type_de_fichier where gtf_extension=\"$extension\" or gtf_type_mime=\"$extension\"" ;
166
        $resultat = $GLOBALS['projet_db']->query ($requete) ;
167
        if (DB::isError($resultat)) {
168
            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
169
        }
170
        if ($resultat->numRows() != 0) {
171
            $ligne = $resultat->fetchRow (DB_FETCHMODE_OBJECT) ;
172
            return new type_fichier_mime ( $ligne->gtf_id_type) ;
173
        } else {
442 mathias 174
            // si il n'y a pas de r�sultat, on renvoie inconnue
431 mathias 175
            return new type_fichier_mime (12) ;
176
        }
177
    } // end of member function factory
178
 
179
    /**
180
     * Renvoie l'identifiant du type Mime de la table gen_type_de_fichier
181
     *
182
     * @return int
183
     * @access public
184
     */
185
    function getIdType( )
186
    {
187
        return $this->_id_type;
188
    } // end of member function getIdType
189
 
190
 
191
} // end of type_fichier_mime
192
?>