Ticket #237: jpref.2.diff

File jpref.2.diff, 16.6 kB (added by bastnic, 6 months ago)
  • build/manifests/jelix-lib.mn

    old new  
    100100   jacl2subject.dao.xml 
    101101   jacl2usergroup.dao.xml 
    102102   jacl2groupsofuser.dao.xml 
     103   jpref.dao.xml 
     104   jpref_ressource.dao.xml 
    103105cd lib/jelix/core-modules/jelix/install/sql 
    104106  delete.mysql.sql 
    105107  install_jacl.schema.mysql.sql 
     
    112114  install_jacl.data.pgsql.sql 
    113115  install_jacl2.schema.pgsql.sql 
    114116  install_jacl2.data.pgsql.sql 
     117  install_jpref.data.pgsql.sql 
     118  install_jpref.schema.mysql.sql 
     119  install_jpref.data.mysql.sql 
     120  install_jpref.schema.pgsql.sql 
    115121  install_jsession.schema.pgsql.sql 
    116122 
    117123cd lib/jelix/core-modules/jelix/locales/en_US 
     
    424430  class.auth.php 
    425431cd lib/jelix/plugins/auth/lds 
    426432  lds.auth.php 
     433cd lib/jelix/plugins/pref/db 
     434  db.pref.php 
    427435 
    428436cd lib/jelix/plugins/coord/magicquotes 
    429437! magicquotes.coord.php 
     
    502510  function.cycle_init.php 
    503511  function.cycle.php 
    504512  function.cycle_reset.php 
     513  function.jpref.php 
    505514  modifier.cat.php 
    506515  modifier.count_array.php 
    507516  modifier.count_characters.php 
     
    575584cd lib/jelix/plugins/urls/simple 
    576585  simple.urls.php 
    577586 
     587 
     588cd lib/jelix/pref 
     589  jPref.class.php 
     590  jPrefDb.class.php 
     591 
    578592cd lib/jelix-www/design 
    579593  jelix.css 
    580594  tooltip.css 
  • lib/jelix/plugins/tpl/common/function.jpref.php

    old new  
     1<?php 
     2/** 
     3* @package    jelix 
     4* @subpackage jtpl_plugin 
     5* @author     Bastien Jaillot 
     6* @copyright  2008 Bastien Jaillot 
     7* @link        http://www.jelix.org 
     8* @licence    GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html 
     9*/ 
     10 
     11/** 
     12 * function plugin : show the content of a jPref 
     13 * 
     14 * @param jTpl $tpl template engine 
     15 * @param string $str1 the first string 
     16 * @param string $str2 the second string 
     17 * @param string $nodiffmsg message quand il n'y a pas de différence 
     18 */ 
     19function jtpl_function_common_jpref($tpl, $id_pref,$ressource=null, $default=false) 
     20{ 
     21    echo jPref::get($id_pref, $ressource, $default); 
     22} 
  • lib/jelix/plugins/pref/db/db.pref.php

    old new  
     1<?php 
     2/** 
     3* @package     jelix 
     4* @subpackage  pref_driver 
     5* @author      Bastien Jaillot 
     6* @copyright   2008 Bastien Jaillot 
     7* @link        http://www.jelix.org 
     8* @licence     http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file 
     9*/ 
     10 
     11/** 
     12 * driver for jPref based on a database 
     13 * @package jelix 
     14 * @subpackage pref_driver 
     15 */ 
     16class dbPrefDriver implements jIPrefDriver { 
     17 
     18    /** 
     19     *  
     20     */ 
     21    function __construct (){ } 
     22 
     23    protected static $pref = array(); 
     24     
     25 
     26    public function get($key, $ressource=null, $default=false) { 
     27 
     28        if (!$default && isset($ressource) && isset(self::$pref[$ressource][$key]) ){ 
     29            return self::$pref[$ressource][$key]; 
     30        } 
     31        else if (isset (self::$pref[$key])) {             
     32            return self::$pref[$key]; 
     33        } 
     34                 
     35        if (!$default && isset($ressource) &&  
     36                $dao = jDao::get('jelix~jpref_ressource', jPrefDb::getProfil()) ) { 
     37            $daorec = $dao->getByRessource($key, $ressource); 
     38            if (!isset($daorec->value)) { 
     39                $default=true; 
     40            } 
     41            else { 
     42                self::$pref[$ressource][$key] = $daorec->value; 
     43            } 
     44        } 
     45        else $default = true; 
     46         
     47        if ($default) { 
     48            $dao = jDao::get('jelix~jpref', jPrefDb::getProfil()); 
     49            $daorec = $dao->get($key); 
     50            self::$pref[$key] = $daorec->value; 
     51        } 
     52         
     53        return $daorec->value; 
     54    } 
     55     
     56    public function set($key, $value, $ressource=null) { 
     57        if ($ressource != null) { 
     58            $dao = jDao::get('jelix~jpref_ressource', jPrefDb::getProfil()); 
     59            if($daorec = $dao->getByRessource($key, $ressource)) { 
     60                $toInsert = false; 
     61            }else{ 
     62                $daorec = jDao::createRecord('jelix~jpref_ressource', jPrefDb::getProfil()); 
     63                $toInsert= true; 
     64            } 
     65            self::$pref[$ressource][$key] = $value; 
     66             
     67        } 
     68        else { 
     69            $dao = jDao::get('jelix~jpref', jPrefDb::getProfil()); 
     70            if($daorec = $dao->get($key)) { 
     71                $toInsert = false; 
     72            }else{ 
     73                $daorec = jDao::createRecord('jelix~jpref', jPrefDb::getProfil()); 
     74                $toInsert= true; 
     75            } 
     76            self::$pref[$key] = $value; 
     77        } 
     78           
     79        $daorec->id_pref = $key; 
     80        $daorec->value = $value; 
     81         
     82        if ($ressource != null) $daorec->ressource = $ressource; 
     83         
     84        if ($toInsert) 
     85            $dao->insert($daorec); 
     86        else $dao->update($daorec); 
     87    } 
     88     
     89    public function unsetRessource($key, $ressource) { 
     90        $dao = jDao::get('jelix~jpref_ressource', jPrefDb::getProfil()); 
     91        $dao->deleteByRessource($key, $ressource); 
     92    } 
     93 
     94 
     95} 
     96 
  • lib/jelix/core/defaultconfig.ini.php

    old new  
    210210driver = db 
    211211enableAclDbEventListener = off 
    212212 
     213[pref] 
     214driver = db 
    213215 
    214216[sessions] 
    215217; to disable sessions, set the following parameter to 0 
  • lib/jelix/init.php

    old new  
    125125$gLibPath=array('Db'=>JELIX_LIB_PATH.'db/', 'Dao'=>JELIX_LIB_PATH.'dao/', 
    126126 'Forms'=>JELIX_LIB_PATH.'forms/', 'Event'=>JELIX_LIB_PATH.'events/', 
    127127 'Tpl'=>JELIX_LIB_PATH.'tpl/', 'Acl'=>JELIX_LIB_PATH.'acl/', 'Controller'=>JELIX_LIB_PATH.'controllers/', 
    128  'Auth'=>JELIX_LIB_PATH.'auth/', 'Installer'=>JELIX_LIB_PATH.'installer/'); 
     128 'Auth'=>JELIX_LIB_PATH.'auth/', 'Installer'=>JELIX_LIB_PATH.'installer/', 
     129 'Pref'=>JELIX_LIB_PATH.'pref/'); 
    129130 
    130131/** 
    131132 * __autoload function used by php to try to load an unknown class 
    132133 */ 
    133134function __autoload($class){ 
    134     if(preg_match('/^j(Dao|Tpl|Acl|Event|Db|Controller|Forms|Auth|Installer).*/i', $class, $m)){ 
     135    if(preg_match('/^j(Dao|Tpl|Acl|Event|Db|Controller|Forms|Auth|Installer|Pref).*/i', $class, $m)){ 
    135136        $f=$GLOBALS['gLibPath'][$m[1]].$class.'.class.php'; 
    136137    }elseif(preg_match('/^cDao(?:Record)?_(.+)_Jx_(.+)_Jx_(.+)$/', $class, $m)){ 
    137138        // pour les dao stockés en sessions notament 
  • lib/jelix/pref/jPref.class.php

    old new  
     1<?php 
     2/** 
     3* @package     jelix 
     4* @subpackage  pref 
     5* @author      Bastien Jaillot 
     6* @copyright   2008 Bastien Jaillot 
     7* @link        http://www.jelix.org 
     8* @licence     http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file 
     9* @since 1.1 
     10*/ 
     11 
     12/** 
     13 * interface for jpref drivers 
     14 * @package jelix 
     15 * @subpackage pref 
     16 */ 
     17interface jIPrefDriver { 
     18     
     19    public function get($key, $ressource=null, $default=false); 
     20     
     21    public function set($key, $value, $ressource=null); 
     22     
     23    public function unsetRessource($key, $ressource); 
     24 
     25} 
     26 
     27/** 
     28 * Main class to query the pref system, and to know value of a pref 
     29 * 
     30 * you should call this class (all method are static) when you want to know the 
     31 * value of a pref (on a specific ressource or not) 
     32 * @package jelix 
     33 * @subpackage pref 
     34 * @static 
     35 */ 
     36class jPref { 
     37 
     38    /** 
     39     * @internal The constructor is private, because all methods are static 
     40     */ 
     41    private function __construct (){ } 
     42 
     43    /** 
     44     * load the pref driver 
     45     * @return jIprefDriver 
     46     */ 
     47    protected static function _getDriver(){ 
     48        static $driver = null; 
     49        if($driver == null){ 
     50            global $gJConfig; 
     51            $db = strtolower($gJConfig->pref['driver']); 
     52            if(!isset($gJConfig->_pluginsPathList_pref)  
     53                || !isset($gJConfig->_pluginsPathList_pref[$db]) 
     54                || !file_exists($gJConfig->_pluginsPathList_pref[$db]) ){ 
     55                throw new jException('jelix~errors.pref.driver.notfound',$db); 
     56            } 
     57            require_once($gJConfig->_pluginsPathList_pref[$db].$db.'.pref.php'); 
     58            $dname = $gJConfig->pref['driver'].'PrefDriver'; 
     59            $driver = new $dname($gJConfig->pref); 
     60        } 
     61        return $driver; 
     62    } 
     63 
     64    public static function get($key, $ressource = null, $default=false) { 
     65        $dr = self::_getDriver(); 
     66        return $dr->get($key, $ressource, $default); 
     67    } 
     68     
     69    public static function set($key, $value, $ressource=null) { 
     70        $dr = self::_getDriver(); 
     71        return $dr->set($key, $value, $ressource); 
     72    } 
     73     
     74    public static function unsetRessource($key, $ressource) { 
     75        $dr = self::_getDriver(); 
     76        return $dr->unsetRessource($key, $ressource); 
     77    } 
     78 
     79} 
     80 
  • lib/jelix/pref/jPrefDb.class.php

    old new  
     1<?php 
     2/** 
     3* @package     jelix 
     4* @subpackage  pref 
     5* @author      Bastien Jaillot 
     6* @copyright   2008 Bastien Jaillot 
     7* @link        http://www.jelix.org 
     8* @licence     http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file 
     9* @since 1.1 
     10*/ 
     11 
     12 
     13/** 
     14 * Utility class for all classes used for the db driver of pref 
     15 * @package     jelix 
     16 * @subpackage  pref 
     17 * @static 
     18 */ 
     19class jPrefDb { 
     20 
     21    /** 
     22     * @internal The constructor is private, because all methods are static 
     23     */ 
     24    private function __construct (){ } 
     25 
     26    /** 
     27     * return the profil name used for pref connection 
     28     * @return string profil name 
     29     */ 
     30    public static function getProfil(){ 
     31        static $profil=''; 
     32        if($profil== ''){ 
     33            try{ 
     34                $prof = jDb::getProfil ('jpref_profil', true); 
     35            }catch(Exception $e){ 
     36                $prof = jDb::getProfil (); 
     37            } 
     38            $profil = $prof['name']; 
     39        } 
     40        return $profil; 
     41    } 
     42} 
  • lib/jelix/core-modules/jelix/locales/fr_FR/errors.ISO-8859-15.properties

    old new  
    111111 
    112112#---- datetime 
    113113datetime.invalid = (400)jDateTime: date/heure invalide (%d-%d-%d %d:%d:%d) 
     114 
     115#---- pref 
     116pref.driver.notfound = (410) Driver %s pour jPref non trouv� No newline at end of file 
  • lib/jelix/core-modules/jelix/locales/fr_FR/errors.ISO-8859-1.properties

    old new  
    111111 
    112112#---- datetime 
    113113datetime.invalid = (400)jDateTime: date/heure invalide (%d-%d-%d %d:%d:%d) 
     114 
     115#---- pref 
     116pref.driver.notfound = (410) Driver %s pour jPref non trouv� No newline at end of file 
  • lib/jelix/core-modules/jelix/locales/fr_FR/errors.UTF-8.properties

    old new  
    111111 
    112112#---- datetime 
    113113datetime.invalid = (400)jDateTime: date/heure invalide (%d-%d-%d %d:%d:%d) 
     114 
     115#---- pref 
     116pref.driver.notfound = (410) Driver %s pour jPref non trouvé 
  • lib/jelix/core-modules/jelix/daos/jpref_ressource.dao.xml

    old new  
     1<?xml version="1.0" encoding="UTF-8"?> 
     2<dao xmlns="http://jelix.org/ns/dao/1.0"> 
     3    <datasources> 
     4        <primarytable name="jlx_prefs_ressource" realname="jlx_prefs_ressource" primarykey="ressource,id_pref" /> 
     5    </datasources> 
     6    <record> 
     7 
     8 
     9         
     10    <property name="ressource" fieldname="ressource" datatype="string" required="true" maxlength="50"/> 
     11    <property name="id_pref" fieldname="id_pref" datatype="string" required="true" maxlength="100"/> 
     12    <property name="value" fieldname="value" datatype="text" default=""/> 
     13     
     14    </record> 
     15     
     16    <factory> 
     17      <method name="getByRessource" type="selectfirst"> 
     18          <parameter name="pref" /> 
     19          <parameter name="ressource" /> 
     20 
     21          <conditions> 
     22              <eq property="ressource" expr="$ressource" /> 
     23              <eq property="id_pref" expr="$pref" /> 
     24          </conditions> 
     25      </method> 
     26      <method name="deleteByRessource" type="delete"> 
     27          <parameter name="pref" /> 
     28          <parameter name="ressource" /> 
     29 
     30          <conditions> 
     31              <eq property="ressource" expr="$ressource" /> 
     32              <eq property="id_pref" expr="$pref" /> 
     33          </conditions> 
     34      </method> 
     35    </factory> 
     36</dao> 
  • lib/jelix/core-modules/jelix/daos/jpref.dao.xml

    old new  
     1<?xml version="1.0" encoding="UTF-8"?> 
     2<dao xmlns="http://jelix.org/ns/dao/1.0"> 
     3    <datasources> 
     4        <primarytable name="jlx_prefs" realname="jlx_prefs" primarykey="id_pref" /> 
     5    </datasources> 
     6    <record> 
     7 
     8 
     9         
     10    <property name="id_pref" fieldname="id_pref" datatype="string" required="true" maxlength="100"/> 
     11    <property name="value" fieldname="value" datatype="text" default=""/> 
     12    <property name="type" fieldname="type" datatype="string" required="true" default="string" maxlength="50"/> 
     13    <property name="label_key" fieldname="label_key" datatype="string" default="" maxlength="100"/> 
     14    <property name="r_acl_sujet" fieldname="r_acl_sujet" datatype="string" default="" maxlength="50"/> 
     15    <property name="w_acl_sujet" fieldname="w_acl_sujet" datatype="string" default="" maxlength="50"/> 
     16 
     17    </record> 
     18     
     19</dao> 
  • lib/jelix/core-modules/jelix/install/sql/install_jpref.schema.mysql.sql

    old new  
     1-- list of prefs 
     2DROP TABLE IF EXISTS `jlx_prefs`; 
     3CREATE TABLE `jlx_prefs` ( 
     4  `id_pref` varchar(100) NOT NULL default '', 
     5  `value` text, 
     6  `type` varchar(50) NOT NULL default 'string', 
     7  `label_key` varchar(100) default NULL, 
     8  -- `id_prefgrp` int(11) NOT NULL default '0', 
     9  `r_acl_sujet` varchar(50) default NULL, 
     10  `w_acl_sujet` varchar(50) default NULL, 
     11  PRIMARY KEY  (`id_pref`) 
     12) TYPE=MyISAM; 
     13 
     14 
     15-- list of prefs param by ressources 
     16DROP TABLE IF EXISTS `jlx_prefs_ressource`; 
     17CREATE TABLE `jlx_prefs_ressource` ( 
     18  `ressource` varchar(50) NOT NULL default '', 
     19  `id_pref` varchar(100) NOT NULL default '', 
     20  `value` text, 
     21  KEY `ressource` (`ressource`,`id_pref`) 
     22) TYPE=MyISAM; 
     23 
     24 
     25 
     26--  
     27-- -- Liste des groupes 
     28-- DROP TABLE IF EXISTS `jlx_prefs_values_group`; 
     29-- CREATE TABLE `jacl2_group` ( 
     30--   `id_prefgrp` int(11) NOT NULL auto_increment, 
     31--   `id_pref` varchar(100) NOT NULL default '', 
     32--   `order` tinyint(4) NOT NULL default '0', 
     33--   `label_key` varchar(100) default NULL, 
     34--   PRIMARY KEY  (`id_prefgrp`) 
     35-- ) TYPE=MyISAM AUTO_INCREMENT=1 ; 
     36-- 
Download in other formats: Original Format