*/ class Setting extends CI_Model { /** * Calls the parent constructor. */ public function __construct() { parent::__construct(); } /** * * @param string $name * @param string $value */ public function set($name, $value) { $this->db->where('name', $name)->update('settings', array('value' => $value)); if ($this->db->where('name', $name)->count_all_results('settings') == 0) { $this->create(array('name' => $name, 'value' => $value)); } } /** * * @param string $name */ public function get($name) { return $this->db->get_where('settings', array('name' => $name))->row()->value; } /** * Creates a new settings entry. * * @param array $data * @return boolean Returns TRUE on success. */ public function create($data = array()) { do { // generate unique hash $data['id'] = random_hash(); } while ($this->db->where('id', $data['id'])->from('settings')->count_all_results() > 0); $this->db->insert('settings', $data); return $this->db->affected_rows() == 1; } /** * Updates all settings. * * @param array $data * @return boolean Returns TRUE on success. */ public function update($data = array()) { foreach ($data as $name => $value) { $this->set($name, $value); } return true; } } /* End of file setting.php */ /* Location: ./application/models/setting.php */