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

get_resource_type_from_extension()

Description

Get resource type ID based on extension
$mappings = array(resource_type_id => array(allowed_extensions));

Example of mapping array:
$mappings = array(2 => array('pdf', 'doc', 'docx', 'epub', 'ppt', 'pptx', 'odt', 'ods', 'tpl'));

Parameters

ColumnTypeDefaultDescription
$extension string Extension we search by (ie. "mp4")
$resource_type_extension_mapping array Maps between resource types and extensions
$default integer The default value to use in case we can't find it the mappings

Return

integer Resource type ID

Location

include/resource_functions.php lines 8516 to 8539

Definition

 
function get_resource_type_from_extension($extension, array $resource_type_extension_mapping$default)
    {
    
$resource_types ps_array("SELECT ref AS value FROM resource_type",array());
    foreach(
$resource_type_extension_mapping as $resource_type_id => $allowed_extensions)
        {
        if (
            !
checkperm('T' $resource_type_id)
            && 
in_array(strtolower($extension), $allowed_extensions)
            && 
in_array($resource_type_id$resource_types)
            ) {
                return 
$resource_type_id;
            }
        }
    if(
in_array($default$resource_types))
        {
        return 
$default;
        }
    else
        {
        
// default resource type does not exist so use the first available type
        
sort($resource_types,SORT_NUMERIC);
        return 
$resource_types[0];
        }
    }

This article was last updated 27th April 2024 09:05 Europe/London time based on the source file dated 26th April 2024 11:50 Europe/London time.