Collections functions
General functions
Node functions
Render functions
Theme permission functions
User functions
Resource functions

get_resource_data()

Parameters

ColumnTypeDefaultDescription
$ref
$cache true

Location

include/resource_functions.php lines 409 to 460

Definition

 
function get_resource_data($ref,$cache=true)
    {
    if ((string)(int)
$ref != (string)$ref)
        {
        return 
false;
        }
    
# Returns basic resource data (from the resource table alone) for resource $ref.
    # For 'dynamic' field data, see get_resource_field_data
    
global $default_resource_type$get_resource_data_cache;
    if (
$cache && isset($get_resource_data_cache[$ref])) {return $get_resource_data_cache[$ref];}
    
truncate_cache_arrays();

    
# Build a string that will return the 'join' columns (not actually joins but cached truncated metadata stored at the resource level)
    
$joins=get_resource_table_joins();
    
$join_fields = empty($joins) ? '' ',' implode(','array_map(prefix_value('field'), $joins));

    
$resource=ps_query("SELECT " columns_in("resource") . $join_fields " FROM resource WHERE ref=?",array("i",$ref));
    if (
count($resource)==0)
        {
        if (
$ref>=0)
            {
            return 
false;
            }
        else
            {
            
# For upload templates (negative reference numbers), generate a new resource if upload permission.
            
if (!(checkperm("c") || checkperm("d"))) {return false;}
            elseif(!
hook('replace_upload_template_creation''', array($ref)))
                {
                global 
$userref;
                
$user $userref;

                
$default_archive_state get_default_archive_state();
                
ps_query("INSERT INTO resource (ref,resource_type,created_by, archive) VALUES (?,?,?,?)",
                    [
"i",$ref,"i",$default_resource_type,"i",$user,"i",$default_archive_state]
                );

                
$resource ps_query("SELECT " columns_in("resource") . " FROM resource WHERE ref=?",array("i",$ref));
                }
            }
        }

    if (isset(
$resource[0]))
        {
        
$get_resource_data_cache[$ref]=$resource[0];
        return 
$resource[0];
        }
    else
        {
        return 
false;
        }
    }

This article was last updated 19th March 2024 05:35 Europe/London time based on the source file dated 11th March 2024 14:25 Europe/London time.