All Data Structures Namespaces Files Functions Variables
Config.php
Go to the documentation of this file.
<?php
namespace Entity;
class Config extends ModelBase
{
private static $config = array();
protected function install()
{
$dbPrefix = $this->getDbPrefix();
$result = self::$dbo->exec("CREATE TABLE IF NOT EXISTS `{$dbPrefix}config` (
`lang` VARCHAR(8) NULL,
`key` VARCHAR(64) NOT NULL,
`value` TEXT NULL,
UNIQUE(`lang`, `key`)
)");
if ($result === false)
throw new \Exception(get_class().": ".self::$dbo->errorInfo()[2]);
return true;
}
public static function setConfig($lang, $key, $value)
{
$fetcher = new self();
$data = $fetcher->selects(array("lang" => $lang, "key" => $key));
if (empty($data))
{
$data = new self();
$data->lang = $lang;
$data->key = $key;
$data->value = $value;
$data->save();
}
else
{
$data = $data[0];
$data->value = $value;
$data->save();
}
}
public static function getConfig($lang =null, $key =null, $defaultValue =null)
{
$fetcher = new self();
if (isset(self::$config[$lang]))
return;
$values = $fetcher->selects(array("lang" => $lang));
foreach ($values as $i)
self::$config[$lang][$i->key] = $i->value;
if ($key)
return (isset(self::$config[$lang][$key]) ? self::$config[$lang][$key] : $defaultValue);
return $defaultValue;
}
}
Entity
Definition: Address.php:3
Entity\Config\getConfig
static getConfig($lang=null, $key=null, $defaultValue=null)
Definition: Config.php:43
Entity\Config\install
install()
Definition: Config.php:9
Entity\ModelBase
Definition: ModelBase.php:5
Entity\Config
Definition: Config.php:5
Entity\Config\setConfig
static setConfig($lang, $key, $value)
Definition: Config.php:23