2013-04-14 22:42:40 +03:00
|
|
|
<?php
|
2013-04-20 20:20:16 +03:00
|
|
|
class Settings_Model extends CI_Model {
|
2013-05-04 00:26:04 +03:00
|
|
|
/**
|
|
|
|
* Class Constructor
|
|
|
|
*/
|
2013-04-20 20:20:16 +03:00
|
|
|
function __construct() {
|
2013-04-14 22:42:40 +03:00
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-05-04 00:26:04 +03:00
|
|
|
* Get setting value from database.
|
|
|
|
*
|
2013-04-14 22:42:40 +03:00
|
|
|
* This method returns a system setting from the
|
|
|
|
* database.
|
|
|
|
*
|
|
|
|
* @param string $name The database setting name.
|
|
|
|
* @return string Returns the database value for
|
|
|
|
* the selected setting.
|
|
|
|
*/
|
2013-05-04 00:26:04 +03:00
|
|
|
function get_setting($name) {
|
2013-04-14 22:42:40 +03:00
|
|
|
$query = $this->db->get_where('ea_settings', array('name' => $name));
|
|
|
|
$setting = ($query->num_rows() > 0) ? $query->row() : '';
|
|
|
|
return $setting->value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method sets the value for a specific setting
|
|
|
|
* on the database. If the setting doesn't exist, it
|
|
|
|
* is going to be created, otherwise updated.
|
|
|
|
*
|
|
|
|
* @param string $name The setting name.
|
|
|
|
* @param type $value The setting value.
|
|
|
|
* @return bool Returns the operation success - failure
|
|
|
|
* result.
|
|
|
|
*/
|
2013-05-04 00:26:04 +03:00
|
|
|
function set_setting($name, $value) {
|
2013-04-14 22:42:40 +03:00
|
|
|
$query = $this->db->get_where('ea_settings', array('name' => $name));
|
|
|
|
if ($query->num_rows() > 0) {
|
|
|
|
// Update setting
|
2013-05-04 00:26:04 +03:00
|
|
|
$update_data = array('value' => $value);
|
2013-04-14 22:42:40 +03:00
|
|
|
$this->db->where('name', $name);
|
2013-05-04 00:26:04 +03:00
|
|
|
$result = $this->db->update('ea_settings', $update_data);
|
2013-04-14 22:42:40 +03:00
|
|
|
} else {
|
|
|
|
// Insert setting
|
2013-05-04 00:26:04 +03:00
|
|
|
$insert_data = array(
|
|
|
|
'name' => $name,
|
2013-04-14 22:42:40 +03:00
|
|
|
'value' => $value
|
|
|
|
);
|
2013-05-04 00:26:04 +03:00
|
|
|
$result = $this->db->insert('ea_settings', $insert_data);
|
2013-04-14 22:42:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
}
|
2013-05-04 00:26:04 +03:00
|
|
|
|
|
|
|
|
|
|
|
/* End of file settings_model.php */
|
|
|
|
/* Location: ./application/models/settings_model.php */
|