Collections functions
Encryption functions
General functions
Render functions
Theme permission functions
Video functions
Resource functions

process_node_search_syntax_to_names()

Description

Process one of the columns whose value is a search string containing nodes (e.g @@228@229, @@555) and mutate input array
by adding a new column (named $column + '_node_name') which will hold the nodes found in the search string and their
translated names

Parameters

ColumnTypeDefaultDescription
$R array Generic type for array (e.g DB results). Each value is a result row.
$column string Record column which needs to be checked and its value converted (if applicable)

Return

array

Location

include/node_functions.php lines 2055 to 2128

Definition

 
function process_node_search_syntax_to_names(array $Rstring $column)
    {
    
$all_nodes = [];
    
$record_node_buckets = [];

    foreach(
$R as $idx => $record)
        {
        if(!(
is_array($record) && isset($record[$column])))
            {
            continue;
            }

        
$search $record[$column];
        
$node_bucket $node_bucket_not = [];
        
resolve_given_nodes($search$node_bucket$node_bucket_not);

        
// Build list of nodes identified (so we can get their details later)
        
foreach($node_bucket as $node_refs)
            {
            
$all_nodes array_merge($all_nodes$node_refs);
            }
        
$all_nodes array_merge($all_nodes$node_bucket_not);

        
// Add node buckets found for this record
        
$record_node_buckets[$idx] = [
            
'node_bucket' => $node_bucket,
            
'node_bucket_not' => $node_bucket_not,
        ];
        }

    
// Translate nodes
    
$node_details get_nodes_by_refs(array_unique($all_nodes));
    
$i18l_nodes = [];
    foreach(
$node_details as $node)
        {
        
$i18l_nodes[$node['ref']] = i18n_get_translated($node['name']);        
        }


    
// Convert the $column value to URL
    
$new_col_name "{$column}_node_name";
    
$syntax_desc_tpl '%s - "%s"<br>';
    foreach(
$R as $idx => $record)
        {
        
// mutate array - add a new column for all records
        
$R[$idx][$new_col_name] = '';

        if(!(
is_array($record) && isset($record[$column]) && isset($record_node_buckets[$idx])))
            {
            continue;
            }

        foreach(
$record_node_buckets[$idx] as $bucket_type => $node_buckets)
            {
            
$prefix = ($bucket_type === 'node_bucket' NODE_TOKEN_PREFIX NODE_TOKEN_PREFIX NODE_TOKEN_NOT);

            foreach(
$node_buckets as $node_ref)
                {
                
$nodes = (is_array($node_ref) ? $node_ref : [$node_ref]);
                foreach(
$nodes as $node)
                    {
                    if(!isset(
$i18l_nodes[$node]))
                        {
                        continue;
                        }

                    
$R[$idx][$new_col_name] .= sprintf($syntax_desc_tpl"{$prefix}{$node}"$i18l_nodes[$node]);
                    }
                }
            }
        }

    return 
$R;
    }

This article was last updated 28th February 2021 15:05 Europe/London time based on the source file dated 26th February 2021 15:35 Europe/London time.