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

set_resource_defaults()

Description

Set resource defaults. Optional, a list of field IDs can be passed on to only update certain fields.
IMPORTANT: this function will always set the resource defaults if any are found. The "client code"
is where developers decide whether this should happen

Parameters

ColumnTypeDefaultDescription
$ref integer Resource ID
$specific_fields array array Specific field ID(s) to update

Return

boolean

Location

include/resource_functions.php lines 1423 to 1459

Definition

 
function set_resource_defaults($ref, array $specific_fields = array())
    {
    global 
$userresourcedefaults;

    if(
'' == $userresourcedefaults)
        {
        return 
false;
        }

    foreach(
explode(';'$userresourcedefaults) as $rule)
        {
        
$rule_detail         explode('='trim($rule));
        
$field_shortname     $rule_detail[0];
        
$field_default_value $rule_detail[1];

        
// Find field(s) - multiple fields can be returned to support several fields with the same name
        
$fields ps_array("SELECT ref AS `value` FROM resource_type_field WHERE name = ?",["s",$field_shortname],"schema");

        if(
=== count($fields))
            {
            continue;
            }

        
// Sometimes we may want to set resource defaults only to specific fields so we ignore anything else
        
if(count($specific_fields))
            {
            
$fields array_intersect($fields$specific_fields);
            }

        foreach(
$fields as $field_ref)
            {
            
update_field($ref$field_ref$field_default_value);
            }
        }

    return 
true;
    }

This article was last updated 17th November 2024 15:05 Europe/London time based on the source file dated 15th November 2024 18:30 Europe/London time.