Collections functions
General functions
Render functions
Theme permission functions
Resource functions

message_get_conversation()

Description

Get all messages between the given user IDs


"msgfind" - (string) Text to find
"sort_desc" - (bool) Sort by message ID in descending order? False = Ascending
"msglimit" - (int) Maximum number of messages to return

Parameters

ColumnTypeDefaultDescription
$user int
$msgusers array array Array of other user IDs
$filteropts array array Array of extra options to filter and sort messages returned
$users int User ID

Return

array Array of messages

Location

include/message_functions.php lines 786 to 843

Definition

 
function message_get_conversation(int $user$msgusers = array(),$filteropts = array())
    {
    
array_map("is_int_loose",$msgusers);
    if(
count($msgusers) == || !is_int_loose($user))
        {
        return array();
        }
    
$validfilterops = array(
        
"msgfind",
        
"sort_desc",
        
"limit",
    );
    foreach(
$validfilterops as $validfilterop)
        {
        if(isset(
$filteropts[$validfilterop]))
            {
            $
$validfilterop $filteropts[$validfilterop];
            }
        else
            {
            $
$validfilterop NULL;
            }
        }

    
# Build array of sql query parameters
    
$parameters ps_param_fill($msgusers,"i");
    
$parameters array_merge($parameters, array("i",$user), array("i",$user));
    
$parameters array_merge($parametersps_param_fill($msgusers,"i"));
    if (
$msgfind != "" )
        {
        
$parameters array_merge($parameters, array("s"$msgfind));
        }
    if (
$limit != "")
        {
        
$parameters array_merge($parameters, array("i", (int)$limit));
        }
    
$msgquery "SELECT message.created,
                        message.owner,
                        message.message,
                        message.url,
                        message.expires,
                        message.type,
                        user_message.user,
                        user_message.ref,
                        user_message.seen
                   FROM message
              LEFT JOIN user_message ON user_message.message=message.ref
                  WHERE ((owner IN(" 
ps_param_insert(count($msgusers)) . ") AND user_message.user = ?)
                     OR (owner = ? AND user_message.user IN(" 
ps_param_insert(count($msgusers)) . ")))"
           
.  ($msgfind != "" ? (" AND message.message LIKE ?") : " " )
           . 
" AND type & '" MESSAGE_ENUM_NOTIFICATION_TYPE_USER_MESSAGE "'"
           
" ORDER BY user_message.ref " . ($sort_desc "DESC" "ASC")
           . (
$limit != "" " LIMIT ?" "");
    
    
$messages ps_query($msgquery$parameters);
    
    return 
$messages;
    }

This article was last updated 26th September 2022 13:35 Europe/London time based on the source file dated 13th September 2022 10:20 Europe/London time.