Collections functions
General functions
Render functions
Theme permission functions
Resource functions

message_get()

Description

Gets messages for a given user (returns true if there are messages, false if not)
Note that messages are passed by reference.

Parameters

ColumnTypeDefaultDescription
&$messages
$user int User ID
$get_all bool false Retrieve all messages? Setting to TRUE will include all seen and expired messages
$sort bool "ASC" Sort by message ID in ascending or descending order
$order_by string "ref" Order of messages returned
$messages array Array that will be populated by messages. Passed by reference

Return

bool Flag to indicate if any messages exist

Location

include/message_functions.php lines 14 to 56

Definition

 
function message_get(&$messages,$user,$get_all=false,$sort="ASC",$order_by="ref")
    {
    switch (
$order_by)
        {
        case 
"ref":
            
$sql_order_by "user_message.ref";
            break;
        case 
"created":
            
$sql_order_by "message.created";
            break;
        case 
"from":
            
$sql_order_by "owner";
            break;
        case 
"fullname":
            
$sql_order_by "user.fullname";
            break;
        case 
"message":
            
$sql_order_by "message.message";
            break;
        case 
"expires":
            
$sql_order_by "message.expires";
            break;
        case 
"seen":
            
$sql_order_by "user_message.seen";
            break;  
        }

    
// Check sort value is valid
    
if (!in_array(strtolower($sort), array("asc""desc")))
    {
    
$sort "ASC";
    }

    
$messages=ps_query("SELECT user_message.ref, user.username AS owner, user_message.seen, message.created, message.expires, message.message, message.url, message.owner as ownerid, message.type " .
        
"FROM `user_message`
        INNER JOIN `message` ON user_message.message=message.ref " 
.
        
"LEFT OUTER JOIN `user` ON message.owner=user.ref " .
        
"WHERE user_message.user = ?" .
        (
$get_all " " " AND message.expires > NOW()") .
        (
$get_all " " " AND user_message.seen='0'") .
        
" ORDER BY " $sql_order_by " " $sort, array("i",$user));
    return(
count($messages) > 0);
    }

This article was last updated 29th May 2022 07:05 Europe/London time based on the source file dated 26th January 2022 11:10 Europe/London time.