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

get_resource_nodes()

Description

Get nodes associated with a particular resource for all / a specific field (optionally)

Parameters

ColumnTypeDefaultDescription
$resource integer
$resource_type_field integer null
$detailed boolean false Set to true to return full node details (as get_node() does)
$node_sort boolean null Set to SORT_ASC to sort nodes ascending, SORT_DESC sort nodes descending, null means do not sort

Return

array

Location

include/node_functions.php lines 1447 to 1484

Definition

 
function get_resource_nodes($resource$resource_type_field null$detailed false$node_sort null)
    {
    
$sql_select 'n.ref AS `value`';
    if(
$detailed)
        {
        
$sql_select columns_in("node","n");
        
// Add code to get translated names
        
$params = [];
        
add_sql_node_language($sql_select,$params,"n");
        }

    
$query "SELECT {$sql_select} FROM node AS n INNER JOIN resource_node AS rn ON n.ref = rn.node WHERE rn.resource = ?";
    
$params[] = 'i';$params[] = $resource;
    if(!
is_null($resource_type_field) && is_numeric($resource_type_field))
        {
        
$query .= " AND n.resource_type_field = ?";
        
$params[] = 'i';
        
$params[] = $resource_type_field;
        }

    if(!
is_null($node_sort))
        {
        if(
$node_sort == SORT_ASC)
            {
            
$query .= " ORDER BY n.ref ASC";
            }
        if(
$node_sort == SORT_DESC)
            {
            
$query .= " ORDER BY n.ref DESC";
            }
        }
    else
        {
        
$query .= " ORDER BY n.resource_type_field, n.order_by ASC";
        }

    return 
$detailed ps_query($query$params) : ps_array($query$params);
    }

This article was last updated 19th March 2024 04:05 Europe/London time based on the source file dated 15th March 2024 17:00 Europe/London time.