Main Page | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

JConfig.class.php

Go to the documentation of this file.
00001 <?php
00006 include_once("core/system/JBaseObject.class.php");
00007 include_once("core/config/ConfigCache.class.php");
00008 
00009 /* constants */
00010 define(CONFIG_SYSTEM_SCOPE, 0);
00011 define(CONFIG_MODULE_SCOPE, 1);
00012 
00020 class JConfig extends JBaseObject
00021 {
00022         var $scope;     
00023         var $idU;       
00024         var $idG;       
00025         var $idM;       
00026         
00027         var $config;    
00028         
00037         function JConfig($scope=CONFIG_SYSTEM_SCOPE, $id=0)
00038         {
00039                 $this->scope = $scope;
00040                 $this->idM = $id;
00041                 
00042                 $currentUser =& JSystem::GetCurrentUser();
00043                 if (JSystem::IsError($currentUser))
00044                         $this->idU = null;
00045                 else
00046                         $this->idU = $currentUser->GetId();
00047                 
00048                 $currentGroup =& JSystem::GetCurrentGroup();
00049                 if (JSystem::IsError($currentGroup))
00050                         $this->idG = null;
00051                 else
00052                 {
00053                         if (!is_subclass_of($currentGroup, "Group"))
00054                                 $this->idG = GLOBAL_GROUP;
00055                         else
00056                                 $this->idG = $currentGroup->GetId();
00057                 }
00058                 
00059                 $this->config = array();
00060                 
00061                 $this->_UpdateData();
00062         }
00063         
00067         function _UpdateData()
00068         {
00069                 $cache =& ConfigCache::GetInstance();
00070         
00071                 // We create the petitions to the cache.        
00072                 $systemPetition = new ConfigPetition();
00073                 
00074                 // Set the scope.
00075                 if ($this->scope == CONFIG_MODULE_SCOPE)
00076                 {
00077                         $systemPetition->SetModule($this->idM);
00078                 }
00079         
00080                 // Get the system information
00081                 $system = $cache->GetPetition($systemPetition);
00082                 
00083                 // And get the user information
00084                 if ($this->idU != null)
00085                 {
00086                         $systemPetition->SetUser($this->idU);
00087                         $systemUser = $cache->GetPetition($systemPetition);
00088                 }
00089                 else
00090                 {
00091                         $systemUser = array();
00092                 }
00093                 
00094                 // Do the same with the group config
00095                 if ($this->idG != null)
00096                 {
00097                         $groupPetition = new ConfigPetition();
00098                         
00099                         // Set the group.
00100                         $groupPetition->SetGroup($this->idG);
00101                         
00102                         if ($this->scope == CONFIG_MODULE_SCOPE)
00103                                 $groupPetition->SetModule($this->idM);
00104                 
00105                         $group = $cache->GetPetition($groupPetition);
00106                         if ($this->idU != null)
00107                         {
00108                                 $groupPetition->SetUser($this->idU);            
00109                                 $groupUser = $cache->GetPetition($groupPetition);
00110                         }
00111                         else
00112                                 $groupUser = array();
00113                 }
00114                 else
00115                 {
00116                         $group = array();
00117                         $groupUser = array();
00118                 }
00119                 
00120                 // Finally, we merge them. Depending on this merge, a config
00121                 // value will have priority over another.
00122                 $this->config = array_merge($system, $group, 
00123                                                                 $systemUser, $groupUser);
00124         }
00125         
00126         function &GetInstance($scope=CONFIG_SYSTEM_SCOPE, $id=0)
00127         {
00128                 static $objs;
00129                 
00130                 if (!isset($objs[$scope][$id]))
00131                 {
00132                         $objs[$scope][$id] = new JConfig($scope, $id);
00133                 }
00134                 
00135                 return $objs[$scope][$id];
00136         }
00137         
00138         function GetKeys()
00139         {
00140                 return array_keys($this->config);
00141         }
00142         
00143         function GetKeysValues()
00144         {
00145                 return $this->config;
00146         }
00147         
00148         function GetValue($key, $default=null)
00149         {
00150                 if (array_key_exists($key, $this->config))
00151                         return $this->config[$key];
00152                 else
00153                         return $default;
00154         }
00155         
00156         function SetValue($keys, $user=true, $group=false)
00157         {
00158                 $cache =& ConfigCache::GetInstance();
00159         
00160                 // We create the petitions to the cache.        
00161                 $petition = new ConfigPetition();
00162                 if ($user)
00163                         $petition->SetUser($this->idU);
00164                 if ($group)
00165                         $petition->SetGroup($this->idG);
00166                 if ($this->scope == CONFIG_MODULE_SCOPE)
00167                         $petition->SetModule($this->idM);
00168 
00169                 $cache->SetPetition($petition, $keys);
00170                 
00171                 $this->_UpdateData();
00172         }       
00173         
00174 }
00175 ?>

Generated on Wed Nov 19 20:29:34 2003 for James by doxygen 1.3.4