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

get_notification_users_by_owner_field()

Description

Get users to notify for requested resources "owned" by particular groups. Configurable using a metadata field
($owner_field) and a defined map ($owner_field_mappings).

value contains an array with at least a "ref" and "email" keys.

Parameters

ColumnTypeDefaultDescription
$users array List of notification users {@see get_notification_users()}. Any array structure where each
$resources array List of resource IDs

Return

array Returns user ID (key) and email (value)

Location

include/request_functions.php lines 1224 to 1258

Definition

 
function get_notification_users_by_owner_field(array $users, array $resources)
    {
    
$users_map_ref_email array_column($users'email''ref');

    if(!
can_use_owner_field())
        {
        return 
$users_map_ref_email;
        }

    global 
$owner_field$owner_field_mappings;

    
$users_to_notify = [];

    
// Determine which users should be notified based on the owner field value and its mappings
    
$resource_nodes get_resource_nodes_batch($resources, [$owner_field], true);

    
// All resources are unmanaged so no users should be filtered out
    
if(!empty($resources) && empty($resource_nodes))
        {
        return 
$users_map_ref_email;
        }

    foreach(
$resource_nodes as $rtf_rns)
        {
        
$owner_field_node_id $rtf_rns[$owner_field][0]['ref'] ?? 0;
        
$mapped_group $owner_field_mappings[$owner_field_node_id] ?? 0;
        if(
$owner_field_node_id && $mapped_group 0)
            {
            
$group_users array_column(get_users($mapped_group'''u.username'false, -11false'u.ref'), 'ref');
            
$users_to_notify += array_intersect_key($users_map_ref_emailarray_flip($group_users));
            }
        }

    return 
$users_to_notify;
    }

This article was last updated 19th March 2024 08:05 Europe/London time based on the source file dated 28th February 2024 10:20 Europe/London time.