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

copy_locked_fields()

Description

Update resource metadata for 'locked' fields from last edited resource.
NB: $fields and $all_selected_nodes are passed by reference

Parameters

ColumnTypeDefaultDescription
$ref integer - resource id being updated
&$fields
&$all_selected_nodes
$locked_fields array - array of locked data columns (may also include resource table columns - handled by copy_locked_data)
$lastedited integer - last edited resource to copy data from
$save boolean false - save data to database (as opposed to just updating the $fields array e.g. for edit page)
$fields array - resource $fields array
$all_selected_nodes array - array of existing resource nodes

Return

void

Location

include/resource_functions.php lines 7165 to 7257

Definition

 
function copy_locked_fields($ref, &$fields,&$all_selected_nodes,$locked_fields,$lastedited$save=false)
    {
    
debug("copy_locked_fields resource " $ref " lastedited: " $lastedited);
    global 
$FIXED_LIST_FIELD_TYPES$tabs_on_edit;
    foreach(
$locked_fields as $locked_field)
            {
            if(!
is_numeric($locked_field))
                {
                
// These are handled by copy_locked_data
                
continue;
                }

            
// Check if this field is listed in the $fields array - if resource type has changed it may not be present
            
$key array_search($locked_fieldarray_column($fields'ref'));
            if(
$key!==false)
                {
                
$fieldtype $fields[$key]["type"];
                }
            else
                {
                
$lockfieldinfo get_resource_type_field($locked_field);
                
$fieldtype $lockfieldinfo["type"];
                }

            if(
in_array($fieldtype$FIXED_LIST_FIELD_TYPES))
                {
                
// Replace nodes for this field
                
$field_nodes get_nodes($locked_fieldnull$fieldtype == FIELD_TYPE_CATEGORY_TREE);
                
$field_node_refs array_column($field_nodes,"ref");
                
$stripped_nodes array_diff ($all_selected_nodes$field_node_refs);
                
$locked_nodes get_resource_nodes($lastedited$locked_field);
                
$all_selected_nodes array_merge($stripped_nodes$locked_nodes);

                if(
$save)
                    {
                    
debug("- adding locked field nodes for resource " $ref ", field id: " $locked_field);
                    
delete_resource_nodes($ref,$field_node_refs,false);
                    if(
count($locked_nodes) > 0)
                        {
                        
add_resource_nodes($ref$locked_nodesfalse);
                        }

                    
# If this is a 'joined' field it still needs to add it to the resource column
                    
$joins=get_resource_table_joins();
                    if (
in_array($locked_field,$joins))
                        {
                        
$node_vals = array();
                        
// Build new value:
                        
foreach($locked_nodes as $locked_node)
                            {
                            foreach (
$field_nodes as $key => $val)
                                {
                                if (
$val['ref'] === $locked_node)
                                    {
                                    
array_push($node_vals$field_nodes[$key]["name"]);
                                    }
                                }
                            
$resource_type_field=$field_nodes[$key]["resource_type_field"];
                            
$values_string implode($GLOBALS['field_column_string_separator'], $node_vals);
                            
update_resource_field_column($ref,$resource_type_field,$values_string);
                            }
                        }
                    }
                }
            else
                {
                
debug(" - checking field values for last resource " $lastedited " field id: " $locked_field);
                if(!isset(
$last_fields))
                    {
                    
$last_fields get_resource_field_data($lastedited,!hook("customgetresourceperms"),null,"",$tabs_on_edit);
                    }

                
$addkey array_search($locked_fieldarray_column($last_fields'ref'));
                if(
$key!==false)
                    {
                    
// Field is already present - just update the value
                
debug(" - updating field value for resource " $lastedited " field id: " $locked_field);
                    
$fields[$key]["value"] = $last_fields[$addkey]["value"];
                    }
                else
                    {
                    
// Add the field to the $fields array
                
debug(" - adding field value for resource " $lastedited " field id:" $locked_field);
                    
$fields[] = $last_fields[$addkey];
                    }
                if(
$save)
                    {
                    
debug("- adding locked field value for resource " $ref ", field id: " $locked_field);
                    
update_field($ref,$locked_field,$last_fields[$addkey]["value"]);
                    }
                }
            }
    }

This article was last updated 13th November 2024 20:35 Europe/London time based on the source file dated 13th November 2024 15:50 Europe/London time.