Cheetah
ChWsbParams.php
Go to the documentation of this file.
1 <?php
2 
8 require_once(CH_DIRECTORY_PATH_CLASSES . 'ChWsbCacheFile.php');
9 
11 {
15  public $_oDb;
16  public $_oCache;
17  public $_sCacheFile;
18  public $_aParams;
19 
23  function __construct($oDb)
24  {
25  global $site;
26 
27  $this->_oDb = $oDb;
28  $this->_sCacheFile = 'sys_options_' . md5($site['ver'] . $site['build'] . $site['url']) . '.php';
29 
30  // feel free to change to another cache system if you are sure that it is available
31  $this->_oCache = new ChWsbCacheFile();
32  $this->_aParams = $this->_oCache->getData($this->_sCacheFile);
33 
34  if (empty($this->_aParams) && $this->_oDb != null)
35  $this->cache();
36  }
37 
38  function isInCache($sKey)
39  {
40  return isset($this->_aParams[$sKey]);
41  }
42 
43  function get($sKey, $bFromCache = true)
44  {
45  if (!$sKey)
46  return false;
47  if ($bFromCache && $this->isInCache($sKey))
48  return $this->_aParams[$sKey];
49  else
50  return $this->_oDb->getOne("SELECT `VALUE` FROM `sys_options` WHERE `Name`= ? LIMIT 1", [$sKey]);
51  }
52 
53  function set($sKey, $mixedValue)
54  {
55  //--- Update Database ---//
56  $this->_oDb->query("UPDATE `sys_options` SET `VALUE`= ? WHERE `Name`= ? LIMIT 1", [$mixedValue, $sKey]);
57 
58  //--- Update Cache ---//
59  $this->cache();
60 
61  // set param alert
62  $oAlert = new ChWsbAlerts('system', 'set_param', 0, 0, array('name' => $sKey, 'value' => $mixedValue));
63  $oAlert->alert();
64  }
65 
66  function cache()
67  {
68  $this->_aParams = $this->_oDb->getPairs("SELECT `Name`, `VALUE` FROM `sys_options`", "Name", "VALUE");
69  if (empty($this->_aParams)) {
70  $this->_aParams = array ();
71  return false;
72  }
73 
74  return $this->_oCache->setData($this->_sCacheFile, $this->_aParams);
75  }
76 
77  function clearCache()
78  {
79  $this->_oCache->delData($this->_sCacheFile);
80  }
81 }
ChWsbParams\isInCache
isInCache($sKey)
Definition: ChWsbParams.php:38
ChWsbParams\$_aParams
$_aParams
Definition: ChWsbParams.php:18
ChWsbParams\__construct
__construct($oDb)
Definition: ChWsbParams.php:23
$oAlert
$oAlert
Definition: embed.php:15
ChWsbParams
Definition: ChWsbParams.php:11
ChWsbParams\clearCache
clearCache()
Definition: ChWsbParams.php:77
php
ChWsbParams\$_oDb
$_oDb
Definition: ChWsbParams.php:15
ChWsbAlerts
Definition: ChWsbAlerts.php:39
ChWsbParams\cache
cache()
Definition: ChWsbParams.php:66
$site
$site['ver']
Definition: version.inc.php:8
$oDb
global $oDb
Definition: db.inc.php:39
ChWsbParams\$_sCacheFile
$_sCacheFile
Definition: ChWsbParams.php:17
global
if(!defined("GLOBAL_MODULE")) define("GLOBAL_MODULE" global
Definition: header.inc.php:25
ChWsbParams\$_oCache
$_oCache
Definition: ChWsbParams.php:16
empty
Attr AllowedRel this is empty
Definition: Attr.AllowedRel.txt:7