<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Resume_listings_model extends CI_Model 
{
    
    

    public function get_myresume_totalcount() 
    {
        $user_id = $this->ion_auth->get_user_id();

        $this->db->where('id =', $user_id);
        $num = $this->db->count_all_results('resume_list');
        return $num;
    }	

    public function get_myresume_listing($limit, $start, $sort_by, $sort_order) 
    {

        $sort_order = ($sort_order == 'desc') ? 'desc' : 'asc';
        $sort_columns = array('first_name', 'last_name', 'r_skills', 'r_job_history', 'education', 'r_phone','r_email');
        $sort_by = (in_array($sort_by, $sort_columns)) ? $sort_by : 'last_name';
        $st = 'D';
        $user_id = $this->ion_auth->get_user_id();

        $this->db->limit($limit, $start);
        $query = $this->db->order_by($sort_by, $sort_order)->where('status !=', $st)->where('id =', $user_id)->get('resume_list');

        if ($query->num_rows() > 0) 
        {
            return $query->result();
        }
        return false;
    }

    public function add_myresume_listing($data) 
    {
        
        $insert = $this->db->insert('resume_list', $data);
        return $insert;
    }

    public function edit_myresume_listing($listing_id, $info) 
    { 
        
            if ($info != '') 
            {
                $data = array(
                    'r_skills' => $this->input->post('r_skills'),
                    'r_job_history' => $this->input->post('r_job_history'),
                    'education' => $this->input->post('education'),
                    'r_phone' => $this->input->post('r_phone'),
                    'r_filename' => $info
    				);
            }
            else
            {
                $data = array(
                    'r_skills' => $this->input->post('r_skills'),
                    'r_job_history' => $this->input->post('r_job_history'),
                    'education' => $this->input->post('education'),
                    'r_phone' => $this->input->post('r_phone')
                    );
            }
        
        
        $this->db->where('resume_id', $listing_id);
        $this->db->update('resume_list', $data);
        return TRUE;
    }

    public function get_myresume_listing_data($listing_id) 
    {
        $this->db->where('resume_id', $listing_id);
        $query = $this->db->get('resume_list');
        return $query->row();
    }

    public function delete_myresume_listing($listing_id) 
    {     
        $this->db->where('resume_id', $listing_id);
        $this->db->delete('resume_list');
        return TRUE;       
    }

    public function get_allresume_totalcount() 
    {
        return $this->db->count_all('resume_list');
    }
    
    public function get_allresume_listings($limit, $start, $sort_by, $sort_order) 
    {

        $sort_order = ($sort_order == 'desc') ? 'desc' : 'asc';
        $sort_columns = array('first_name', 'last_name', 'r_skills', 'r_job_history', 'education', 'r_phone','r_email');
        $sort_by = (in_array($sort_by, $sort_columns)) ? $sort_by : 'last_name';

        $this->db->limit($limit, $start);
        $query = $this->db->order_by($sort_by, $sort_order)->get('resume_list');

        if ($query->num_rows() > 0) 
        {
            return $query->result();
        }
        return false;
    }
    
    public function get_allresume_listing_data($listing_id) 
    {
        $this->db->where('resume_id', $listing_id);
        $query = $this->db->get('resume_list');
        return $query->row();
    }
    
    public function search_allresume_listings($part_c, $crit, $limit, $start, $sort_by, $sort_order) 
    {

        $sort_order = ($sort_order == 'desc') ? 'desc' : 'asc';
        $sort_columns = array('first_name', 'last_name', 'r_skills', 'r_job_history','education', 'r_phone', 'r_email', 'r_filename');
        $sort_by = (in_array($sort_by, $sort_columns)) ? $sort_by : 'last_name';
        $st = 'D';

        $query = $this->db->select('
                 resume_id,
                 id,
                 status,
                 first_name,
                 last_name,
                 r_skills,
                 r_job_history,
                 education,
                 r_phone,
                 r_email,
                 r_filename             
                ')
                ->from('resume_list')
                ->limit($limit, $start)
                ->order_by($sort_by, $sort_order)
                ->where('status !=', $st)
                ->like($part_c, $crit);

        $ret['rows'] = $query->get()->result();

        return $ret;
    }

    public function search_allresume_count($part_c, $crit) 
    {
        $st = 'D';
        $query1 = $this->db->select('COUNT(*) as count', FALSE)
                ->from('resume_list')
                ->where('status !=', $st)
                ->like($part_c, $crit);
        $temp1 = $query1->get()->result();
        $ret1['num_rows'] = $temp1[0]->count;
        return $ret1;
    } 
}
