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

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 2479 to 2552

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 4th December 2024 08:35 Europe/London time based on the source file dated 28th November 2024 12:10 Europe/London time.