option = $this; $CI->config->load('application', TRUE); $this->_config = $CI->config->item('option', 'application'); $this->DB =& $CI->db; $this->_is_enabled(); $this->_cache_all(); } /** * @access private * @return void */ private function _is_enabled() { $test = array ('table', 'attribute', 'value'); $invalid = FALSE; $config = $this->_config; if ($config['enable'] === TRUE) { foreach ($test as $value) { if (trim($config[$value]) === '') { $invalid = TRUE; } } $this->_enabled = ($invalid === FALSE ? TRUE : FALSE); } else { $this->_enabled = FALSE; } } /** * load all values from database * @access private * @return void */ private function _cache_all() { $config = $this->_config; if ($this->_enabled === TRUE) { $this->DB->select($config['attribute']); $this->DB->select($config['value']); $this->DB->from($config['table']); $query = $this->DB->get(); foreach ($query->result_array() as $row) { $this->_data[$row[$config['attribute']]] = $row[$config['value']]; } } } /** * * @param string $name [optional] * @return string */ public function get($name = '') { if ( ! isset($this->_data[$name])) { return FALSE; } else { return $this->_data[$name]; } } /** * * @param string $name [optional] * @param string $value [optional] * @return void */ public function update($name = '', $value = '') { $data = array(); $config = $this->_config; if ($this->_enabled === TRUE && trim($name) !== '') { $data[$config['value']] = $value; if ( ! isset($this->_data[$name])) { $data[$config['attribute']] = $name; $this->DB->insert($config['table'], $data); } else { $this->DB->where($config['attribute'], $name); $this->DB->update($config['table'], $data); } $this->_data[$name] = $value; } } /** * * @param string $name [optional] * @return */ public function delete($name = '') { $config = $this->_config; if ($this->_enabled === TRUE && trim($name) !== '') { $this->DB->where($config['attribute'], $name); $this->DB->delete($config['table']); $this->_data[$name] = FALSE; } } }