fixed last remaining function calls which are class-methods now
Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
@@ -32,23 +32,10 @@ use Froxlor\Database\Database;
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package Classes
|
||||
*
|
||||
* @method static mixed Get ($setting = null) return a setting-value by its group and varname separated by a dot (group.varname)
|
||||
* @method static boolean Set ($setting = null, $value = null, $instant_save = true) update a setting / set a new value
|
||||
* @method static boolean IsInList ($setting = null, $entry = null) tests if a setting-value that i s a comma separated list contains an entry
|
||||
* @method static boolean AddNew ($setting = null, $value = null) add a new setting to the database (mainly used in updater)
|
||||
* @method static boolean Flush () Store all un-saved changes to the database and re-read in all settings
|
||||
* @method static void Stash () forget all un-saved changes to settings
|
||||
*/
|
||||
class Settings
|
||||
{
|
||||
|
||||
/**
|
||||
* current settings object
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
private static $_obj = null;
|
||||
|
||||
/**
|
||||
* settings data
|
||||
*
|
||||
@@ -74,27 +61,30 @@ class Settings
|
||||
/**
|
||||
* private constructor, reads in all settings
|
||||
*/
|
||||
private function __construct()
|
||||
private static function init()
|
||||
{
|
||||
$this->_readSettings();
|
||||
self::$_updatedata = array();
|
||||
// prepare statement
|
||||
self::$_updstmt = Database::prepare("
|
||||
if (empty(self::$_data)) {
|
||||
self::_readSettings();
|
||||
self::$_updatedata = array();
|
||||
|
||||
// prepare statement
|
||||
self::$_updstmt = Database::prepare("
|
||||
UPDATE `" . TABLE_PANEL_SETTINGS . "` SET `value` = :value
|
||||
WHERE `settinggroup` = :group AND `varname` = :varname
|
||||
");
|
||||
");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read in all settings from the database
|
||||
* and set the internal $_data array
|
||||
*/
|
||||
private function _readSettings()
|
||||
private static function _readSettings()
|
||||
{
|
||||
$result_stmt = Database::query("
|
||||
SELECT `settingid`, `settinggroup`, `varname`, `value`
|
||||
FROM `" . TABLE_PANEL_SETTINGS . "`
|
||||
");
|
||||
SELECT `settingid`, `settinggroup`, `varname`, `value`
|
||||
FROM `" . TABLE_PANEL_SETTINGS . "`
|
||||
");
|
||||
self::$_data = array();
|
||||
while ($row = $result_stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
self::$_data[$row['settinggroup']][$row['varname']] = $row['value'];
|
||||
@@ -127,8 +117,9 @@ class Settings
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function pGet($setting = null)
|
||||
public function Get($setting = null)
|
||||
{
|
||||
self::init();
|
||||
$sstr = explode(".", $setting);
|
||||
// no separator - do'h
|
||||
if (! isset($sstr[1])) {
|
||||
@@ -151,9 +142,10 @@ class Settings
|
||||
*
|
||||
* @return boolean true, if the list contains $entry
|
||||
*/
|
||||
public function pIsInList($setting = null, $entry = null)
|
||||
public function IsInList($setting = null, $entry = null)
|
||||
{
|
||||
$s = Settings::Get($setting);
|
||||
self::init();
|
||||
$s = self::Get($setting);
|
||||
if ($s == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -171,10 +163,11 @@ class Settings
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pSet($setting = null, $value = null, $instant_save = true)
|
||||
public function Set($setting = null, $value = null, $instant_save = true)
|
||||
{
|
||||
self::init();
|
||||
// check whether the setting exists
|
||||
if (Settings::Get($setting) !== null) {
|
||||
if (self::Get($setting) !== null) {
|
||||
// set new value in array
|
||||
$sstr = explode(".", $setting);
|
||||
if (! isset($sstr[1])) {
|
||||
@@ -183,7 +176,7 @@ class Settings
|
||||
self::$_data[$sstr[0]][$sstr[1]] = $value;
|
||||
// should we store to db instantly?
|
||||
if ($instant_save) {
|
||||
$this->_storeSetting($sstr[0], $sstr[1], $value);
|
||||
self::_storeSetting($sstr[0], $sstr[1], $value);
|
||||
} else {
|
||||
// set temporary data for usage
|
||||
if (! isset(self::$_data[$sstr[0]]) || ! is_array(self::$_data[$sstr[0]])) {
|
||||
@@ -210,11 +203,11 @@ class Settings
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function pAddNew($setting = null, $value = null)
|
||||
public function AddNew($setting = null, $value = null)
|
||||
{
|
||||
|
||||
self::init();
|
||||
// first check if it doesn't exist
|
||||
if (Settings::Get($setting) === null) {
|
||||
if (self::Get($setting) === null) {
|
||||
// validate parameter
|
||||
$sstr = explode(".", $setting);
|
||||
if (! isset($sstr[1])) {
|
||||
@@ -244,19 +237,20 @@ class Settings
|
||||
* Store all un-saved changes to the database and
|
||||
* re-read in all settings
|
||||
*/
|
||||
public function pFlush()
|
||||
public static function Flush()
|
||||
{
|
||||
self::init();
|
||||
if (is_array(self::$_updatedata) && count(self::$_updatedata) > 0) {
|
||||
// save all un-saved changes to the settings
|
||||
foreach (self::$_updatedata as $group => $vargroup) {
|
||||
foreach ($vargroup as $varname => $value) {
|
||||
$this->_storeSetting($group, $varname, $value);
|
||||
self::_storeSetting($group, $varname, $value);
|
||||
}
|
||||
}
|
||||
// now empty the array
|
||||
self::$_updatedata = array();
|
||||
// re-read in all settings
|
||||
return $this->_readSettings();
|
||||
return self::_readSettings();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -264,50 +258,13 @@ class Settings
|
||||
/**
|
||||
* forget all un-saved changes to settings
|
||||
*/
|
||||
public function pStash()
|
||||
public static function Stash()
|
||||
{
|
||||
self::init();
|
||||
// empty update array
|
||||
self::$_updatedata = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* create new object and return instance
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
private static function getInstance()
|
||||
{
|
||||
// do we got an object already?
|
||||
if (self::$_obj == null) {
|
||||
self::$_obj = new self();
|
||||
}
|
||||
// return it
|
||||
return self::$_obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* let's us interact with the settings-Object by using static
|
||||
* call like "Settings::function()"
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $args
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function __callStatic($name, $args)
|
||||
{
|
||||
// as our functions are not static and therefore cannot
|
||||
// be called statically, we prefix a 'p' to all of
|
||||
// our public functions so we can use Settings::functionname()
|
||||
// which looks cooler and is easier to use
|
||||
$callback = array(
|
||||
self::getInstance(),
|
||||
"p" . $name
|
||||
);
|
||||
$result = call_user_func_array($callback, $args);
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function loadSettingsInto(&$settings_data)
|
||||
{
|
||||
if (is_array($settings_data) && isset($settings_data['groups']) && is_array($settings_data['groups'])) {
|
||||
|
||||
Reference in New Issue
Block a user