Collections functions
Encryption functions
General functions
Render functions
Theme permission functions
Video functions
Resource functions

get_data_by_field()

Description

Get the resource data value for a field and a specific resource
or get the specified field for all resources in the system

records for the specified field

Parameters

ColumnTypeDefaultDescription
$resource integer Resource ID. Use NULL to retrieve all resources
$field integer|string Resource type field ID. Can also be a shortname.

Return

string|array

Location

include/resource_functions.php lines 7365 to 7427

Definition

 
function get_data_by_field($resource$field)
    {
    global 
$rt_fieldtype_cache$NODE_FIELDS;

    
$return              '';
    
$resource_type_field escape_check($field);

    
$sql_select   'SELECT *';
    
$sql_from     'FROM resource_data AS rd';
    
$sql_join     '';
    
// $sql_join     = 'LEFT JOIN resource AS r ON rd.resource = r.ref';
    
$sql_where    'WHERE';
    
$sql_order_by '';
    
$sql_limit    '';

        
// Update cache
    
if(!isset($rt_fieldtype_cache[$field]))
        {
        
$rt_fieldtype_cache[$field] = sql_value("SELECT type AS `value` FROM resource_type_field WHERE ref = '{$resource_type_field}' OR name = '{$resource_type_field}'"null"schema");
        }

    if (!
in_array($rt_fieldtype_cache[$field], $NODE_FIELDS))
        {
        
// Let's first check how we deal with the field value we've got
        // Integer values => search for a specific ID
        // String values => search by using a shortname
        
if(is_numeric($field))
            {
            
$sql_select 'SELECT rd.`value`';
            
$sql_where .= " rd.resource = '{$resource}'";
            
$sql_where .= " AND rd.resource_type_field = '{$resource_type_field}'";
            }
        else
            {
            
$sql_select 'SELECT rd.`value`';
            
$sql_where .= " rd.resource = '{$resource}'";
            
$sql_where .= " AND rd.resource_type_field = (SELECT ref FROM resource_type_field WHERE name = '{$resource_type_field}' LIMIT 1)";
            }
        
        
$results sql_query("{$sql_select} {$sql_from} {$sql_join} {$sql_where} {$sql_order_by} {$sql_limit}");
        if(
!== count($results))
            {
            
$return = !is_null($resource) ? $results[0]['value'] : $return;
            }
        
// Default values: '' when we are looking for a specific resource and empty array when looking through all resources
        
else
            {
            
$return = !is_null($resource) ? $return : array();
            }

        if(!
is_array($return) && == $rt_fieldtype_cache[$field])
            {
            
$return strip_tags($return);
            
$return str_replace(' '' '$return);
            }
        }
    else
        {
        
$nodes get_resource_nodes($resource$resource_type_fieldTRUE);
        
$return implode(', 'array_column($nodes'name'));    
        }
    return 
$return;   
    }

This article was last updated 23rd November 2020 19:05 Europe/London time based on the source file dated 13th November 2020 16:50 Europe/London time.