<?php defined("BASEPATH")or exit("NO DIRECT ACCESS IS ALLOWED");?>

<?php

class StudentinfoModel extends CI_Model{
    public function __construct() {
        parent::__construct();
    }
    
    public function conversation_with_st_for_course($limit, $offset){
        $offset       =   ($offset-1)*$limit;
        $query        =   $this->db->select(['pr.*',
            'class.class','category.category','subject.subject','master_user.first_name','master_user.last_name','master_user.email',
             'master_user.mobile','master_user.gender'])
            ->from('v2_student_request_program as pr')
            ->join('class','pr.class_id=class.id')
            ->join('category','pr.category_id=category.id')
            ->join('subject','pr.subject_id=subject.id')
            ->join('master_user','master_user.id=pr.user_id')
            ->limit($limit, $offset)
            ->order_by('pr.id','desc')
            ->get();
            return $query->result();
            //  echo $this->db->last_query();die;
    }
    public function conversation_with_st_for_course_num_rows(){
        $query        =   $this->db->select(['pr.*',
            'class.class','category.category','subject.subject','master_user.first_name','master_user.last_name','master_user.email',
            'master_user.mobile','master_user.gender'])
            ->from('v2_student_request_program as pr')
            ->join('class','pr.class_id=class.id')
            ->join('category','pr.category_id=category.id')
            ->join('subject','pr.subject_id=subject.id')
            ->join('master_user','master_user.id=pr.user_id')
            
            ->order_by('pr.id','desc')
            ->get();
            return $query->num_rows();
            //  echo $this->db->last_query();die;
    }
    public function conversation_with_st_for_course_detail($limit, $offset,$request_program_id){
        $offset       =   ($offset-1)*$limit;
        $query        =   $this->db->select(['pr.*','pr_chat.id as chat_id','pr_chat.request_program_id','pr_chat.user_message','pr_chat.admin_reply',
            'pr_chat.user_msg_date','pr_chat.admin_reply_date','pr_chat.create_at as chat_create','pr_chat.update_at as chat_update',
            'class.class','category.category','subject.subject','master_user.first_name','master_user.last_name','master_user.email',
            'master_user.mobile','master_user.gender'])
            ->from('v2_student_request_program as pr')
            ->join('v2_student_request_program_chat as pr_chat','pr_chat.request_program_id=pr.id')
            ->join('class','pr.class_id=class.id')
            ->join('category','pr.category_id=category.id')
            ->join('subject','pr.subject_id=subject.id')
            ->join('master_user','master_user.id=pr.user_id')
            ->where('pr.id',$request_program_id)
            ->limit($limit, $offset)
            ->order_by('pr_chat.id','desc')
            ->get();
            return $query->result();
            //  echo $this->db->last_query();die;
    }
    public function conversation_with_st_for_course_detail_num_rows($request_program_id){
        $query        =   $this->db->select(['pr.*','pr_chat.id as chat_id','pr_chat.request_program_id','pr_chat.user_message','pr_chat.admin_reply',
            'pr_chat.user_msg_date','pr_chat.admin_reply_date','pr_chat.create_at as chat_create','pr_chat.update_at as chat_update',
            'class.class','category.category','subject.subject','master_user.first_name','master_user.last_name','master_user.email',
            'master_user.mobile','master_user.gender'])
            ->from('v2_student_request_program as pr')
            ->join('v2_student_request_program_chat as pr_chat','pr_chat.request_program_id=pr.id')
            ->join('class','pr.class_id=class.id')
            ->join('category','pr.category_id=category.id')
            ->join('subject','pr.subject_id=subject.id')
            ->join('master_user','master_user.id=pr.user_id')
            ->where('pr.id',$request_program_id)
            ->order_by('pr_chat.id','desc')
            ->get();
            return $query->num_rows();
            //  echo $this->db->last_query();die;
    }
   
    public function update_admin_reply_to_user($field,$value,$editid){
        $this->db->set($field,$value);
        $this->db->where('id',$editid);
        $this->db->update('v2_student_request_program_chat');
        return true;
    }
    
}