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

related_resource_pull()

Description

Get a related resource to pull images from

Parameters

ColumnTypeDefaultDescription
$resource array Array of resource data from do_search()

Return

array|bool $resdata Array of alternative resource data to use, or false if not configured or no resource image found

Location

include/resource_functions.php lines 9366 to 9399

Definition

 
function related_resource_pull(array $resource)
    {
    global 
$resource_path_pull_cache;
    
$related false;
    if (isset(
$resource_path_pull_cache[$resource["ref"]]))
        {
        return 
$resource_path_pull_cache[$resource["ref"]];
        }

    
$restypes get_resource_types('',false,true,true);
    
$pull_images array_column($restypes,"pull_images","ref")[$resource['resource_type']];
    if ((int)
$pull_images === 1)
        {
        
$relatedpull do_search("!related" $resource["ref"]);
        
debug("Looking for a related resource with image for resource ID #" $resource["ref"]);
        if (
is_array($relatedpull))
            {
            foreach (
$relatedpull as $related)
                {
                if(
$related["has_image"] !== RESOURCE_PREVIEWS_NONE)
                    {
                    
$relatedpath get_resource_path($related["ref"],true,"pre",false,"jpg",true,1,false);
                    if(
file_exists($relatedpath))
                        {
                        
$resource_path_pull_cache[$resource["ref"]] = $related;
                        
debug("Found related resource with image: " $related["ref"]);
                        break;
                        }
                    }
                }
            }
        }
    return 
$related;
    }

This article was last updated 14th July 2024 16:35 Europe/London time based on the source file dated 10th July 2024 11:30 Europe/London time.