Collections functions
General functions
Node functions
Render functions
Theme permission functions
User functions
Resource functions

get_user_actions_recent()

Description

Get recent user actions, optionally for all users. For use by action notifications cron job.

the 'a' permission and the current script is not running from CLI then only the currently logged on
user's actions will be returned

Included columns are as per get_user_actions()
- resourcerequest - array of resource requests
- userrequest - array of user requests
- resourcereview - array of resources to reviewdescription)

Parameters

ColumnTypeDefaultDescription
$minutes int Return actions that were created in the last $minutes minutes
$allusers bool Return actions for all users? If false, or if the current user does not have
$userref; []; // Find all resources that have changed archive state in the given number of minutes ifis_int_loose$view_title_field

Return

array An array with the user id as the index and the following arrays of sub elements.

Location

include/action_functions.php lines 138 to 212

Definition

 
function get_user_actions_recent(int $minutesbool $allusers) : array
    {
    
debug_function_call(__FUNCTION__,func_get_args());
    global 
$view_title_field$userref;

    
$newactions = [];
    
    
// Find all resources that have changed archive state in the given number of minutes
    
if(is_int_loose($view_title_field)) 
        {
        
$generated_title_field "field".$view_title_field;
        }
    else
        {
        
$generated_title_field "r.ref";
        }
    
$sql "SELECT r.ref, r.archive, r.resource_type, rl.user, rl.date AS date, $generated_title_field AS description, 'resourcereview' AS type 
              FROM resource_log rl 
         LEFT JOIN resource_log rl2 ON (rl.resource=rl2.resource AND rl.ref<rl2.ref) 
         LEFT JOIN resource r ON rl.resource=r.ref
             WHERE rl2.ref IS NULL 
               AND rl.type IN('" 
LOG_CODE_STATUS_CHANGED "','" LOG_CODE_CREATED "')
               AND TIMESTAMPDIFF(MINUTE,rl.date,NOW())<?
          ORDER BY rl.ref DESC"
;

    
$params = ["i",$minutes];
    
$newactions["resourcereview"] = ps_query($sql,$params);

    
// Find all resource requests created in the given number of minutes
    
$sql "SELECT r.ref, r.user, r.created AS date, r.expires, r.comments AS description, r.assigned_to, 'resourcerequest' as type
              FROM request r
             WHERE status = 0
               AND TIMESTAMPDIFF(MINUTE,created,NOW())<?
          ORDER BY r.ref ASC"
;
    
$params = ["i",$minutes];
    
$newactions["resourcerequest"] = ps_query($sql,$params);

    
// Find all account requests created in the last XX minutes
    
$sql "SELECT ref, ref as user, created AS date, comments AS description, usergroup, 'userrequest' as type
              FROM user
             WHERE approved =  0
               AND TIMESTAMPDIFF(MINUTE,created,NOW())<?
          ORDER BY ref ASC"
;
    
$params = ["i",$minutes];
    
$newactions["userrequest"] = ps_query($sql,$params);

    
// Any actions that add actions to the array using the hook below should return an element including the function name, parameters and required value to be returned for a user to be able to see the action
    // e.g. 
    // $newactions["access_callback"] = 
    //     ["function"=>"get_edit_access",
    //      "parameters => 12345,
    //      "required => true,
    //     ]
    
$hookactions hook("user_actions_recent","",[$minutes,$newactions]);
    if(
$hookactions != false)
        {
        
$newactions $hookactions;
        }

    
$userrecent = [];
    if(
$allusers)
        {
        
$action_notify_users get_users_by_preference("user_pref_new_action_emails","1");
        foreach(
$action_notify_users as $action_notify_user)
            {
            
$userrecent[$action_notify_user] = actions_filter_by_user($action_notify_user,$newactions);
            }
        }
    else
        {
        
$userrecent[$userref] = actions_filter_by_user($userref,$newactions);
        }

    return 
$userrecent;
    }

This article was last updated 23rd July 2024 21:35 Europe/London time based on the source file dated 6th March 2024 14:45 Europe/London time.