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

class Testimonial_Model extends CI_Model {

        var $tableName = 'tbl_testimonial';       
         
   
    function getTestimonialList() { 
        $query = $this->db->get($this->tableName);
        $result = $query->result_array();
        return $result;
    }
    
    function getTestimonialById($testimonialId) {  
        $this->db->where('testimonial_id',$testimonialId);
        $query = $this->db->get($this->tableName);
        $result = $query->row_array();
        return $result;
    }  
    
   
    function add($testimonial_image) {
              if($testimonial_image)
            $this->db->set('testimonial_image', $testimonial_image);
          
            if($this->input->post('name'))
            $this->db->set('name', $this->input->post('name'));
            if($this->input->post('company'))
            $this->db->set('company',$this->input->post('company'));
            if($this->input->post('testimonial'))
            $this->db->set('testimonial', $this->input->post('testimonial'));    
         
            $this->db->set('status','active');  
            $this->db->set('add_time', time());            

            $query = $this->db->insert($this->tableName);
            $response=$this->db->insert_id();
        return $response;
    }   
 
    
     function update($testimonialId,$testimonial_image){
            if($testimonial_image)
            $this->db->set('testimonial_image', $testimonial_image);
          
            if($this->input->post('name'))
            $this->db->set('name', $this->input->post('name'));
            if($this->input->post('company'))
            $this->db->set('company',$this->input->post('company'));
            if($this->input->post('testimonial'))
            $this->db->set('testimonial', $this->input->post('testimonial'));  
                
            $this->db->where('testimonial_id',$testimonialId);    
            $query = $this->db->update($this->tableName);
            return $response;       
    }  
    
    public function updateStatus($testimonialId,$action) {       
   
        $this->db->set('status',$action);
        $this->db->where('testimonial_id',$testimonialId);
        $response = $this->db->update($this->tableName);
        return $response; 
    }
    
    public function delete($testimonialId){        
        $this->db->where('testimonial_id',$testimonialId);
        $response = $this->db->delete($this->tableName);
        return $response; 
    }   
    
   
}
