Jeff PHP framework  0.99
Modular, extensible, OOP, MVC, lightweight php framework designed to ease the programmers in the development of web applications.
language.php
Go to the documentation of this file.
00001 <?php
00029 class language extends model {
00030         
00037         function __construct($id) {
00038         
00039                 $this->_tbl_data = TBL_LNG;
00040 
00041                 parent::__construct($id);
00042 
00043         }
00044 
00052         public static function get($registry, $opts=null) {
00053         
00054                 $objs = array();
00055                 $where = gOpt($opts, "where", ''); 
00056                 $rows = $registry->db->autoSelect("id", TBL_LNG, $where, 'language');
00057                 foreach($rows as $row) $objs[] = new language($row['id']);
00058 
00059                 return $objs;
00060         
00061         }
00062         
00069         public static function getFromLabel($label) {
00070 
00071                 $registry = registry::instance();
00072 
00073                 $rows = $registry->db->autoSelect("id", TBL_LNG, "label='$label'", 'language');
00074                 if(count($rows)) return new language($rows[0]['id']);
00075 
00076                 return null;
00077         
00078         }
00079 
00087         public static function setLanguage() {
00088 
00089                 $registry = registry::instance();
00090         
00091                 $language = null;
00092                 if($code = cleanInput('get', 'lng', 'string')) {
00093                         // charge language and put it in session
00094                         $rows = $registry->db->autoSelect(array("id", "language"), TBL_LNG, "code='$code'", 'language');
00095                         $language = $rows[0]['language'];
00096                         $_SESSION['lng'] = $language;
00097                         header("Location: ".preg_replace("#\?.*$#", "", $_SERVER['REQUEST_URI']));
00098                 }
00099                 elseif(isset($_SESSION['lng'])) {
00100                         // use session language
00101                         $language = $_SESSION['lng'];
00102                 }
00103 
00104                 if(!$language) {
00105                         // default language
00106                         $rows = $registry->db->autoSelect(array("id", "language"), TBL_LNG, "main='1'", 'language');
00107                         $language = $rows[0]['language'];
00108                         $_SESSION['lng'] = $language;
00109                 }
00110         
00111                 return $language;
00112         }
00113 
00114 }
00115 
00116 ?>