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

copy_resource_type_field_nodes()

Description

Copy all nodes from one metadata field to another one.
Used mostly with copy field functionality

Parameters

ColumnTypeDefaultDescription
$from integer resource_type_field ID FROM which we copy
$to integer resource_type_field ID TO which we copy

Return

boolean

Location

include/node_functions.php lines 1492 to 1558

Definition

 
function copy_resource_type_field_nodes($from$to)
    {
    global 
$FIXED_LIST_FIELD_TYPES;

    
// Since field has been copied, they are both the same, so we only need to check the from field
    
$type sql_value("SELECT `type` AS `value` FROM resource_type_field WHERE ref = '{$from}'"0"schema");

    if(!
in_array($type$FIXED_LIST_FIELD_TYPES))
        {
        return 
false;
        }

    
$nodes get_nodes($fromnulltrue);

    
// Handle category trees
    
if(== $type)
        {
        
// Sort array of nodes to put parent item at the top of each branch to make sure each child item can find its parent below.
        
$node_branches = array();
        foreach(
$nodes as $node)
            {
            if(
$node['parent'] == "")
                {
                
$node_branches[] = $node;
                
$next_branch = array();
                
$next_branch[] = get_nodes($from$node['ref'], true);
                foreach (
$next_branch[0] as $leaf)
                    {
                    
$node_branches[] = $leaf;
                    }
                }
            }
        
$nodes $node_branches;
        
        
// array(from_ref => new_ref)
        
$processed_nodes = array();

        foreach(
$nodes as $node)
            {
            if(
array_key_exists($node['ref'], $processed_nodes))
                {
                continue;
                }

            
$parent $node['parent'];

            
// Child nodes need to have their parent set to the new parent ID
            
if('' != trim($parent))
                {
                
$parent $processed_nodes[$parent];
                }

            
$new_node_id                   set_node(null$to$node['name'], $parent$node['order_by']);
            
$processed_nodes[$node['ref']] = $new_node_id;
            }

        return 
true;
        }

    
// Default handle for types different than category trees
    
foreach($nodes as $node)
        {
        
set_node(null$to$node['name'], $node['parent'], $node['order_by']);
        }

    return 
true;
    }

This article was last updated 13th June 2021 07:05 Europe/London time based on the source file dated 24th May 2021 11:45 Europe/London time.