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

get_resource_types()

Description

Return an array of resource types that this user has access to

blank string returns all available types

Parameters

ColumnTypeDefaultDescription
$types string "" Comma separated list to limit the types that are returned by ref,
$translate boolean true Flag to translate the resource types before returning
$ignore_access boolean false Return all resource types regardless of access?#
$usecache boolean false Return cached result?

Return

array Array of resource types limited by T* permissions and optionally by $types

Location

include/resource_functions.php lines 3792 to 3835

Definition

 
function get_resource_types($types ""$translate true$ignore_access false$usecache false)
    {
    global 
$restype_cache;
    
$hash md5(serialize([$types,$translate,$ignore_access]));
    if(
$usecache && isset($restype_cache[$hash]))
        {
        return 
$restype_cache[$hash];
        }
        
    
$resource_types get_all_resource_types();

    if (
$types!="")
        {
        
$s=explode(",",$types);
        }

    
$return=[];
    for (
$n=0;$n<count($resource_types);$n++)
        {
        if (
            (
$ignore_access || !checkperm('T' $resource_types[$n]['ref']))
            &&
            (empty(
$s) || in_array($resource_types[$n]['ref'],$s))
            )
            {
            if(!isset(
$return[$resource_types[$n]["ref"]]))
                {
                if (
$translate==true)
                    {
                    
# Translate name
                    
$resource_types[$n]["name"]=lang_or_i18n_get_translated($resource_types[$n]["name"], "resourcetype-");
                    }
                
$return[$resource_types[$n]["ref"]]=$resource_types[$n]; # Add to return array
                // Create an array to hold associated resource_type_fields, no need to keep the current row's field ID
                
$return[$resource_types[$n]["ref"]]["resource_type_fields"] = [];
                unset(
$return[$resource_types[$n]["ref"]]["resource_type_field"]);
                }
            
// Add associated fields to the resource_type_fields array
            
$return[$resource_types[$n]["ref"]]["resource_type_fields"] = array_filter(explode(",",(string)$resource_types[$n]["resource_type_field"]),"is_int_loose");
            }
        }
    
$restype_cache[$hash] = array_values($return);
    return 
array_values($return);
    }

This article was last updated 24th May 2024 11:35 Europe/London time based on the source file dated 24th May 2024 10:10 Europe/London time.