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

get_tabs_with_usage_count()

Description

Get tabs (paged) based on some criteria (currently only order by and limit).

Parameters

ColumnTypeDefaultDescription
$criteria array Array holding criteria information (order_by and limit).

Return

array {@see sql_limit_with_total_count()}

Location

include/tab_functions.php lines 43 to 69

Definition

 
function get_tabs_with_usage_count(array $criteria)
    {
    
$order_by_columns = ['order_by''ref'];
    
$sort_options = ['ASC''DESC'];

    
$order_by = isset($criteria['order_by'][0]) && in_array($criteria['order_by'][0], $order_by_columns)
                ? 
$criteria['order_by'][0]
                : 
'order_by';
    
$sort = isset($criteria['order_by'][1]) && in_array($criteria['order_by'][1], $sort_options)
            ? 
$criteria['order_by'][1]
            : 
'ASC';

    
$per_page $criteria['limit']['per_page'] ?? null;
    
$offset $criteria['limit']['offset'] ?? null;

    
$query = new PreparedStatementQuery(
        
"SELECT t.ref,
                t.`name`,
                t.order_by,
                (SELECT count(ref) FROM resource_type_field WHERE tab = t.ref) AS usage_rtf,
                (SELECT count(ref) FROM resource_type WHERE tab = t.ref) AS usage_rt
           FROM tab AS t
           ORDER BY 
{$order_by} {$sort}"
    
);

    return 
sql_limit_with_total_count($query$per_page$offset);
    }

This article was last updated 19th March 2024 11:35 Europe/London time based on the source file dated 18th August 2023 11:35 Europe/London time.