<?php
require_once (PATH_TABLES . "prospect/ProspectConversationTable.php") ;
require_once (PATH_MODELS . "base/MasterBase.php") ;

class ProspectConversationClass extends MasterBase {
    function __construct($db) {
        $this->db       = $db ;
        $this->tbl      = ProspectConversationTable::C_TABLE ;
        $this->fldid2   = ProspectConversationTable::C_ID ;
        $this->fldid    = ProspectConversationTable::C_CONVERSATION_ID ;
    }
    function __destruct() {
    }

    function getConversationHistory($id, $contact_id, $top=0){
        $sql = "";
        if($top > 0){
            $sql = "SELECT TOP " . $top . " ";
        } else {
            $sql = "SELECT ";
        }
        $sql .= ProspectConversationTable::C_DESC .
                       "," . ProspectConversationTable::C_CREATE_DATE .
                " FROM " . ProspectConversationTable::C_TABLE . 
                " WHERE " . ProspectConversationTable::C_ID . " = " . $id . 
                " AND " . ProspectConversationTable::C_CONTACT_ID . " = " . $contact_id.
                " ORDER BY " . ProspectConversationTable::C_CREATE_DATE . " DESC ";
        $rows = $this->db->getTable($sql);
        if(!is_null($rows) && count($rows) > 0){
            return $rows;
        }
        return null;
    }

    function getLastConversationProspect($id, $contact_id){
        $sql = "SELECT TOP 1 ". ProspectConversationTable::C_DESC .
                       ", " . ProspectConversationTable::C_CREATE_DATE .
                " FROM " . ProspectConversationTable::C_TABLE . 
                " WHERE " . ProspectConversationTable::C_ID . " = " . $id . 
                " AND " . ProspectConversationTable::C_CONTACT_ID . " = " . $contact_id . 
                " ORDER BY " . ProspectConversationTable::C_CREATE_DATE . " DESC ";
        $rows = $this->db->getTable($sql);
        if(!is_null($rows) && count($rows) > 0){
            return $rows;
        }
        return null;
    }
}
