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_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 3844 to 3887

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 4th December 2024 08:35 Europe/London time based on the source file dated 28th November 2024 12:10 Europe/London time.