Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Class.Lang.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
5  * @package FDL
6 */
7 /**
8  * Generated Header (not documented yet)
9  *
10  * @author Anakeen 2000
11  * @version $Id: Class.Lang.php,v 1.2 2003/08/18 15:46:42 eric Exp $
12  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
13  * @package FDL
14  * @subpackage CORE
15  */
16 /**
17  */
18 // ---------------------------------------------------------------
19 // $Id: Class.Lang.php,v 1.2 2003/08/18 15:46:42 eric Exp $
20 // $Source: /home/cvsroot/anakeen/freedom/core/Class/Layout/Class.Lang.php,v $
21 // ---------------------------------------------------------------
22 // $Log: Class.Lang.php,v $
23 // Revision 1.2 2003/08/18 15:46:42 eric
24 // phpdoc
25 //
26 // Revision 1.1 2002/01/08 12:41:34 eric
27 // first
28 //
29 // Revision 1.9 2001/10/17 09:08:49 eric
30 // mise en place de i18n via gettext
31 //
32 // Revision 1.8 2001/02/26 15:05:31 yannick
33 // Optimization : Add a buffer
34 //
35 // Revision 1.7 2000/11/02 19:04:51 marc
36 // Simplification, affichage des code si pas de message.
37 //
38 // Revision 1.6 2000/10/23 14:23:55 marc
39 // Another release
40 //
41 // Revision 1.5 2000/10/19 16:34:45 yannick
42 // Pour Marc
43 //
44 // Revision 1.4 2000/10/19 10:31:04 marc
45 // Langues: suppression ancien catalogue lors du reload de l'app
46 //
47 // Revision 1.3 2000/10/19 10:15:13 marc
48 // Finalisation de l'internationalisation
49 //
50 // Revision 1.2 2000/10/18 20:15:17 marc
51 // Internationalisation
52 //
53 // Revision 1.1 2000/10/18 19:55:08 marc
54 // Internationalisation
55 //
56 //
57 // ---------------------------------------------------------------
58 include_once ('Class.DbObj.php');
59 include_once ('Class.QueryDb.php');
60 include_once ('Class.Log.php');
61 
62 class Lang extends DbObj
63 {
64 
65  var $fmttxt = "NO TEXT DEFINED";
66  var $fields = array(
67  "idapp",
68  "lang",
69  "code",
70  "fmt"
71  );
72  var $id_fields = array(
73  "idapp",
74  "lang",
75  "code"
76  );
77  var $dbtable = "lang";
78 
79  var $sqlcreate = '
80 create table lang (idapp int not null,
81 lang varchar(10) not null,
82 code varchar(60) not null,
83 fmt varchar(200) not null );
84 create index lang_idx1 on lang(idapp, lang, code);
85 ';
86 
87  var $buffer = array();
88 
89  function Exist($idapp, $code, $lang)
90  {
91  $query = new QueryDb($this->dbaccess, "Lang");
92  $query->basic_elem->sup_where = array(
93  "idapp={$idapp}",
94  "lang='{$lang}'",
95  "code='{$code}'"
96  );
97  $query->Query();
98 
99  if ($query->nb == 0) return FALSE;
100  return TRUE;
101  }
102 
103  function SetEnv($id, $lang, $deflang)
104  {
105  $this->idapp = $id;
106  $this->lang = $lang;
107  $this->deflang = $lang;
108  $query = new QueryDb($this->dbaccess, "Lang");
109  $query->basic_elem->sup_where = array(
110  "idapp={$id}",
111  "lang='{$deflang}'"
112  );
113  $lista = $query->Query();
114  $query->basic_elem->sup_where = array(
115  "idapp={$id}",
116  "lang='{$lang}'"
117  );
118  $listb = $query->Query();
119  $list = array_merge($lista, $listb);
120  reset($list);
121  while (list($k, $v) = each($list)) {
122  $this->buffer[$v->code] = $v->fmt;
123  }
124  }
125 
126  function Store($idapp, $code, $lang, $fmt)
127  {
128  $this->idapp = $idapp;
129  $this->lang = $lang;
130  $this->code = $code;
131  $this->fmt = $fmt;
132  if ($this->exist($idapp, $code, $lang)) {
133  $this->Modify();
134  } else {
135  $this->Add();
136  }
137  }
138 
139  function Get($idapp, $lang, $code, $args = NULL)
140  {
141 
142  $query = new QueryDb($this->dbaccess, "Lang");
143  $query->basic_elem->sup_where = array(
144  "idapp={$idapp}",
145  "lang='{$lang}'",
146  "code='{$code}'"
147  );
148  $list = $query->Query();
149 
150  if ($query->nb <= 0) {
151  $this->fmttxt = "**{$code}**";
152  return FALSE;
153  }
154 
155  $uf = $list[0]->fmt;
156  if ($args == NULL) {
157  $this->fmttxt = $uf;
158  } else {
159  $nfmt = preg_replace("/%([0-9]+)%/", "{\$args[\\1]}", $uf);
160  eval("\$out = \"$nfmt\";");
161  $this->fmttxt = $out;
162  }
163  return TRUE;
164  }
165  function GetText($code, $args = NULL)
166  {
167  if (!isset($this->buffer[$code])) return FALSE;
168  $uf = $this->buffer[$code];
169  if ($args == NULL) {
170  $this->fmttxt = $uf;
171  } else {
172  $nfmt = preg_replace("/%([0-9]+)%/", "{\$args[\\1]}", $uf);
173  eval("\$out = \"$nfmt\";");
174  $this->fmttxt = $out;
175  }
176  return TRUE;
177  }
178 
179  function deletecatalog($idapp)
180  {
181  $query = new QueryDb($this->dbaccess, "Lang");
182  $query->basic_elem->sup_where = array(
183  "idapp={$idapp}"
184  );
185  $list = $query->Query();
186  if ($query->nb > 0) {
187  while (list($k, $v) = each($list)) $v->delete();
188  }
189  }
190 } // End Class
← centre documentaire © anakeen - published under CC License - Dynacase