Ticket #237: jpref.diff

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

    old new  
    9898   jacl2subject.dao.xml 
    9999   jacl2usergroup.dao.xml 
    100100   jacl2groupsofuser.dao.xml 
     101   jpref.dao.xml 
     102   jpref_ressource.dao.xml 
    101103cd lib/jelix/core-modules/jelix/install/sql 
    102104  delete.mysql.sql 
    103105  install_jacl.schema.mysql.sql 
     
    110112  install_jacl.data.pgsql.sql 
    111113  install_jacl2.schema.pgsql.sql 
    112114  install_jacl2.data.pgsql.sql 
     115  install_jpref.data.pgsql.sql 
     116  install_jpref.schema.mysql.sql 
     117  install_jpref.data.mysql.sql 
     118  install_jpref.schema.pgsql.sql 
    113119  install_jsession.schema.pgsql.sql 
    114120 
    115121cd lib/jelix/core-modules/jelix/locales/en_US 
     
    422428  class.auth.php 
    423429cd lib/jelix/plugins/auth/lds 
    424430  lds.auth.php 
     431cd lib/jelix/plugins/pref/db 
     432  db.pref.php 
    425433 
    426434cd lib/jelix/plugins/coord/magicquotes 
    427435! magicquotes.coord.php 
     
    500508  function.cycle_init.php 
    501509  function.cycle.php 
    502510  function.cycle_reset.php 
     511  function.jpref.php 
    503512  modifier.cat.php 
    504513  modifier.count_array.php 
    505514  modifier.count_characters.php 
     
    573582cd lib/jelix/plugins/urls/simple 
    574583  simple.urls.php 
    575584 
     585 
     586cd lib/jelix/pref 
     587  jPref.class.php 
     588  jPrefDb.class.php 
     589 
    576590cd lib/jelix-www/design 
    577591  jelix.css 
    578592  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 
     24    public function get($key, $ressource=null, $default=false) { 
     25         
     26        if (!$default && isset($ressource) && $dao = jDao::get('jelix~jpref_ressource', jPrefDb::getProfil()) ) { 
     27            $daorec = $dao->getByRessource($key, $ressource); 
     28        } 
     29        else { 
     30            $dao = jDao::get('jelix~jpref', jPrefDb::getProfil()); 
     31            $daorec = $dao->get($key); 
     32        } 
     33 
     34        return $daorec->value; 
     35    } 
     36     
     37    public function set($key, $value, $ressource=null) { 
     38        $dao = jDao::get('jelix~jpref', jPrefDb::getProfil()); 
     39         
     40        if($daorec = $dao->get($key)) { 
     41            $toInsert = false; 
     42        }else{ 
     43            $daorec = jDao::createRecord('jelix~jpref', jPrefDb::getProfil()); 
     44            $toInsert= true; 
     45        } 
     46                 
     47        $daorec->id_pref = $key; 
     48        $daorec->value = $value; 
     49        if ($toInsert) 
     50            $dao->insert($daorec); 
     51        else $dao->update($daorec); 
     52    } 
     53 
     54} 
     55 
  • lib/jelix/core/defaultconfig.ini.php

    old new  
    208208driver = db 
    209209enableAclDbEventListener = off 
    210210 
     211[pref] 
     212driver = db 
    211213 
    212214[sessions] 
    213215; 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} 
     24 
     25/** 
     26 * Main class to query the pref system, and to know value of a pref 
     27 * 
     28 * you should call this class (all method are static) when you want to know the 
     29 * value of a pref (on a specific ressource or not) 
     30 * @package jelix 
     31 * @subpackage pref 
     32 * @static 
     33 */ 
     34class jPref { 
     35 
     36    /** 
     37     * @internal The constructor is private, because all methods are static 
     38     */ 
     39    private function __construct (){ } 
     40 
     41    /** 
     42     * load the pref driver 
     43     * @return jIprefDriver 
     44     */ 
     45    protected static function _getDriver(){ 
     46        static $driver = null; 
     47        if($driver == null){ 
     48            global $gJConfig; 
     49            $db = strtolower($gJConfig->pref['driver']); 
     50            if(!isset($gJConfig->_pluginsPathList_pref)  
     51                || !isset($gJConfig->_pluginsPathList_pref[$db]) 
     52                || !file_exists($gJConfig->_pluginsPathList_pref[$db]) ){ 
     53                throw new jException('jelix~errors.pref.driver.notfound',$db); 
     54            } 
     55            require_once($gJConfig->_pluginsPathList_pref[$db].$db.'.pref.php'); 
     56            $dname = $gJConfig->pref['driver'].'PrefDriver'; 
     57            $driver = new $dname($gJConfig->pref); 
     58        } 
     59        return $driver; 
     60    } 
     61 
     62    public static function get($key, $ressource = null, $default=false) { 
     63        $dr = self::_getDriver(); 
     64        return $dr->get($key, $ressource, $default); 
     65    } 
     66     
     67    public static function set($key, $value, $ressource=null) { 
     68        $dr = self::_getDriver(); 
     69        return $dr->set($key, $value, $ressource); 
     70    } 
     71 
     72} 
     73 
  • 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.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/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/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    </factory> 
     27</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