Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test functions

actions_filter_by_user()

Description

Filter actions in the provided array to return only those applicable to the given user

Parameters

ColumnTypeDefaultDescription
$actionuser int User ref to get actions for
$actions array Array of actions as returned by get_user_actions_recent()
func_get_args;
$actions_resource_requests
$actions_account_requests
$actions_approve_hide_groups;

Return

array Subset of actions for the given user as would be provided by get_user_actions()

Location

include/action_functions.php lines 223 to 315

Definition

 
function actions_filter_by_user(int $actionuser,array $actions) : array
    {
    
debug_function_call(__FUNCTION__,func_get_args());
    global 
$userref$actions_resource_requests$actions_account_requests$actions_approve_hide_groups

    
$return = [];

    if(!isset(
$userref) || $actionuser != $userref)
        {
        
$saved_user $userref ?? 0;
        
$actionuserdata get_user($actionuser);
        
setup_user($actionuserdata);
        }
    foreach(
$actions as $actiontype=>$typeactions)
        {
        switch(
$actiontype)
            {
            case 
"resourcereview":
                
get_config_option($userref,'actions_resource_review'$actions_resource_reviewtrue);
                if(
$actions_resource_review == false)
                    {
                    
$arrnotifystates = [];
                    }
                else
                    {
                    
get_config_option($userref,"actions_notify_states"$notifystates);
                    if(
is_null($notifystates))
                        {
                        
$arrnotifystates get_default_notify_states();
                        }
                    else
                        {
                        
$arrnotifystates explode(",",$notifystates);
                        }
                    
get_config_option($userref,"actions_resource_types_hide"$ignoretypes,"");
                    
$arrignoretypes explode(",",$ignoretypes);
                    }
                foreach(
$typeactions as $typeaction)
                    {
                    if(
in_array($typeaction["archive"],$arrnotifystates)
                        && !
in_array($typeaction["resource_type"],$arrignoretypes)
                        && 
get_edit_access($typeaction["ref"])
                        && 
$typeaction["user"] != $actionuser // Filter out if the user changed the state themselves
                        
)
                        {
                        
$return["resourcereview"][] = $typeaction;
                        }
                    }
                break;
            case 
"resourcerequest":
                if(
$actions_resource_requests)
                    {
                    foreach(
$typeactions as $typeaction)
                        {
                        if(
resource_request_visible($typeaction))
                            {
                            
$return["resourcerequest"][] = $typeaction;
                            }
                        }
                    }
                break;
            case 
"userrequest":
                if(
checkperm("u") && $actions_account_requests)
                    {
                    foreach(
$typeactions as $typeaction)
                        {
                        if(
checkperm_user_edit($typeaction["ref"]))
                            {
                            
$return["userrequest"][] = $typeaction;
                            }
                        }
                    }
                break;
            default;
                
// Handle any actions added by plugins
                
foreach ($typeactions as $typeaction){
                    if (
                        isset(
$typeaction["access_callback"])
                        && 
call_user_func_array($typeaction["access_callback"]["function"],$typeaction["access_callback"]["parameters"]) == $typeaction["access_callback"]["required"]
                        ) {
                            
$return["userrequest"][] = $typeaction;
                        }
                    }
                break;
            }
        }
    if(isset(
$saved_user) && $saved_user !=0)
        {
        
$saveduserdata get_user($saved_user);
        
setup_user($saveduserdata);
        }
    return 
$return;
    }

This article was last updated 11th December 2024 14:05 Europe/London time based on the source file dated 6th March 2024 14:45 Europe/London time.