<commit_before><commit_msg>Tambah model untuk visitor thread<commit_after><?php

class Model_visitor extends CI_Model
{

    public function saveVisitor($data)
    {
            $dataWhere = array(
                'thread'     => $data['thread'],
                'ip_address' => $data['ip_address'],
                'access_url' => $data['access_url'],
                'user_id'    => $data['user_id']
            );

        $check = $this->db->get_where('visitors',$dataWhere)->result();
        if(count($check)>0){
            foreach($check as $c){
                $dataUpdate = array(
                    'times'      => $c->times+1,
                    'updated_at' => date('Y-m-d').' '.date('G:i:s')
                );
            }
            $data = array_merge($data,$dataUpdate);
            $save = $this->incrementTimes($dataWhere,$data);
        }else{
            $data = array_merge($data,array('times'=>1));
            $save = $this->newVisitor($data);
        }

        return $save;
    }

    public function incrementTimes($dataWhere, $data)
    {
        $this->db->where($dataWhere);
        $update = $this->db->update('visitors',$data);
        if($update){
            return TRUE;
        }else{
            return FALSE;
        }
    }

    public function newVisitor($data)
    {        
        $insert = $this->db->insert('visitors',$data);
        if($insert){
            return TRUE;
        }else{
            return FALSE;
        }
    }

    function get_visitors(){
        $get = $this->db->get('visitors');
        return $get->result();
    }
}
{'fraction_non_alphanumeric': 0.16279069767441862, 'fraction_numerical': 0.0018856065367693275, 'mean_word_length': 1.631404958677686, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2482176', 'n_tokens_mistral': 474, 'n_tokens_neox': 460, 'n_words': 76}