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

update_fieldx()

Parameters

ColumnTypeDefaultDescription
$metadata_field_ref: int
get_resource_table_joins

Location

include/metadata_functions.php lines 324 to 381

Definition

 
function update_fieldx(int $metadata_field_ref): void
    
{
    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 17th November 2024 15:35 Europe/London time based on the source file dated 6th March 2024 14:45 Europe/London time.