Collections functions
Encryption functions
General functions
Render functions
Theme permission functions
Video 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 8077 to 8103

Definition

 
function get_resource_type_from_extension($extension, array $resource_type_extension_mapping$default)
    {
    
$resource_types sql_array("SELECT ref AS value FROM resource_type");
    foreach(
$resource_type_extension_mapping as $resource_type_id => $allowed_extensions)
        {
        if (!
checkperm('T' $resource_type_id))
            {
            if(
in_array(strtolower($extension), $allowed_extensions))
                {
                    if(
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 1st December 2020 09:05 Europe/London time based on the source file dated 30th November 2020 11:55 Europe/London time.