ecom
E-commerce cms
 All Data Structures Namespaces Files Functions Variables
Config.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Entity;
4 
5 class Config extends ModelBase
6 {
7  private static $config = array();
8 
9  protected function install()
10  {
11  $dbPrefix = $this->getDbPrefix();
12  $result = self::$dbo->exec("CREATE TABLE IF NOT EXISTS `{$dbPrefix}config` (
13  `lang` VARCHAR(8) NULL,
14  `key` VARCHAR(64) NOT NULL,
15  `value` TEXT NULL,
16  UNIQUE(`lang`, `key`)
17  )");
18  if ($result === false)
19  throw new \Exception(get_class().": ".self::$dbo->errorInfo()[2]);
20  self::setConfig(null, "theme", "default");
21  return true;
22  }
23 
24  public static function setConfig($lang, $key, $value)
25  {
26  $fetcher = new self();
27  $data = $fetcher->selects(array("lang" => $lang, "key" => $key));
28  if (empty($data))
29  {
30  $data = new self();
31  $data->lang = $lang;
32  $data->key = $key;
33  $data->value = $value;
34  $data->save();
35  }
36  else
37  {
38  $data = $data[0];
39  $data->value = $value;
40  $data->save();
41  }
42  }
43 
44  public static function getConfig($lang =null, $key =null, $defaultValue =null)
45  {
46  $fetcher = new self();
47  $_lang = $lang;
48  if ($lang === null)
49  $_lang = "nolang";
50  if (isset(self::$config[$_lang]))
51  return isset(self::$config[$_lang][$key]) ? self::$config[$_lang][$key] : $defaultValue;
52  $values = $fetcher->selects(array("lang" => $lang));
53  foreach ($values as $i)
54  self::$config[$_lang][$i->key] = $i->value;
55  if ($key)
56  return (isset(self::$config[$_lang][$key]) ? self::$config[$_lang][$key] : $defaultValue);
57  return $defaultValue;
58  }
59 }
60 
static getConfig($lang=null, $key=null, $defaultValue=null)
Definition: Config.php:44
static setConfig($lang, $key, $value)
Definition: Config.php:24