Collections functions
Encryption functions
General functions
Theme permission functions
Resource functions

reorder_nodes()

Description

Virtually re-order nodes

Temporarily re-order nodes (mostly) for display purposes

Parameters

ColumnTypeDefaultDescription
$unordered_nodes array Original nodes array

Return

array

Location

include/node_functions.php lines 481 to 519

Definition

 
function reorder_nodes(array $unordered_nodes)
    {
    
// Put $auto_order_checkbox and $auto_order_checkbox_case_insensitive as global 
    // to future proof function for when we will drop globals for easier refactoring
    
global $auto_order_checkbox$auto_order_checkbox_case_insensitive;

    
$reordered_options = array();
    
$use_index_key     = array();
    foreach(
$unordered_nodes as $unordered_node_index => $node)
        {
        
$reordered_options[$node['ref']] = i18n_get_translated($node['name']);
        
$use_index_key[$node['ref']]     = ($unordered_node_index == $node['ref']);
        }

    if(isset(
$auto_order_checkbox) && $auto_order_checkbox && $auto_order_checkbox_case_insensitive)
        {
        
natcasesort($reordered_options);
        }
    else
        {
        
natsort($reordered_options);
        }

    
$reordered_nodes = array();
    foreach(
$reordered_options as $reordered_node_id => $reordered_node_option)
        {
        if(!
$use_index_key[$reordered_node_id])
            {
            
$reordered_nodes[$reordered_node_id] = $unordered_nodes[array_search($reordered_node_idarray_column($unordered_nodes'ref'))];
            }
        else
            {
            
$reordered_nodes[$reordered_node_id] = $unordered_nodes[array_search($reordered_node_idarray_column($unordered_nodes'ref''ref'))];
            }
        }

    
clear_query_cache("schema");
    return 
$reordered_nodes;
    }

This article was last updated 10th July 2020 23:35 Europe/London time based on the source file dated 6th July 2020 18:09 Europe/London time.