Collections functions
General functions
Render functions
Theme permission functions
Resource functions

get_node_order_by()

Description

Calculate the next order by for a new record

Parameters

ColumnTypeDefaultDescription
$resource_type_field integer ID of the metadata field
$is_tree boolean FALSE Param to flag whether this is for a tree node
$parent integer NULL ID of the parent of this node

Return

integer $order_by

Location

include/node_functions.php lines 741 to 781

Definition

 
function get_node_order_by($resource_type_field$is_tree FALSE$parent NULL)
    {
    
$order_by 10;

    
// Blank parent fixup to NULL; non-blank parent fixup to integer
    
if(!is_null($parent))
        {
        if (
$parent == ""){$parent=NULL;}
        else {
$parent = (int) $parent;}
        }
        
    
$query         "SELECT COUNT(*) AS value FROM node WHERE resource_type_field = ? ORDER BY order_by ASC;";
    
$parameters     = array("i",$resource_type_field);
    
$nodes_counter ps_value($query$parameters0);

    if(
$is_tree)
        {
        
$query "SELECT COUNT(*) AS value FROM node WHERE resource_type_field = ?";
        
$parameters=array("i",$resource_type_field);

        if (
is_null($parent))
            {
            
$query.=" AND parent IS NULL ";
            }
        else    
            {
            
$query.=" AND parent = ? ";
            
$parameters=array_merge($parameters,array("i",$parent));
            }
        
$query.="ORDER BY order_by ASC;";
        
        
$nodes_counter ps_value($query$parameters0);
        }

    if(
$nodes_counter)
        {
        
$order_by = ($nodes_counter 1) * 10;
        }

    return 
$order_by;
    }

This article was last updated 4th October 2022 11:05 Europe/London time based on the source file dated 3rd October 2022 13:50 Europe/London time.