Documentation

node_functions.php

Table of Contents

Functions

set_node()  : bool|int
Set node - Used for both creating and saving a node in the database.
delete_node()  : void
Delete node. This will fully delete a node and remove any association between the deleted node and resources / keywords.
delete_nodes_for_resource_type_field()  : void
Delete all nodes for a resource type field
get_node()  : bool
Get a specific node by ref
get_nodes()  : array<string|int, mixed>
Get all nodes from database for a specific metadata field or parent.
get_nodes_by_refs()  : array<string|int, mixed>
Find and return node details for a list of node IDs.
is_parent_node()  : bool
Checks whether a node is parent to other nodes or not
get_tree_node_level()  : int
Determine how many level deep a node is. Useful for knowing how much to indent a node
get_all_ancestors_for_node()  : array<string|int, mixed>|bool
Return a row consisting of all ancestor nodes of a given node Example: 1 2 2.3 2.7 2.8.4 2.8.5 2.8.6 2.9 3 Passing in node 5 will return nodes 8,2 in one row
reorder_node()  : void
Function used to reorder nodes based on an array with nodes in the new order
reorder_nodes()  : array<string|int, mixed>
Virtually re-order nodes
render_new_node_record()  : void
Renders HTML for adding a new node record in the database
get_node_order_by()  : int
Calculate the next order by for a new record
draw_tree_node_table()  : bool
Renders HTML for a tree node
node_field_options_override()  : bool
Overrides either a field[options] array structure or a flat option array with values derived from nodes.
add_node_keyword()  : bool
Adds node keyword for indexing purposes
remove_node_keyword()  : void
Removes node keyword for indexing purposes
remove_all_node_keyword_mappings()  : void
Removes all indexed keywords for a specific node ID
check_node_indexed()  : void
Function used to check if a fields' node needs (re-)indexing
add_node_keyword_mappings()  : bool
Function used to index node keywords
remove_node_keyword_mappings()  : bool
Function used to un-index node keywords
add_resource_nodes()  : bool
Add nodes in array to resource
add_resource_nodes_multi()  : bool
Add nodes in array to multiple resources. Changes made using this function will not be logged by default.
get_resource_nodes()  : array<string|int, mixed>
Get nodes associated with a particular resource for all / a specific field (optionally)
get_resources_nodes_by_rtf()  : Generator
Get all resource nodes associated for a specific resource type field.
delete_resource_nodes()  : void
Delete nodes in array from resource
delete_resource_nodes_multi()  : void
Delete all node relationships matching the passed resource IDs and node IDs.
delete_all_resource_nodes()  : void
Delete all node relationships for the given resource.
delete_node_resources()  : void
Delete all resource node relationships for the given node.
copy_resource_nodes()  : void
Copy resource nodes from one resource to another. Only applies for active metadata fields.
copy_resource_type_field_nodes()  : bool
Copy all nodes from one metadata field to another one.
get_parent_nodes()  : array<string|int, mixed>
Get all the parent nodes of the given node, all the way back to the top of the node tree.
get_nodes_count()  : int
Get the total number of nodes for a specific field
extract_node_options()  : array<string|int, mixed>
Extract option names (in raw form if desired) from a nodes array.
get_node_by_name()  : array<string|int, mixed>
Search an array of nodes by name
get_node_id()  : false|int
Return a node ID for a given string
node_translated_name_comparator()  : 0
Comparator function for uasort to allow sorting of node array by translated name
node_orderby_comparator()  : 0
Comparator function for uasort to allow sorting of node array by order_by field
get_node_elements()  : array<string|int, mixed>
This function returns an array containing list of values for a selected field, identified by $field_label, in the multidimensional array $nodes
get_node_tree()  : array<string|int, mixed>
This function returns a multidimensional array with hierarchy that reflects category tree field hierarchy, using parent and order_by fields
get_cattree_nodes_ordered()  : array<string|int, mixed>
This function returns an array of category tree nodes in the hierarchical sequence defined in manage options
get_cattree_node_strings()  : array<string|int, mixed>
This function returns an array of category tree node strings in the hierarchical sequence defined in manage options The returned strings are i18 translated
cattree_node_creator()  : array<string|int, mixed>
Helper function for building node entry arrays for ordering
cattree_node_flatten()  : array<string|int, mixed>
Helper function which adds child nodes after each flattened parent node
get_node_strings()  : array<string|int, mixed>
This function returns an array of strings that represent the full paths to each tree node passed
compute_node_branch_path()  : array<string|int, mixed>
Get to the root of the branch starting from a node.
compute_nodes_by_parent()  : array<string|int, mixed>
Find all nodes with parent
get_resource_nodes_batch()  : array<string|int, mixed>
Get all nodes for given resources and fields. Returns a multidimensional array wth resource IDs as top level indexes and field IDs as second level indexes
process_node_search_syntax_to_names()  : array<string|int, mixed>
Process one of the columns whose value is a search string containing nodes (e.g @@228@229, @@555) and mutate input array by adding a new column (named $column + '_node_name') which will hold the nodes found in the search string and their translated names
delete_unused_non_fixed_list_nodes()  : mixed
Delete unused non-fixed list field nodes with a 1:1 resource association
remove_invalid_node_keyword_mappings()  : mixed
Delete invalid node_keyword associations. Note, by invalid, it's meant where the node is missing.
remove_invalid_resource_node_mappings()  : mixed
Delete invalid resource_node associations. Note, by invalid, it's meant where the node is missing.
get_nodes_use_count()  : array<string|int, mixed>
Get a count of how many resources are using the specified nodes
check_delete_nodes()  : mixed
Check array of nodes and delete any that relate to non-fixed list fields and are unused
remove_field_keywords()  : void
Delete all keywords for all nodes associated with the specified field
update_resource_node_hitcount()  : void
For the specified $resource, increment the hitcount for each node in array
order_tree_nodes()  : array<string|int, mixed>
Order array of tree nodes into logical order - Each parent followed by its child nodes, all following order_by
add_sql_node_language()  : void
Append SQL to an existing node query to obtain the translated names of the node
migrate_fixed_to_text()  : bool
Migrate fixed list field data to text field data for a given resource reference. Useful when changing resource type field from a data type that can contain multiple values such as a dynamic keywords field. This script will concatenate the existing values and leave one remaining node for the new text field.
cleanup_invalid_nodes()  : int
Remove invalid field data from resources, optionally just for the specified resource types and/or fields
update_node_active_state()  : void
Batch update nodes' active state to the database. The same state will apply to all nodes in the list.
toggle_active_state_for_nodes()  : array<int, 0|1>
Toggle nodes' active state
toggle_category_tree_nodes_active_state()  : array<int, 0|1>
Toggle category tree nodes' active state
node_is_active()  : bool
Helper function to check if a node is active Note: a node here requires the "active" key.
suggest_dynamic_keyword_nodes()  : array<string|int, mixed>
Suggest dynamic keyword nodes. Used by pages/edit_fields/9_ajax/suggest_keywords.php

Functions

set_node()

Set node - Used for both creating and saving a node in the database.

set_node(int $ref, int $resource_type_field, string $name, int $parent, int $order_by) : bool|int

Use NULL for ref if you just want to insert a new record.

Parameters
$ref : int

ID of the node. To insert new record ID should be NULL

$resource_type_field : int

ID of the metadata field

$name : string

Node name to be used (international)

$parent : int

ID of the parent of this node (null for non trees)

$order_by : int

Value of the order in the list (e.g. 10). To automatically pick next order by use ''.

Tags
used-by
prepareTags()
Return values
bool|int

delete_node()

Delete node. This will fully delete a node and remove any association between the deleted node and resources / keywords.

delete_node(int $ref) : void
Parameters
$ref : int

ID of the node

delete_nodes_for_resource_type_field()

Delete all nodes for a resource type field

delete_nodes_for_resource_type_field(mixed $ref) : void
Parameters
$ref : mixed

get_node()

Get a specific node by ref

get_node(int $ref, array<string|int, mixed> &$returned_node[, bool $cache = true ]) : bool
Parameters
$ref : int

ID of the node

$returned_node : array<string|int, mixed>

If a value does exist it will be returned through this parameter which is passed by reference

$cache : bool = true

By default this function returns cached data. This may not be appropriate if called after a value has been changed, for example after editing a node name. Set to false to not use cache.

Tags
used-by
prepareTags()
Return values
bool

get_nodes()

Get all nodes from database for a specific metadata field or parent.

get_nodes([int $resource_type_field = null ][, int $parent = null ][, bool $recursive = false ][, int $offset = null ][, int $rows = null ][, string $name = '' ][, bool $use_count = false ][, bool $order_by_translated_name = false ][, bool $exact_match = false ]) : array<string|int, mixed>

Use $parent = NULL and recursive = TRUE to get all nodes for a category tree field

Use $offset and $rows only when returning a subset.

Parameters
$resource_type_field : int = null

ID of the metadata field

$parent : int = null

ID of parent node

$recursive : bool = false

Set to true to get children nodes as well. IMPORTANT: this is normally used with category trees, but can also be used with other fixed field types which allow multiple values eg. dynamic keywords list and checkbox list. This allows field type changes to be made between these three types without losing sight of all nodes.

$offset : int = null

Specifies the offset of the first row to return

$rows : int = null

Specifies the maximum number of rows to return. IMPORTANT! For non-fixed list fields this is capped at 10000 to avoid out of memory errors

$name : string = ''

Filter by name of node

$use_count : bool = false

Show how many resources use a particular node in the node properties

$order_by_translated_name : bool = false

Flag to order by translated names rather then the order_by column

$exact_match : bool = false

When $name is supplied, match the exact name only instead of returning matches containing the $name string.

Tags
used-by
check_display_condition()
Return values
array<string|int, mixed>

get_nodes_by_refs()

Find and return node details for a list of node IDs.

get_nodes_by_refs(array<string|int, mixed> $refs) : array<string|int, mixed>
Parameters
$refs : array<string|int, mixed>

List of node IDs

Return values
array<string|int, mixed>

is_parent_node()

Checks whether a node is parent to other nodes or not

is_parent_node(int $ref[, bool $active_only = false ]) : bool
Parameters
$ref : int

Node ref

$active_only : bool = false

Check only for active (children) nodes

Return values
bool

get_tree_node_level()

Determine how many level deep a node is. Useful for knowing how much to indent a node

get_tree_node_level(int $ref) : int
Parameters
$ref : int

Node ref

Return values
int

The depth value of a tree node

get_all_ancestors_for_node()

Return a row consisting of all ancestor nodes of a given node Example: 1 2 2.3 2.7 2.8.4 2.8.5 2.8.6 2.9 3 Passing in node 5 will return nodes 8,2 in one row

get_all_ancestors_for_node(int $ref, int $level) : array<string|int, mixed>|bool
Parameters
$ref : int

A tree node

$level : int

Node depth level (as returned by get_tree_node_level())

Return values
array<string|int, mixed>|bool

reorder_node()

Function used to reorder nodes based on an array with nodes in the new order

reorder_node(array<string|int, mixed> $nodes_new_order) : void
Parameters
$nodes_new_order : array<string|int, mixed>

Array of nodes

reorder_nodes()

Virtually re-order nodes

reorder_nodes(array<string|int, mixed> $unordered_nodes) : array<string|int, mixed>

Temporarily re-order nodes (mostly) for display purposes

Parameters
$unordered_nodes : array<string|int, mixed>

Original nodes array

Return values
array<string|int, mixed>

render_new_node_record()

Renders HTML for adding a new node record in the database

render_new_node_record(string $form_action, bool $is_tree[, int $parent = 0 ][, int $node_depth_level = 0 ][, array<string|int, mixed> $parent_node_options = array() ]) : void
Parameters
$form_action : string

Set the action path of the form

$is_tree : bool

Set to TRUE if the field is category tree type

$parent : int = 0

ID of the parent of this node

$node_depth_level : int = 0

When rendering for trees, we need to know how many levels deep we need to render it

$parent_node_options : array<string|int, mixed> = array()

Array of node options to be used as parent for new records

get_node_order_by()

Calculate the next order by for a new record

get_node_order_by(int $resource_type_field[, bool $is_tree = false ][, int $parent = null ]) : int
Parameters
$resource_type_field : int

ID of the metadata field

$is_tree : bool = false

Param to flag whether this is for a tree node

$parent : int = null

ID of the parent of this node

Return values
int

$order_by

draw_tree_node_table()

Renders HTML for a tree node

draw_tree_node_table(int $ref, int $resource_type_field, string $name, int $parent, int $order_by[, bool $last_node = false ][, int $use_count = 0 ]) : bool
Parameters
$ref : int

ID of the node

$resource_type_field : int

ID of the metadata field

$name : string

Node name to be used (international)

$parent : int

ID of the parent of this node

$order_by : int

Value of the order in the list (e.g. 10)

$last_node : bool = false

Set to true to allow to insert new records after last node in each level

$use_count : int = 0

Counter of how many resources use a particular node

Return values
bool

node_field_options_override()

Overrides either a field[options] array structure or a flat option array with values derived from nodes.

node_field_options_override(mixed &$field[, int $resource_type_field = null ]) : bool

If a field, then will also add field=>nodes[] sub array ready for field rendering.

Parameters
$field : mixed

Either field array structure or flat options list array

$resource_type_field : int = null

ID of the metadata field, if specified will treat as flat options list

Return values
bool

add_node_keyword()

Adds node keyword for indexing purposes

add_node_keyword(int $node, string $keyword, int $position[, mixed $normalize = true ][, mixed $stem = true ]) : bool
Parameters
$node : int

ID of the node (from node table) the keyword should be linked to

$keyword : string

Keyword to index

$position : int

The position of the keyword in the string that was indexed

$normalize : mixed = true
$stem : mixed = true
Return values
bool

remove_node_keyword()

Removes node keyword for indexing purposes

remove_node_keyword(int $node, string $keyword, int $position[, bool $normalized = false ]) : void
Parameters
$node : int

ID of the node (from node table) the keyword should be linked to

$keyword : string

Keyword to index

$position : int

The position of the keyword in the string that was indexed

$normalized : bool = false

If this keyword is normalized by the time we add it, set as true

remove_all_node_keyword_mappings()

Removes all indexed keywords for a specific node ID

remove_all_node_keyword_mappings(int $node) : void
Parameters
$node : int

Node ID

check_node_indexed()

Function used to check if a fields' node needs (re-)indexing

check_node_indexed(array<string|int, mixed> $node[, bool $partial_index = false ]) : void
Parameters
$node : array<string|int, mixed>

Individual node for a field ( as returned by get_nodes() )

$partial_index : bool = false

Partially index flag for node keywords

add_node_keyword_mappings()

Function used to index node keywords

add_node_keyword_mappings(array<string|int, mixed> $node[, bool|null $partial_index = false ][, bool $is_date = false ][, bool $is_html = false ]) : bool
Parameters
$node : array<string|int, mixed>

Individual node for a field ( as returned by get_nodes() )

$partial_index : bool|null = false

Partially index flag for node keywords. Use NULL if code doesn't have access to the fields' data

$is_date : bool = false
$is_html : bool = false
Return values
bool

remove_node_keyword_mappings()

Function used to un-index node keywords

remove_node_keyword_mappings(array<string|int, mixed> $node[, bool|null $partial_index = false ]) : bool
Parameters
$node : array<string|int, mixed>

Individual node for a field ( as returned by get_nodes() )

$partial_index : bool|null = false

Partially index flag for node keywords. Use NULL if code doesn't have access to the fields' data

Return values
bool

add_resource_nodes()

Add nodes in array to resource

add_resource_nodes(int $resourceid[, array<string|int, mixed> $nodes = array() ][, bool $checkperms = true ][, bool $logthis = true ]) : bool
Parameters
$resourceid : int

Resource ID to add nodes to

$nodes : array<string|int, mixed> = array()

Array of node IDs to add

$checkperms : bool = true

Check permissions before adding?

$logthis : bool = true

Log this? Log entries are ideally added when more data on all the changes made is available to make reverts easier.

Tags
used-by
updateAnnotation()
copy_locked_fields()
Return values
bool

add_resource_nodes_multi()

Add nodes in array to multiple resources. Changes made using this function will not be logged by default.

add_resource_nodes_multi([array<string|int, mixed> $resources = array() ][, array<string|int, mixed> $nodes = array() ][, bool $checkperms = true ][, bool $logthis = false ]) : bool
Parameters
$resources : array<string|int, mixed> = array()

Array of resource IDs to add nodes to

$nodes : array<string|int, mixed> = array()

Array of node IDs to add

$checkperms : bool = true

Check permissions before adding?

$logthis : bool = false

Log this? Log entries are ideally added when more data on all the changes made is available to make reverts easier.

Return values
bool

get_resource_nodes()

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

get_resource_nodes(int $resource[, int $resource_type_field = null ][, bool $detailed = false ][, bool $node_sort = null ]) : array<string|int, mixed>
Parameters
$resource : int
$resource_type_field : int = null
$detailed : bool = false

Set to true to return full node details (as get_node() does)

$node_sort : bool = null

Set to SORT_ASC to sort nodes ascending, SORT_DESC sort nodes descending, null means do not sort

Tags
used-by
check_display_condition()
copy_locked_fields()
HookFacesViewCustompanels()
Return values
array<string|int, mixed>

get_resources_nodes_by_rtf()

Get all resource nodes associated for a specific resource type field.

get_resources_nodes_by_rtf(int $ref) : Generator
Parameters
$ref : int

Resource type field ID

Return values
Generator

delete_resource_nodes()

Delete nodes in array from resource

delete_resource_nodes(int $resourceid[, array<string|int, mixed> $nodes = array() ][, bool $logthis = true ]) : void
Parameters
$resourceid : int

Resource ID to add nodes to

$nodes : array<string|int, mixed> = array()

Array of node IDs to remove

$logthis : bool = true

Log this? Log entries are ideally added when more data on all changes made is available to make reverts easier.

Tags
used-by
deleteAnnotation()
updateAnnotation()

delete_resource_nodes_multi()

Delete all node relationships matching the passed resource IDs and node IDs.

delete_resource_nodes_multi([array<string|int, mixed> $resources = array() ][, mixed $nodes = array() ]) : void
Parameters
$resources : array<string|int, mixed> = array()

An array of resource IDs

$nodes : mixed = array()

An integer or array of single/multiple nodes

delete_all_resource_nodes()

Delete all node relationships for the given resource.

delete_all_resource_nodes(int $resourceid) : void
Parameters
$resourceid : int

The resource ID

delete_node_resources()

Delete all resource node relationships for the given node.

delete_node_resources(int $node) : void
Parameters
$node : int

The node ID to remove from all resources.

copy_resource_nodes()

Copy resource nodes from one resource to another. Only applies for active metadata fields.

copy_resource_nodes(int $resourcefrom, int $resourceto) : void
Parameters
$resourcefrom : int

Resource we are copying data from

$resourceto : int

Resource we are copying data to

copy_resource_type_field_nodes()

Copy all nodes from one metadata field to another one.

copy_resource_type_field_nodes(int $from, int $to) : bool

Used mostly with copy field functionality

Parameters
$from : int

resource_type_field ID FROM which we copy

$to : int

resource_type_field ID TO which we copy

Return values
bool

get_parent_nodes()

Get all the parent nodes of the given node, all the way back to the top of the node tree.

get_parent_nodes(int $noderef[, bool $detailed = false ][, bool $include_child = false ]) : array<string|int, mixed>
Parameters
$noderef : int

The child node ID

$detailed : bool = false

Return all node data? false by default

$include_child : bool = false

Include the passed node in the returned array (easier for resolving tree nodes to paths)? false by default

Return values
array<string|int, mixed>

Array of the parent node IDs

get_nodes_count()

Get the total number of nodes for a specific field

get_nodes_count(int $resource_type_field[, string $name = '' ]) : int
Parameters
$resource_type_field : int

ID of the metadata field

$name : string = ''

Filter by name of node

Return values
int

extract_node_options()

Extract option names (in raw form if desired) from a nodes array.

extract_node_options(array<string|int, mixed> $nodes[, bool $i18n = true ][, bool $index_with_node_id = true ]) : array<string|int, mixed>
Parameters
$nodes : array<string|int, mixed>

Array of nodes as returned by get_nodes()

$i18n : bool = true

Set to false if you don't need to translate the option name

$index_with_node_id : bool = true

Set to false if you don't want a map between node ID and its name

Tags
used-by
check_display_condition()
Return values
array<string|int, mixed>

get_node_by_name()

Search an array of nodes by name

get_node_by_name(array<string|int, mixed> $nodes, string $name[, bool $i18n = true ]) : array<string|int, mixed>

Useful to avoid querying the database multiple times if we already have a full detail array of nodes

Parameters
$nodes : array<string|int, mixed>

Nodes array as returned by get_nodes()

$name : string

Filter by name of node

$i18n : bool = true

Use the translated option value?

Tags
uses
i18n_get_translated()
used-by
check_display_condition()
Return values
array<string|int, mixed>

get_node_id()

Return a node ID for a given string

get_node_id(string $value, int $resource_type_field) : false|int
Parameters
$value : string

The node name to return

$resource_type_field : int

The field to search

Return values
false|int

false = not found integer = node ID of matching keyword.

node_translated_name_comparator()

Comparator function for uasort to allow sorting of node array by translated name

node_translated_name_comparator(array<string|int, mixed> $n1, string $n2) : 0
Parameters
$n1 : array<string|int, mixed>

Node one to compare

$n2 : string

Node two to compare

Return values
0

means $n1 equals $n2 <0 means $n1 less than $n2

0 means $n1 greater than $n2

node_orderby_comparator()

Comparator function for uasort to allow sorting of node array by order_by field

node_orderby_comparator(array<string|int, mixed> $n1, string $n2) : 0
Parameters
$n1 : array<string|int, mixed>

Node one to compare

$n2 : string

Node two to compare

Return values
0

means $n1 equals $n2 <0 means $n1 less than $n2

0 means $n1 greater than $n2

get_node_elements()

This function returns an array containing list of values for a selected field, identified by $field_label, in the multidimensional array $nodes

get_node_elements(array<string|int, mixed> $node_values, array<string|int, mixed> $nodes, string $field_label) : array<string|int, mixed>
Parameters
$node_values : array<string|int, mixed>
  • list of values for a selected field in the node tree
$nodes : array<string|int, mixed>
  • node tree to parse
$field_label : string
  • node field to retrieve value of and add to array $node_values
Return values
array<string|int, mixed>

$node_values

get_node_tree()

This function returns a multidimensional array with hierarchy that reflects category tree field hierarchy, using parent and order_by fields

get_node_tree([string $parentId = "" ][, array<string|int, mixed> $nodes = array() ]) : array<string|int, mixed>
Parameters
$parentId : string = ""
  • elements at top of tree do not have a value for "parent" field, so default value is empty string, otherwise it is the value of the parent element in tree
$nodes : array<string|int, mixed> = array()
  • node tree to parse and order
Return values
array<string|int, mixed>

$tree - multidimension array containing nodes in correct hierarchical order

get_cattree_nodes_ordered()

This function returns an array of category tree nodes in the hierarchical sequence defined in manage options

get_cattree_nodes_ordered(array<string|int, mixed> $treefield[, int $resource = null ][, array<string|int, mixed> $allnodes = false ]) : array<string|int, mixed>
Parameters
$treefield : array<string|int, mixed>
  • the category tree field to be processed
$resource : int = null
  • the resource against which to check for selected nodes - optional
$allnodes : array<string|int, mixed> = false
  • is true if all nodes in the structure are returned, false if only selected nodes are returned
Return values
array<string|int, mixed>

$flatnodes - the array of nodes returned in correct hierarchical order

get_cattree_node_strings()

This function returns an array of category tree node strings in the hierarchical sequence defined in manage options The returned strings are i18 translated

get_cattree_node_strings(array<string|int, mixed> $nodesordered[, array<string|int, mixed> $strings_are_paths = true ]) : array<string|int, mixed>
Parameters
$nodesordered : array<string|int, mixed>
  • the array of nodes in correct hierarchical order
$strings_are_paths : array<string|int, mixed> = true
  • governs the format of the name returned True (default) strings are paths to nodes; False strings are the individual node names
Return values
array<string|int, mixed>

$strings - the returned array of node paths or node names

cattree_node_creator()

Helper function for building node entry arrays for ordering

cattree_node_creator(int $ref, int $resource_type_field, string $name, int $parent, int $order_by, int $resource, array<string|int, mixed> $children, int $active) : array<string|int, mixed>
Parameters
$ref : int

Node id

$resource_type_field : int

Category tree field id

$name : string

Node name

$parent : int

Parent node id

$order_by : int

Node order by

$resource : int

Resource id

$children : array<string|int, mixed>

Array of child node ids

$active : int

Node active state (0 or 1)

Return values
array<string|int, mixed>

cattree_node_flatten()

Helper function which adds child nodes after each flattened parent node

cattree_node_flatten(array<string|int, mixed> $node) : array<string|int, mixed>
Parameters
$node : array<string|int, mixed>

Array of nodes each with a child node array

Return values
array<string|int, mixed>

Array of nodes with child nodes flattened out after their respective parents

get_node_strings()

This function returns an array of strings that represent the full paths to each tree node passed

get_node_strings(array<string|int, mixed> $resource_nodes[, bool $allnodes = false ][, bool $translate = true ]) : array<string|int, mixed>
Parameters
$resource_nodes : array<string|int, mixed>
  • node tree to parse
$allnodes : bool = false
  • include paths to all nodes -if false will just include the paths to the end leaf nodes
$translate : bool = true
  • translate strings?
Return values
array<string|int, mixed>

$nodestrings - array of strings for all nodes passed in correct hierarchical order

compute_node_branch_path()

Get to the root of the branch starting from a node.

compute_node_branch_path(array<string|int, mixed> $nodes, int $id) : array<string|int, mixed>

IMPORTANT: the term nodes here is generic, it refers to a tree node structure containing at least ref and parent

Parameters
$nodes : array<string|int, mixed>

List of nodes to search through (MUST contain elements with at least the "ref" index)

$id : int

Node ref we compute the branch path for

Return values
array<string|int, mixed>

Branch path structure starting from root to the searched node (inclusive)

compute_nodes_by_parent()

Find all nodes with parent

compute_nodes_by_parent(array<string|int, mixed> $nodes, int $id) : array<string|int, mixed>
Parameters
$nodes : array<string|int, mixed>

List of nodes to search through (MUST contain elements with at least the "parent" index)

$id : int

Parent node ref to search by

Return values
array<string|int, mixed>

get_resource_nodes_batch()

Get all nodes for given resources and fields. Returns a multidimensional array wth resource IDs as top level indexes and field IDs as second level indexes

get_resource_nodes_batch(array<string|int, mixed> $resources[, array<string|int, mixed> $resource_type_fields = array() ][, bool $detailed = false ][, bool $node_sort = null ]) : array<string|int, mixed>
Parameters
$resources : array<string|int, mixed>
$resource_type_fields : array<string|int, mixed> = array()
$detailed : bool = false

Set to true to return full node details (as get_node() does)

$node_sort : bool = null

Set to SORT_ASC to sort nodes ascending, SORT_DESC sort nodes descending, null means do not sort

Return values
array<string|int, mixed>

process_node_search_syntax_to_names()

Process one of the columns whose value is a search string containing nodes (e.g @@228@229, @@555) and mutate input array by adding a new column (named $column + '_node_name') which will hold the nodes found in the search string and their translated names

process_node_search_syntax_to_names(array<string|int, mixed> $R, string $column) : array<string|int, mixed>
Parameters
$R : array<string|int, mixed>

Generic type for array (e.g DB results). Each value is a result row.

$column : string

Record column which needs to be checked and its value converted (if applicable)

Return values
array<string|int, mixed>

delete_unused_non_fixed_list_nodes()

Delete unused non-fixed list field nodes with a 1:1 resource association

delete_unused_non_fixed_list_nodes(int $resource_type_field) : mixed
Parameters
$resource_type_field : int

Resource type field (metadata field) ID

remove_invalid_node_keyword_mappings()

Delete invalid node_keyword associations. Note, by invalid, it's meant where the node is missing.

remove_invalid_node_keyword_mappings() : mixed

remove_invalid_resource_node_mappings()

Delete invalid resource_node associations. Note, by invalid, it's meant where the node is missing.

remove_invalid_resource_node_mappings() : mixed

get_nodes_use_count()

Get a count of how many resources are using the specified nodes

get_nodes_use_count(array<string|int, mixed> $nodes) : array<string|int, mixed>
Parameters
$nodes : array<string|int, mixed>

Array of node refs

Return values
array<string|int, mixed>

Array of node ref as keys and number of resources using them as the values

check_delete_nodes()

Check array of nodes and delete any that relate to non-fixed list fields and are unused

check_delete_nodes(array<string|int, mixed> $nodes) : mixed
Parameters
$nodes : array<string|int, mixed>

Array of node IDs

remove_field_keywords()

Delete all keywords for all nodes associated with the specified field

remove_field_keywords(int $field) : void
Parameters
$field : int

Field ID

update_resource_node_hitcount()

For the specified $resource, increment the hitcount for each node in array

update_resource_node_hitcount(int $resource, array<string|int, mixed> $nodes) : void
Parameters
$resource : int
$nodes : array<string|int, mixed>

order_tree_nodes()

Order array of tree nodes into logical order - Each parent followed by its child nodes, all following order_by

order_tree_nodes(array<string|int, mixed> $nodes[, mixed $order_by_translated_name = false ]) : array<string|int, mixed>
Parameters
$nodes : array<string|int, mixed>

Array of detailed nodes

$order_by_translated_name : mixed = false
Return values
array<string|int, mixed>

Full nodes in order

add_sql_node_language()

Append SQL to an existing node query to obtain the translated names of the node

add_sql_node_language(string &$sql_select, array<string|int, mixed> &$sql_params[, string $alias = "node" ]) : void
Parameters
$sql_select : string

SQL query

$sql_params : array<string|int, mixed>

Array of SQL parameters

$alias : string = "node"

migrate_fixed_to_text()

Migrate fixed list field data to text field data for a given resource reference. Useful when changing resource type field from a data type that can contain multiple values such as a dynamic keywords field. This script will concatenate the existing values and leave one remaining node for the new text field.

migrate_fixed_to_text(mixed $resource_type_field, mixed $resource, mixed $category_tree[, mixed $separator = ', ' ]) : bool
Parameters
$resource_type_field : mixed

Resource type field id. ** The field type should have been changed to a text type in advance

  • additional checks maybe need before calling this to ensure the fields are / were of the expected type. see examples in pages/tools/migrate_fixed_to_text.php **
$resource : mixed

Resource reference to be processed.

$category_tree : mixed

Was the field data being migrated previously of type category tree? Specifying true will allow the format of category tree branches to be preserved e.g. "level1/value, level2/value"

$separator : mixed = ', '

Default is comma and space e.g. "value1, value2"

Return values
bool

True on success else false.

cleanup_invalid_nodes()

Remove invalid field data from resources, optionally just for the specified resource types and/or fields

cleanup_invalid_nodes([array<string|int, mixed> $fields = [] ][, array<string|int, mixed> $restypes = [] ][, bool $dryrun = false ]) : int
Parameters
$fields : array<string|int, mixed> = []

=[] Array of resource_type_field refs

$restypes : array<string|int, mixed> = []

=[] Array of resource_type refs

$dryrun : bool = false

Don't delete, just return count of rows that will be affected

Return values
int

Count of rows deleted/to delete

update_node_active_state()

Batch update nodes' active state to the database. The same state will apply to all nodes in the list.

update_node_active_state(array<int, int> $refs, bool $active) : void

For logic on which nodes to toggle toggle_active_state_for_nodes()

Parameters
$refs : array<int, int>

Node IDs

$active : bool

Should nodes be active or not?

toggle_active_state_for_nodes()

Toggle nodes' active state

toggle_active_state_for_nodes(array<int, int> $refs) : array<int, 0|1>
Parameters
$refs : array<int, int>

Node IDs

Return values
array<int, 0|1>

toggle_category_tree_nodes_active_state()

Toggle category tree nodes' active state

toggle_category_tree_nodes_active_state(int $rtf, array<int, int> $node_refs) : array<int, 0|1>
Parameters
$rtf : int

Resource type field ID

$node_refs : array<int, int>
Return values
array<int, 0|1>

node_is_active()

Helper function to check if a node is active Note: a node here requires the "active" key.

node_is_active(array{'active': 0|1} $node) : bool
Parameters
$node : array{'active': 0|1}

A node structure with at least the "active" key present

Return values
bool

suggest_dynamic_keyword_nodes()

Suggest dynamic keyword nodes. Used by pages/edit_fields/9_ajax/suggest_keywords.php

suggest_dynamic_keyword_nodes(int $field, string $keyword, bool $readonly) : array<string|int, mixed>
Parameters
$field : int

Metadata field ID

$keyword : string

String to match

$readonly : bool

Add an option to add new node if no exact match

Return values
array<string|int, mixed>
On this page

Search results