get_alternative_files()

Description

Retrieves alternative files associated with a specified resource.

Parameters

ColumnTypeDefaultDescription
$resource int The resource ID for which to fetch alternative files.
$order_by string "" The field to order the results by (optional).
$sort string "" The sorting direction (ASC or DESC) for the order_by field (optional).
$type string "" The type of alternative file to filter by (optional).

Return

array|bool An array of alternative files if successful, false otherwise.

Location

include/resource_functions.php lines 4554 to 4589

Definition

 
function get_alternative_files($resource$order_by ""$sort ""$type "")
{
    
# Returns a list of alternative files for the given resource
    
if (
        
$order_by != ""
        
&& $sort != ""
        
&& in_array(strtoupper($order_by), array("ALT_TYPE"))
        && 
validate_sort_value($sort)
    ) {
        
$ordersort $order_by " " $sort ",";
    } else {
        
$ordersort "";
    }

    
# The following hook now returns a query object
    
$extrasql hook("get_alternative_files_extra_sql""", array($resource));

    if (!
$extrasql) {
        
# Hook inactive, ensure we have an empty query object
        
$extrasql = new PreparedStatementQuery();
    }

    
# Filter by type, if provided.
    
if ($type != "") {
        
$extrasql->sql .= " AND alt_type=?";
        
$extrasql->parameters array_merge($extrasql->parameters, array("s",$type));
    }

    
$alt_files_sql "SELECT ref,name,description,file_name,file_extension,file_size,creation_date,alt_type
                    FROM resource_alt_files where resource=? " 
$extrasql->sql .
                   
" order by " $ordersort " name asc, file_size desc";

    
$alt_files_parameters array_merge(array("i",$resource), $extrasql->parameters);

    return 
ps_query($alt_files_sql$alt_files_parameters);
}

This article was last updated 14th March 2025 20:35 Europe/London time based on the source file dated 6th March 2025 14:30 Europe/London time.