ConversationMessageModel::getCountByConversation PHP Method

getCountByConversation() public method

Get number of messages in a conversation.
Since: 2.0.0
public getCountByConversation ( integer $ConversationID, integer $ViewingUserID, array $Wheres = '' ) : integer
$ConversationID integer Unique ID of conversation being viewed.
$ViewingUserID integer Unique ID of current user.
$Wheres array SQL conditions.
return integer Number of messages.
    public function getCountByConversation($ConversationID, $ViewingUserID, $Wheres = '')
    {
        if (is_array($Wheres)) {
            $this->SQL->where($Wheres);
        }
        $Data = $this->SQL->select('cm.MessageID', 'count', 'Count')->from('ConversationMessage cm')->join('Conversation c', 'cm.ConversationID = c.ConversationID')->join('UserConversation uc', 'c.ConversationID = uc.ConversationID and uc.UserID = ' . $ViewingUserID)->beginWhereGroup()->where('uc.DateCleared is null')->orWhere('uc.DateCleared >', 'c.DateUpdated', true, false)->endWhereGroup()->groupBy('cm.ConversationID')->where('cm.ConversationID', $ConversationID)->get();
        if ($Data->numRows() > 0) {
            return $Data->firstRow()->Count;
        }
        return 0;
    }