Location: PHPKode > projects > EXtensible Production Suite (XPS) > xpsdev/core/controls/setting_control.php
<?php
class Setting_Control
{
	private $Setting;
    private $debug;

	public function __construct($debug=false)
	{
        $this->debug = $debug;
        if($debug) echo 'Setting_Control::__construct<br />';
		require_once( MODELS . '/setting.php' );
		$this->Setting = new Setting();
	}

	public function get_setting($id, $file_location='core')
	{
        if($this->debug) echo 'Setting_Control::get_setting($id='.$id.', $file_location='.$file_location.')<br />';
		return $this->Setting->get_setting($id, $file_location);
	}

    /*******************************************************
    * <p>get_settings</p>
    *
    * @access   public
    * @author     rennemannt <hide@address.com>
    * @param	array [$params] array of parameters.
    * @return	array settings([id]=>array(label, value, ref), [id]=>array(label, value, ref), ...).
    ********************************************************/
    public function get_settings($file_location='core')
	{
        $settings = array();
		$nodes = $this->Setting->get_settings($file_location);

		foreach($nodes as $node)
		{
			$settings[$node->getAttribute('id')] = array('label' => $node->getAttribute('label'),
                                                        'value' => $node->nodeValue,
                                                        'ref' => $node->getAttribute('ref'));
		}
		return $settings;
	}

    /*******************************************************
    * <p>get_setting_options gets the options for a setting</p>
    *
    * @access   public
    * @author     rennemannt <hide@address.com>
    * @param	$id the ID of the setting in settings.xml.
    * @return	array options([0]=>array(id, option_value, is_default), [1]=>array(id, option_value, is_default), ...) .
    ********************************************************/
    public function get_setting_options($params)
    {
        $setting_id = $params['id'];
        if(isset($params['file_location']) and ($params['file_location'] != ''))
        {
            $file_location = $params['file_location'];
        }
        else
        {
            $file_location = 'core';
        }
        $options = array();
        $i = 0;
        $setting_value_and_options = $this->Setting->get_setting_options($setting_id, $file_location);

        foreach($setting_value_and_options['setting_options'] as $node)
        {
            foreach($node->attributes as $attribute)
            {
                $options[$i][$attribute->name] = $attribute->value;
            }
            $options[$i]['value'] = $node->nodeValue;
            if(($setting_value_and_options['setting_value'] != '') and ($setting_value_and_options['setting_value'] == $options[$i]['option_value'])) $options[$i]['is_default'] = 1;
            $i++;
        }
        return $options;
    }

	public function set_setting($id, $value, $file_location)
	{
		return $this->Setting->set_setting($id, $value, $file_location);
	}

	public function list_settings($file_location='core')
	{
		$node_list = $this->Setting->list_settings($file_location);
		$return = array();

		if(($node_list->length < 1) or ($node_list === false)) return false;
		//need to convert the node list to an array for smarty to use
		foreach($node_list as $node)
		{
			$label_value = array('label' => $node->getAttribute('label'), 'value' => $node->nodeValue);
		 	$return[$node->getAttribute('id')] = $label_value;
		}
		return $return;
	}
}
?>
Return current item: EXtensible Production Suite (XPS)