common functions

public function get_user_meta($userID,$metakey){
$this->db->where(['user_id'=>$userID,'key'=>$metakey]);
$query = $this->db->get('user_meta');
if($query->num_rows()>0){
$row = $query->row();
return is_serial($row->value) ? unserialize($row->value) : $row->value ;
}
}

public function update_user_meta($userID,$metakey,$metavalue){
$this->db->where(['user_id'=>$userID,'key'=>$metakey]);
$query = $this->db->get('user_meta');
$metavalue = is_array($metavalue) ? serialize($metavalue) : $metavalue;
if($query->num_rows()>0){
$this->db->update('user_meta',['value'=>$metavalue],
'user_id'=>$userID,'key'=>$metakey]);
$row = $query->row();
return $row->id;
}else{
$this->db->insert('user_meta',['value'=>$metavalue,'user_id'=>$userID,'key'=>$metakey]);
return $this->db->insert_id();
}
}

public function get_option($key){
$this->db->where(['key'=>$key]);
$query = $this->db->get('options');
if($query->num_rows()>0){
$row = $query->row();
return is_serial($row->values) ? unserialize($row->values) : $row->values ;
}
return false;
}

public function set_option($key,$value){
$value = is_array($value) ? serialize($value) : $value;
if($this->get_option($key)){
$this->db->update('options',['values'=>$value],['key'=>$key]);
return true;
}else{
$this->db->insert('options',['values'=>$value,'key'=>$key]);
return $this->db->insert_id();
}

Comments

Popular posts from this blog

Blogger post using PHP API

Pin payment laravel

zoom image on mouse over