Location: PHPKode > projects > EXtensible Production Suite (XPS) > xpsdev/core/models/setting.php
<?php
class Setting
{
	public function __construct(){}

	/****************************************************************
	* <p>gets settings</p>
	*
	* @access   private
	* @author 	heidtc < hide@address.com >
	* @param	$id the identification value of the setting
	* @return	config value
	****************************************************************/
	public function get_setting($id, $file_location)
	{
		$dom = new DOMDocument;
		$dom->preserveWhiteSpace = false;

		if($file_location == 'core')
		{
			$dom->load( CONFIGS . '/settings.xml');
		}
		else
		{
			$dom->load( MODULES . '/' . $file_location . '/configs/settings.xml');
		}

		$xpath = new DOMXPath($dom);

		$config_node = $xpath->query('//setting[@id="'.$id.'"]');

		if(count($config_node) > 0)
		{
			$config_value = $config_node->item(0)->nodeValue;
			return $config_value;
		}
		else
		{
		 	return false;
		}
	}

	public function set_setting($id, $value, $file_location)
	{
		$dom = new DOMDocument;
		$dom->preserveWhieSpace = true;
		if($file_location == 'core')
		{
			$dom->load( CONFIGS . '/settings.xml');
		}
		else
		{
			$dom->load( MODULES . '/' . $file_location . '/configs/settings.xml');
		}
		$xpath = new DOMXPath($dom);

		$config_node = $xpath->query('//setting[@id="'.$id.'"]');

		if($config_node->length > 0)
		{
			$config_node->item(0)->nodeValue = $value;
			if($file_location == 'core')
			{
				return $dom->save( CONFIGS . '/settings.xml');
			}
			else
			{
				return $dom->save( MODULES . '/' . $file_location . '/configs/settings.xml');
			}
		}

	 	else
	 	{
	 		return false;
	 	}
	}

	public function list_settings($file_location='core')
	{
		$dom = new DOMDocument;
		$dom->preserveWhiteSpace = false;
		if($file_location == 'core')
		{
			$dom->load(CONFIGS . '/settings.xml');
	 	}
		else
		{
		 	$dom->load(MODULES . '/' . $file_location . '/configs/settings.xml');
		}

		$xpath = new DOMXPath($dom);
		$settings = $xpath->query('//settings/*[@label]');

		if($settings->length > 0)
		{
			return $settings;
		}
		else
		{
			return false;
		}

	}

    /*******************************************************
    * <p>get_settings</p>
    *
    * @access   public
    * @author     rennemannt <hide@address.com>
    * @param	$file_location location of the settings.xml file.
    * @return	nodes.
    *******************************************************/
    public function get_settings($file_location='core')
	{
		$dom = new DOMDocument;
		$dom->preserveWhiteSpace = false;
        if($file_location == 'core')
		{
			$dom->load(CONFIGS . '/settings.xml');
	 	}
		else
		{
		 	$dom->load(MODULES . '/' . $file_location . '/configs/settings.xml');
		}
		$xpath = new DOMXPath($dom);

		return $xpath->query('//settings/*[@label]');
	}

    /*******************************************************
    * <p>get_setting_options</p>
    *
    * @access   public
    * @author     rennemannt <hide@address.com>
    * @param	$setting_id ID of the setting in settings.xml.
    * @param	$file_location location of the settings.xml file.
    * @return	nodes.
    *******************************************************/
    public function get_setting_options($setting_id, $file_location='core')
    {
        $dom = new DOMDocument;
		$dom->preserveWhiteSpace = false;

        if($file_location == 'core')
		{
			$dom->load(CONFIGS . '/settings.xml');
	 	}
		else
		{
		 	$dom->load(MODULES . '/' . $file_location . '/configs/settings.xml');
		}
		$xpath = new DOMXPath($dom);
        $nodes = $xpath->query('//setting[@id="' . $setting_id . '"]');
        $options = $xpath->query('//setting[@id="' . $nodes->item(0)->getAttribute('ref') . '"]');
        $setting_value_and_options = array('setting_value' => $nodes->item(0)->nodeValue,
                                                        'setting_options' => $options);

		return $setting_value_and_options;
    }
}
?>
Return current item: EXtensible Production Suite (XPS)