Collections functions
General functions
Render functions
Theme permission functions
Resource functions

update_fieldx()

Description

updates the value of fieldx field further to a metadata field value update

Parameters

ColumnTypeDefaultDescription
$metadata_field_ref integer - metadata field ref

Return

array

Location

include/metadata_functions.php lines 339 to 396

Definition

 
function update_fieldx(int $metadata_field_ref)
    {
    global 
$NODE_FIELDS;

    if(
$metadata_field_ref && in_array($metadata_field_refget_resource_table_joins()))
        {
        
$fieldinfo get_resource_type_field($metadata_field_ref);
        
$allresources ps_array("SELECT ref value FROM resource WHERE ref>0 ORDER BY ref ASC", []);
        if(
in_array($fieldinfo['type'],$NODE_FIELDS))
            {
            if(
$fieldinfo['type'] === FIELD_TYPE_CATEGORY_TREE)
                {
                
$all_tree_nodes_ordered get_cattree_nodes_ordered($fieldinfo['ref'], nulltrue);
                
// remove the fake "root" node which get_cattree_nodes_ordered() is adding since we won't be using get_cattree_node_strings()
                
array_shift($all_tree_nodes_ordered);
                
$all_tree_nodes_ordered array_values($all_tree_nodes_ordered);

                foreach(
$allresources as $resource)
                    {
                    
// category trees are using full paths to node names
                    
$resource_nodes array_keys(get_cattree_nodes_ordered($fieldinfo['ref'], $resourcefalse));
                    
$node_names_paths = [];
                    foreach(
$resource_nodes as $node_ref)
                        {
                        
$node_names_paths[] = implode(
                            
'/',
                            
array_column(compute_node_branch_path($all_tree_nodes_ordered$node_ref), 'name')
                        );
                        }

                    
update_resource_field_column(
                        
$resource,
                        
$metadata_field_ref,
                        
implode($GLOBALS['field_column_string_separator'], $node_names_paths)
                    );
                    }
                }
            else
                {
                foreach(
$allresources as $resource)
                    {
                    
$resnodes get_resource_nodes($resource$metadata_field_reftrue);
                    
uasort($resnodes'node_orderby_comparator'); 
                    
$resvals array_column($resnodes,"name");
                    
$resdata implode($GLOBALS['field_column_string_separator'], $resvals);
                    
update_resource_field_column($resource$metadata_field_ref$resdata);
                    }
                }
            }
        else
                {
                foreach(
$allresources as $resource)
                    {
                    
update_resource_field_column($resource$metadata_field_refget_data_by_field($resource$metadata_field_ref));
                    }
                }
         }
    }

This article was last updated 31st January 2023 10:05 Europe/London time based on the source file dated 17th January 2023 15:20 Europe/London time.