Config.php 2.18 KB
Newer Older
1 2
<?php
namespace ACP3\Core;
3

4 5 6
use \ACP3\Core\Cache;

/**
7
 * Manages the various module settings
8 9 10
 *
 * @author Tino Goratsch
 */
11 12
abstract class Config {

13 14 15
	/**
	 * Gibt die Systemeinstellungen aus
	 */
16
	public static function getSystemSettings() {
17 18 19 20 21 22
		$settings = self::getSettings('system');
		foreach ($settings as $key => $value) {
			define('CONFIG_' . strtoupper($key), $value);
		}
		return;
	}
23

24 25 26 27 28 29 30
	/**
	 * Erstellt/Verändert die Konfigurationsdateien für die Module
	 *
	 * @param string $module
	 * @param array $data
	 * @return boolean
	 */
31
	public static function setSettings($module, $data) {
32
		$bool = $bool2 = false;
33
		$mod_id = Registry::get('Db')->fetchColumn('SELECT id FROM ' . DB_PRE . 'modules WHERE name = ?', array($module));
34 35
		if (!empty($mod_id)) {
			foreach ($data as $key => $value) {
36
				$bool = Registry::get('Db')->executeUpdate('UPDATE ' . DB_PRE . 'settings SET value = ? WHERE module_id = ? AND name = ?', array($value, (int) $mod_id, $key));
37 38 39 40 41 42
			}
			$bool2 = self::setModuleCache($module);
		}

		return $bool !== false && $bool2 !== false ? true : false;
	}
43

44 45 46 47 48 49
	/**
	 * Gibt den Inhalt der Konfigurationsdateien der Module aus
	 *
	 * @param string $module
	 * @return array
	 */
50
	public static function getSettings($module) {
51 52 53 54 55
		if (Cache::check($module, 'settings') === false)
			self::setModuleCache($module);

		return Cache::output($module, 'settings');
	}
56

57 58 59 60 61 62
	/**
	 * Setzt den Cache für die Einstellungen eines Moduls
	 *
	 * @param string $module
	 * @return boolean
	 */
63
	private static function setModuleCache($module) {
64
		$settings = Registry::get('Db')->executeQuery('SELECT s.name, s.value FROM ' . DB_PRE . 'settings AS s JOIN ' . DB_PRE . 'modules AS m ON(m.id = s.module_id) WHERE m.name = ?', array($module))->fetchAll();
65 66 67 68 69 70 71 72 73 74 75 76 77 78
		$c_settings = count($settings);

		$cache_ary = array();
		for ($i = 0; $i < $c_settings; ++$i) {
			if (is_int($settings[$i]['value']))
				$cache_ary[$settings[$i]['name']] = (int) $settings[$i]['value'];
			elseif (is_float($settings[$i]['value']))
				$cache_ary[$settings[$i]['name']] = (float) $settings[$i]['value'];
			else
				$cache_ary[$settings[$i]['name']] = $settings[$i]['value'];
		}

		return Cache::create($module, $cache_ary, 'settings');
	}
79

80
}