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

get_resource_data()

Parameters

ColumnTypeDefaultDescription
$ref
$cache true

Location

include/resource_functions.php lines 418 to 469

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 11th December 2024 18:35 Europe/London time based on the source file dated 11th December 2024 15:55 Europe/London time.