Collections functions
General functions
Node functions
Render functions
Theme permission functions
User 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 735 to 775

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 19th March 2024 11:05 Europe/London time based on the source file dated 19th March 2024 10:45 Europe/London time.